遇一山,过一山,处处有风景;只要勇敢向前,一路尽是繁花盛开。 | (点击查看→)【测试干货】python/java自动化、持续集成、性能、测开、简历、笔试面试等

配置日志中显示IP(logback)

 

 

package com.demo.conf;

import ch.qos.logback.classic.pattern.ClassicConverter;
import ch.qos.logback.classic.spi.ILoggingEvent;

import java.net.InetAddress;
import java.net.UnknownHostException;

/**
 * 配置日志中显示IP
 */
public class IPLogConfig extends ClassicConverter {
    @Override
    public String convert(ILoggingEvent event) {
        try {
            return InetAddress.getLocalHost().getHostAddress();
        } catch (UnknownHostException e) {
            e.printStackTrace();
        }
        return null;
    }
}

  

 

 

    <!--配置规则类的位置-->
    <conversionRule conversionWord="ip" converterClass="com.demo.conf.IPLogConfig" />

  

%ip -%date{HH:mm:ss} %highlight(%-5level)[%yellow(%thread)]%green(%logger{56}.%method:%L) -%msg%n"

  

 

posted @ 2018-12-02 10:46  全栈测试笔记  阅读(1425)  评论(0编辑  收藏  举报
浏览器标题切换
浏览器标题切换end