首页  

logback pattern 配置     所属分类 logback 浏览量 1848
日志输出格式
https://logback.qos.ch/manual/encoders.html

%caller 打印方法调用栈 这个很有用


<appender name="STD" class="ch.qos.logback.core.ConsoleAppender">  
        <encoder>  
            <pattern>%d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger -%msg%n</pattern>  
        </encoder>  
</appender> 


%d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger -%msg%n

2019-06-12 08:30:07 [main] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory -Returning cached instance of singleton bean 'config'

影响性能 避免使用的配置
%class  调用者全限定名
%file   java源文件名    
%line   行号
%method  方法
%caller 调用栈


%d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger -%msg --- %class %file %line %method %caller{30}    %n

打印详细的日志 方便跟踪阅读源码

%caller 打印方法调用栈 这个很有用

%caller
最大深度 7
可以打断点 ,可 在 debug 界面   查看 堆栈
copy stack 复制堆栈 
%caller{3}


2019-06-12 08:05:01 [main] INFO  org.springframework.context.annotation.AnnotationConfigApplicationContext -Closing org.springframework.context.annotation.AnnotationConfigApplicationContext@4f7d0008: startup date [Fri Jun 14 13:34:01 CST 2019]; root of context hierarchy --- org.springframework.context.support.AbstractApplicationContext AbstractApplicationContext.java 989 doClose Caller+0	 at org.springframework.context.support.AbstractApplicationContext.doClose(AbstractApplicationContext.java:989)
Caller+1	 at org.springframework.context.support.AbstractApplicationContext.close(AbstractApplicationContext.java:963)
Caller+2	 at spring5.Hello.main(Hello.java:19)
 
2019-06-12 08:05:01 [main] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory -Returning cached instance of singleton bean 'lifecycleProcessor' --- org.springframework.beans.factory.support.AbstractBeanFactory AbstractBeanFactory.java 255 doGetBean Caller+0	 at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:255)
Caller+1	 at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:200)
Caller+2	 at org.springframework.context.support.DefaultLifecycleProcessor.getLifecycleBeans(DefaultLifecycleProcessor.java:286)
Caller+3	 at org.springframework.context.support.DefaultLifecycleProcessor.stopBeans(DefaultLifecycleProcessor.java:194)
Caller+4	 at org.springframework.context.support.DefaultLifecycleProcessor.onClose(DefaultLifecycleProcessor.java:127)
Caller+5	 at org.springframework.context.support.AbstractApplicationContext.doClose(AbstractApplicationContext.java:1005)
Caller+6	 at org.springframework.context.support.AbstractApplicationContext.close(AbstractApplicationContext.java:963)
Caller+7	 at spring5.Hello.main(Hello.java:19)


2019-06-12 08:05:01 [main] INFO  logCallerTest -log caller pattern test --- spring5.Hello Hello.java 39 log2 Caller+0	 at spring5.Hello.log2(Hello.java:39)
Caller+1	 at spring5.Hello.log1(Hello.java:35)
Caller+2	 at spring5.Hello.log0(Hello.java:31)
Caller+3	 at spring5.Hello.main(Hello.java:25)


方法调用栈  深度 
栈 后进先出   栈顶 caller 0 


private static void log0(){
		log1();
	}
	
	private static void log1(){
		log2();
	}
	
	private static void log2(){
		LoggerFactory.getLogger("logCallerTest").info("log caller pattern test");
	}

上一篇     下一篇
spring-boot-starter-parent的作用

spring5实例之AnnotationConfigApplicationContext使用

spring Java Config 相关注解及注意点

java8的方法区

Hadoop不行了吗

java内存模型