我全部都对自定义登录记录器有疑问。它根本不记录任何内容来控制台或文本文件。我确信我的代码可以正常工作,因为sysout可以完全打印我想要的内容。您能用这个记录器名称=“ REQUEST”帮我吗? 还应该自动创建该日志文件吗?这不会发生。
logback.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xml>
<configuration>
<appender name="STDOUT"
class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n
</pattern>
</encoder>
</appender>
<appender name="REQUEST_FILE"
class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>logs/xxxRequests.log</file>
<rollingPolicy
class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
<fileNamePattern>logs/archived/xxxRequests.%d{yyyy-MM-dd}.%i.log
</fileNamePattern>
<maxFileSize>10MB</maxFileSize>
<!-- total size of all archive files, if total size > 20GB, it will delete
old archived file -->
<totalSizeCap>20GB</totalSizeCap>
<!-- 60 days to keep -->
<maxHistory>60</maxHistory>
</rollingPolicy>
<encoder>
<pattern>%date %level [%thread] %logger{10} [%file:%line] %msg%n
</pattern>
</encoder>
</appender>
<appender name="GENERAL_FILE"
class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>logs/xxx.log</file>
<rollingPolicy
class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
<fileNamePattern>logs/archived/xxx.%d{yyyy-MM-dd}.%i.log
</fileNamePattern>
<maxFileSize>10MB</maxFileSize>
<!-- total size of all archive files, if total size > 20GB, it will delete
old archived file -->
<totalSizeCap>20GB</totalSizeCap>
<!-- 60 days to keep -->
<maxHistory>60</maxHistory>
</rollingPolicy>
<encoder>
<pattern>%date %level [%thread] %logger{10} [%file:%line] %msg%n
</pattern>
</encoder>
</appender>
<appender name="ERROR"
class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>logs/xxxError.log</file>
<rollingPolicy
class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
<fileNamePattern>logs/archived/xxxError.%d{yyyy-MM-dd}.%i.log
</fileNamePattern>
<maxFileSize>10MB</maxFileSize>
<!-- total size of all archive files, if total size > 20GB, it will delete
old archived file -->
<totalSizeCap>20GB</totalSizeCap>
<!-- 60 days to keep -->
<maxHistory>60</maxHistory>
</rollingPolicy>
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
<level>WARN</level>
</filter>
<encoder>
<pattern>%date %level [%thread] %logger{10} [%file:%line] %msg%n
</pattern>
</encoder>
</appender>
<logger name="REQUEST" level="DEBUG" additivity="false">
<appender-ref ref="REQUEST_FILE" />
</logger>
<root level="DEBUG">
<appender-ref ref="STDOUT" />
<appender-ref ref="GENERAL_FILE" />
<appender-ref ref="ERROR" />
</root>
</configuration>
我正尝试使用以下命令记录任何内容:
private static final Logger log = LoggerFactory.getLogger("REQUEST");
,没有任何结果。
我的文件位于以下位置:
-application:
-logs folder:
-archived folder:
-src:
-main:
-resources:
logback.xml