用户工具

站点工具


java:logback
  • 常用格式
    • %cn,%contextName上下文,默认default,通常是应用名称
    • %d,%date{ISO8601},%date{pattern,timezone}
    • %level,%-5level,级别,
    • %thread,%t,线程名
    • %logger,%lo{length},日志器名称
    • %n,换行符
    • %ex,默认会附加到格式末尾;%ex{short|full|2},异常深度;%nopex,不记录异常
    • %property{key},属性
  • 有性能损失
    • %line,行号
    • %method,%M,方法
  • 不常用
    • %class功能类似,但性能较差
    • %file文件名,性能较差;
    • %mdc{key:-defVal},%X,诊断信息,默认全部输出:key1=val1, key2=val2
    • %xEx,类似%ex,输出jar包名称;%rEx,异常根源优先输出;
    • %marker,Marker信息有父子关系
    • %replace(p){r,t},%replace(%logger %msg){'\.', '/'},句点替换为斜杠
  • 限长截断

  • %20logger,右对齐,左边补空格
  • %-20logger,左对齐,右边补空格
  • %.30logger,保留末尾,前面截断
  • %20.30logger,小于20字符时右对齐,左边补空格;多余30字符时保留末尾,前面截断
  • %-20.-30logger,小于20字符时左对齐,右边补空格;多余30字符时截断末尾
  • %10.10logger,main.foo.foo.bar.Name ⇒ o.bar.Name

<configuration scan="false" scanPeriod="60 seconds" debug="false">
<contextName>app</contextName>
<property name="LOG_PATH" value="/var/log/app"/>
<property name="FILE_NAME" value="app"/>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d %-5level [%thread] %logger{0}:%L %msg%n</pattern>
</encoder>
</appender>
 <!--
<appender name="SOCKET" class="ch.qos.logback.classic.net.SocketAppender">
		<RemoteHost>itechgt</RemoteHost>
		<Port>6000</Port>
		<ReconnectionDelay>10000</ReconnectionDelay>
		<IncludeCallerData>false</IncludeCallerData>
</appender> 
<appender name="ASYNC_SOCKET" class="ch.qos.logback.classic.AsyncAppender">
		<appender-ref ref="SOCKET" />
		<IncludeCallerData>true</IncludeCallerData>
</appender>
-->
 <!--
 <appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <file>${LOG_PATH}/${FILE_NAME}.log</file>
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            <fileNamePattern>${LOG_PATH}/${FILE_NAME}.log.%d{yyyy-MM}</fileNamePattern>
        </rollingPolicy>
        <encoder>
            <pattern>%d{HH:mm:ss.SSS} %-5level [%thread] %logger{0}:%L %msg%n</pattern>
        </encoder>
    </appender> 
-->
<root level="INFO">
<appender-ref ref="STDOUT"/>
</root>
</configuration>
java/logback.txt · 最后更改: 2020/01/05 23:20 由 admin