我最近启用了log4j2配置,以便从记录器生成CSV文件。 CSV文件生成正常。但是,只有来自Web服务客户端类的日志语句才能在CSV中实现,即管理器,操作类(Struts 2操作),实用程序类,映射器类和Web服务请求/响应打印处理程序的日志语句根本不会生成在CSV文件中。这可能是什么原因?
这是我的代码:
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="WARN">
<Properties>
<Property name="infoLog.filename">/logs/info.log</Property>
<Property name="debugLog.filename">/logs/debug.log</Property>
<Property name="errorLog.filename">/logs/error.log</Property>
<Property name="communicationLog.filename">/logs/communication.log</Property>
<Property name="csvLog.fileName">/logs/csvLog</Property>
<Property name="file-header">column1,column2,column3</Property>
</Properties>
<Appenders>
<RollingFile name="csvFile" fileName="${csvLog.fileName}.csv"
filePattern="${csvLog.fileName}-%d{MM-dd-yyyy}-%i.csv">
<BurstFilter level="WARN" rate="16" maxBurst="100"/>
<CsvParameterLayout delimiter="," header="${file-header}\n" />
<Policies>
<TimeBasedTriggeringPolicy interval="1"
modulate="true" />
<SizeBasedTriggeringPolicy size="10 MB" />
</Policies>
<DefaultRolloverStrategy max="200" />
</RollingFile>
<RollingFile name="debugFile" fileName="${debugLog.filename}"
filePattern="${debugLog.filename}-%d{MM-dd-yyyy}-%i.log">
<PatternLayout
pattern="%-5p [%t] -%-10c (%L):-(%method) %m%n%throwable" />
<Policies>
<TimeBasedTriggeringPolicy interval="1"
modulate="true" />
<SizeBasedTriggeringPolicy size="10 MB" />
</Policies>
<DefaultRolloverStrategy max="200" />
</RollingFile>
<RollingFile name="infoFile" fileName="${infoLog.filename}"
filePattern="${infoLog.filename}-%d{MM-dd-yyyy}-%i.log">
<PatternLayout
pattern="%d{dd MMM yyyy HH:mm:ss,SSS} %-5p %X{userId} [%t] -%-10c (%-L):-(%method) %m%n" />
<Policies>
<TimeBasedTriggeringPolicy interval="1"
modulate="true" />
<SizeBasedTriggeringPolicy size="10 MB" />
</Policies>
<DefaultRolloverStrategy max="200" />
</RollingFile>
<RollingFile name="errorFile" fileName="${errorLog.filename}"
filePattern="${errorLog.filename}-%d{MM-dd-yyyy}-%i.log">
<PatternLayout
pattern="%d{dd MMM yyyy HH:mm:ss,SSS} %-5p %X{userId} [%t] -%-10c (%-L):-(%method) %m%n%throwable" />
<Policies>
<TimeBasedTriggeringPolicy interval="1"
modulate="true" />
<SizeBasedTriggeringPolicy size="10 MB" />
</Policies>
<DefaultRolloverStrategy max="200" />
</RollingFile>
<RollingFile name="communicationLog" fileName="${communicationLog.filename}"
filePattern="${communicationLog.filename}-%d{MM-dd-yyyy}-%i.log">
<PatternLayout
pattern="%d{dd MMM yyyy HH:mm:ss,SSS} %-5p %X{userId} [%t] -%-10c (%-L):-(%method) %m%n%throwable" />
<Policies>
<TimeBasedTriggeringPolicy interval="1"
modulate="true" />
<SizeBasedTriggeringPolicy size="10 MB" />
</Policies>
<DefaultRolloverStrategy max="200" />
</RollingFile>
<Console name="STDOUT" target="SYSTEM_OUT">
<PatternLayout
pattern="%-5p | %d{yyyy-MM-dd HH:mm:ss} | %X{userId} [%t] -%-10c (%-L):-(%method) %m%n" />
</Console>
</Appenders>
<Loggers>
<logger name="com.syb.core.manager" level="DEBUG" additivity="false">
<appender-ref ref="STDOUT" />
<appender-ref ref="communicationLog" />
<appender-ref ref="csvFile" />
</logger>
<logger name="com.syb.as.manager" level="DEBUG" additivity="false">
<appender-ref ref="STDOUT" />
<appender-ref ref="communicationLog" />
<appender-ref ref="csvFile" />
</logger>
<logger name="com.syb.ao.manager" level="DEBUG" additivity="false">
<appender-ref ref="STDOUT" />
<appender-ref ref="communicationLog" />
<appender-ref ref="csvFile" />
</logger>
<logger name="error.unhandled" additivity="false">
<level value="ERROR" />
<appender-ref ref="STDOUT" level="INFO" />
<appender-ref ref="errorFile" level="ERROR" />
<appender-ref ref="csvFile" />
</logger>
<Root level="debug" additivity="false">
<AppenderRef ref="debugFile" level="debug"/>
<AppenderRef ref="errorFile" level = "error"/>
<AppenderRef ref="infoFile" level="info"/>
<AppenderRef ref="STDOUT" level="info"/>
<AppenderRef ref="csvFile" level="all"/>
</Root>
</Loggers>
是否可以采取任何措施在CSV文件中为整个应用程序中的日志语句生成CSV记录?如果你可以提供帮助,那真的很棒。