zoukankan      html  css  js  c++  java
  • logback 添加自定义字段(转换)

    <configuration scan="true"> 
        <conversionRule conversionWord="serverIP" 
            converterClass="com.foo.MyCustomTagConverter" /> 
    
        <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> 
        <!-- encoders are by default assigned the type 
         ch.qos.logback.classic.encoder.PatternLayoutEncoder --> 
        <encoder> 
         <pattern>%serverIP- %m%n</pattern> 
        </encoder> 
        </appender> 
    
    ... 
    
    </configuration> 
    import ch.qos.logback.classic.pattern.ClassicConverter;
    import ch.qos.logback.classic.spi.ILoggingEvent;
    import org.slf4j.Logger;
    import org.slf4j.LoggerFactory;
    
    import java.net.InetAddress;
    import java.net.UnknownHostException;
    public class LogIpConfig extends ClassicConverter {
        private static final Logger logger = LoggerFactory.getLogger(LogIpConfig .class);
        private static String webIP;
        static {
            try {
                webIP = InetAddress.getLocalHost().getHostAddress();
            } catch (UnknownHostException e) {
                logger.error("获取日志Ip异常", e);
                webIP = null;
            }
        }
    
        @Override
        public String convert(ILoggingEvent event) {
            return webIP;
        }
    }
  • 相关阅读:
    batch build OSG
    COM技术内幕第八章笔记组件复用
    在Fireworks CS5中使用PS滤镜
    不能载入ive场景
    转:lib,dll和h
    想不到的.ive
    显卡始终只支持OPENGL1.1
    初识3D JavaScript接口
    32位CPU寄存器简介以及TSS和TR
    3dsMax的Intervals
  • 原文地址:https://www.cnblogs.com/tiancai/p/15693976.html
Copyright © 2011-2022 走看看