有没有logback.xml的配置示例?

提问者:帅平 问题分类:微服务
有没有logback.xml的配置示例?
6 个回答
ヤ
这里显示不全,可参考如下:
<?xml version="1.0" encoding="UTF-8"?>
<configuration debug="true" scan="true" scanPeriod="1 seconds">
    <appender name="stdout" class="ch.qos.logback.core.ConsoleAppender">
        <filter class="ch.qos.logback.classic.filter.ThresholdFilter">
            <level>DEBUG</level>
        </filter>
        <encoder>
            <pattern>%d [%thread] %-5level %logger{36} [%file : %line] - %msg%n</pattern>
        </encoder>
    </appender>
    <root level="info">
        <appender-ref ref="stdout"/>
    </root>
</configuration>

这个只是打印到控制台
发布于:10个月前 (12-07) IP属地:未知
心似狂潮
心似狂潮
如果要显示到文件中,可添加如下代码:
<appender name = "File" class= "ch.qos.logback.core.rolling.RollingFileAppender">
        <file>logs/app.log</file>
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            <fileNamePattern>logs/archives/app-%d{yyyy-MM-dd}.log.gz</fileNamePattern>
            <maxFileSize>1 GB</maxFileSize>
        </rollingPolicy>
    </appender>
发布于:10个月前 (12-07) IP属地:未知
咪有了
咪有了
如果要显示到文件中,可添加如下代码:
<appender name = "File" class= "ch.qos.logback.core.rolling.RollingFileAppender">
        <file>logs/app.log</file>
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            <fileNamePattern>logs/archives/app-%d{yyyy-MM-dd}.log.gz</fileNamePattern>
            <maxFileSize>1 GB</maxFileSize>
        </rollingPolicy>
    </appender>
追加:
<appender name="file" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <file>${scheduler.manager.server.home}/logs/${app.name}.log</file>
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            <fileNamePattern>logs/archives/app-%d{yyyy-MM-dd}.log.gz
            </fileNamePattern>
            <maxHistory>60</maxHistory>
            <totalSizeCap>20GB</totalSizeCap>
        </rollingPolicy>
        <triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
            <maxFileSize>100MB</maxFileSize>
        </triggeringPolicy>
        <encoder>
            <pattern>%d [%thread] %-5level %logger{36} [%file : %line] - %msg%n</pattern>
        </encoder>
    </appender>
发布于:10个月前 (12-07) IP属地:未知
我来回答