logback SpringBoot 日志处理之 Logback - 掘金
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 <?xml version="1.0" encoding="utf-8" ?> <configuration > <contextName > logback-spring-demo-dev</contextName > <property name ="pattern" value ="%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg %n" /> <property name ="pattern-color" value ="%yellow(%d{yyyy-MM-dd HH:mm:ss.SSS}) [%thread] %highlight(%-5level) %green(%logger{50}) - %highlight(%msg) %n" /> <property name ="LOG_HOME" value ="logs" /> <appender name ="CONSOLE" class ="ch.qos.logback.core.ConsoleAppender" > <encoder class ="ch.qos.logback.classic.encoder.PatternLayoutEncoder" > <pattern > ${pattern}</pattern > </encoder > </appender > <appender name ="CONSOLE-WITH-COLOR" class ="ch.qos.logback.core.ConsoleAppender" > <encoder class ="ch.qos.logback.classic.encoder.PatternLayoutEncoder" > <pattern > ${pattern-color}</pattern > </encoder > </appender > <appender name ="FILE" class ="ch.qos.logback.core.rolling.RollingFileAppender" > <rollingPolicy class ="ch.qos.logback.core.rolling.TimeBasedRollingPolicy" > <fileNamePattern > ${LOG_HOME}/all.%d.%i.log</fileNamePattern > <timeBasedFileNamingAndTriggeringPolicy class ="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP" > <maxFileSize > 10MB</maxFileSize > </timeBasedFileNamingAndTriggeringPolicy > <maxHistory > 30</maxHistory > </rollingPolicy > <encoder > <pattern > ${pattern}</pattern > </encoder > </appender > <root level ="INFO" > <appender-ref ref ="CONSOLE-WITH-COLOR" /> <appender-ref ref ="FILE" /> </root > <logger name ="com.example.logbackdemo.IndexAction" level ="info" additivity ="false" > <appender-ref ref ="CONSOLE" /> </logger > </configuration >
日志
How to define a live template
Go to File->Settings->Editor->Live Templates.
In the right panel tree select category other.
Click the plus (+) sign on the top right, select Live Template.
Set
Abbreviation: log
Description: Inserts private static Logger for slf4j
Template text: private static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger($CLASS_NAME$.class);$END$
Now click the Edit Variables button, we will tell the IDE what $CLASS_NAME$ means here. $END$ means where to place the cursor after template expansion.
Name: CLASS_NAME
Expression: className()
Default value: leave empty
Skip if defined: true (check the checkbox)
At the very bottom look for text Applicable in with a link Change next to it, click it. Select Java->declaration.
Congratulations, you’re done! Just type log and press Tab anywhere in the class declaration.
有颜色的 log4j 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 log4j.debug =false log4j.rootLogger =DEBUG,StdoutErrorFatal,StdoutWarn,StdoutInfo,StdoutDebug,StdoutTracelog4j.logger.com.some.package =TRACElog4j.appender.StdoutErrorFatal =org.apache.log4j.ConsoleAppenderlog4j.appender.StdoutErrorFatal.layout =org.apache.log4j.PatternLayoutlog4j.appender.StdoutErrorFatal.layout.conversionPattern =\u001b[31 log4j.appender.StdoutErrorFatal.threshold=ERROR log4j.appender.StdoutWarn=org.apache.log4j.ConsoleAppender log4j.appender.StdoutWarn.layout=org.apache.log4j.PatternLayout log4j.appender.StdoutWarn.layout.conversionPattern=\u001b[33 log4j.appender.StdoutWarn.threshold=WARN log4j.appender.StdoutWarn.filter.filter1=org.apache.log4j.varia.LevelRangeFilter log4j.appender.StdoutWarn.filter.filter1.levelMin=WARN log4j.appender.StdoutWarn.filter.filter1.levelMax=WARN log4j.appender.StdoutInfo=org.apache.log4j.ConsoleAppender log4j.appender.StdoutInfo.layout=org.apache.log4j.PatternLayout log4j.appender.StdoutInfo.layout.conversionPattern=\u001b[0 m%d{HH:mm:ss,SSS} %-5 p - %-26 c - [user:%X{username}] %m\n log4j.appender.StdoutInfo.threshold=INFO log4j.appender.StdoutInfo.filter.filter1=org.apache.log4j.varia.LevelRangeFilter log4j.appender.StdoutInfo.filter.filter1.levelMin=INFO log4j.appender.StdoutInfo.filter.filter1.levelMax=INFO log4j.appender.StdoutDebug=org.apache.log4j.ConsoleAppender log4j.appender.StdoutDebug.layout=org.apache.log4j.PatternLayout log4j.appender.StdoutDebug.layout.conversionPattern=\u001b[0 log4j.appender.StdoutDebug.threshold=DEBUG log4j.appender.StdoutDebug.filter.filter1=org.apache.log4j.varia.LevelRangeFilter log4j.appender.StdoutDebug.filter.filter1.levelMin=DEBUG log4j.appender.StdoutDebug.filter.filter1.levelMax=DEBUG log4j.appender.StdoutTrace=org.apache.log4j.ConsoleAppender log4j.appender.StdoutTrace.layout=org.apache.log4j.PatternLayout log4j.appender.StdoutTrace.layout.conversionPattern=\u001b[0 log4j.appender.StdoutTrace.threshold=TRACE log4j.appender.StdoutTrace.filter.filter1=org.apache.log4j.varia.LevelRangeFilter log4j.appender.StdoutTrace.filter.filter1.levelMin=TRACE log4j.appender.StdoutTrace.filter.filter1.levelMax=TRACE
完整配置: http://javapub.iteye.com/blog/866664
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 log4j.rootLogger =CONSOLE,FILElog4j.addivity.org.apache =true log4j.appender.CONSOLE =org.apache.log4j.ConsoleAppenderlog4j.appender.CONSOLE.Threshold =INFOlog4j.appender.CONSOLE.Target =System.outlog4j.appender.CONSOLE.Encoding =GBKlog4j.appender.CONSOLE.layout =org.apache.log4j.PatternLayoutlog4j.appender.CONSOLE.layout.ConversionPattern =[framework] %d - %c -%-4 r [%t] %-5 p %c %x - %m%nlog4j.appender.A1 =org.apache.log4j.DailyRollingFileAppenderlog4j.appender.A1.File =C:/log4j/loglog4j.appender.A1.Encoding =GBKlog4j.appender.A1.Threshold =DEBUGlog4j.appender.A1.DatePattern ='.' yyyy-MM-ddlog4j.appender.A1.layout =org.apache.log4j.PatternLayoutlog4j.appender.A1.layout.ConversionPattern =%d{ABSOLUTE} %5 p %c{1 }:%L : %m%nlog4j.appender.FILE =org.apache.log4j.FileAppenderlog4j.appender.FILE.File =C:/log4j/file.loglog4j.appender.FILE.Append =false log4j.appender.FILE.Encoding =GBKlog4j.appender.FILE.layout =org.apache.log4j.PatternLayoutlog4j.appender.FILE.layout.ConversionPattern =[framework] %d - %c -%-4 r [%t] %-5 p %c %x - %m%nlog4j.appender.ROLLING_FILE =org.apache.log4j.RollingFileAppenderlog4j.appender.ROLLING_FILE.Threshold =ERRORlog4j.appender.ROLLING_FILE.File =rolling.loglog4j.appender.ROLLING_FILE.Append =true log4j.appender.CONSOLE_FILE.Encoding =GBKlog4j.appender.ROLLING_FILE.MaxFileSize =10 KBlog4j.appender.ROLLING_FILE.MaxBackupIndex =1 log4j.appender.ROLLING_FILE.layout =org.apache.log4j.PatternLayoutlog4j.appender.ROLLING_FILE.layout.ConversionPattern =[framework] %d - %c -%-4 r [%t] %-5 p %c %x - %m%nlog4j.appender.im = net.cybercorlin.util.logger.appender.IMAppenderlog4j.appender.im.host = mail.cybercorlin.netlog4j.appender.im.username = usernamelog4j.appender.im.password = passwordlog4j.appender.im.recipient = yyflyons@163 .comlog4j.appender.im.layout =org.apache.log4j.PatternLayoutlog4j.appender.im.layout.ConversionPattern =[framework] %d - %c -%-4 r [%t] %-5 p %c %x - %m%nlog4j.appender.SOCKET =org.apache.log4j.RollingFileAppenderlog4j.appender.SOCKET.RemoteHost =localhostlog4j.appender.SOCKET.Port =5001 log4j.appender.SOCKET.LocationInfo =true log4j.appender.SOCKET.layout =org.apache.log4j.PatternLayoutlog4j.appender.SOCET.layout.ConversionPattern =[start]%d{DATE}[DATE]%n%p[PRIORITY]%n%x[NDC]%n%t[THREAD]%n%c[CATEGORY]%n%m[MESSAGE]%n%nlog4j.appender.LF5_APPENDER =org.apache.log4j.lf5.LF5Appenderlog4j.appender.LF5_APPENDER.MaxNumberOfRecords =2000 log4j.appender.MAIL =org.apache.log4j.net.SMTPAppenderlog4j.appender.MAIL.Threshold =FATALlog4j.appender.MAIL.BufferSize =10 log4j.appender.MAIL.From =yyflyons@163 .comlog4j.appender.MAIL.SMTPHost =www.wusetu.comlog4j.appender.MAIL.Subject =Log4J Messagelog4j.appender.MAIL.To =yyflyons@126 .comlog4j.appender.MAIL.layout =org.apache.log4j.PatternLayoutlog4j.appender.MAIL.layout.ConversionPattern =[framework] %d - %c -%-4 r [%t] %-5 p %c %x - %m%n