我的src / main / resources中有一个log4j2 XML文件,如下所示。但我仍然没有看到创建的日志文件。不知道我能错过什么。
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="WARN">
<Appenders>
<File name="file" fileName="C:\\Users\\Guest\\Desktop\\Mule.log">
<PatternLayout>
<Pattern>%d %p %c{1.} [%t] %m %ex%n</Pattern>
</PatternLayout>
</File>
<Console name="STDOUT" target="SYSTEM_OUT">
<PatternLayout pattern="%m%n"/>
</Console>
</Appenders>
<Loggers>
<Root level="trace">
<AppenderRef ref="file" level="DEBUG"/>
<AppenderRef ref="STDOUT" level="INFO"/>
</Root>
</Loggers>
</Configuration>
答案 0 :(得分:2)
Log4j2配置仅适用于Mule-3.6版本+,请检查您的Mule版本并将文件名提供给C:/Users/Guest/Desktop/Mule.log格式。
示例文件:
<?xml version="1.0" encoding="utf-8"?>
<Configuration>
<Properties>
<Property name="log-path">${env:MULE_HOME}/logs/test</Property>
<Property name="log-name">test</Property>
</Properties>
<Appenders>
<Console name="console-log" target="SYSTEM_OUT">
<PatternLayout
pattern="[%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %c{1} - %msg%n" />
</Console>
<RollingFile name="info-log" fileName="${log-path}/${log-name}-info.log"
filePattern="${log-path}/${log-name}-info-%d{yyyy-MM-dd}.log">
<PatternLayout>
<pattern>[%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %c{1} - %msg%n
</pattern>
</PatternLayout>
<Policies>
<TimeBasedTriggeringPolicy interval="1" modulate="true" />
</Policies>
<SizeBasedTriggeringPolicy size="10 MB" />
<DefaultRolloverStrategy max="10"/>
</RollingFile>
<RollingFile name="debug-log" fileName="${log-path}/${log-name}-debug.log"
filePattern="${log-path}/${log-name}-debug-%d{yyyy-MM-dd}.log">
<PatternLayout>
<pattern>[%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %c{1} - %msg%n
</pattern>
</PatternLayout>
<Policies>
<TimeBasedTriggeringPolicy interval="1" modulate="true" />
</Policies>
<SizeBasedTriggeringPolicy size="10 MB" />
<DefaultRolloverStrategy max="10"/>
</RollingFile>
<RollingFile name="trace-log" fileName="${log-path}/${log-name}-trace.log"
filePattern="${log-path}/${log-name}-trace-%d{yyyy-MM-dd}.log">
<PatternLayout>
<pattern>[%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %c{1} - %msg%n
</pattern>
</PatternLayout>
<Policies>
<TimeBasedTriggeringPolicy interval="1" modulate="true" />
</Policies>
<SizeBasedTriggeringPolicy size="10 MB" />
<DefaultRolloverStrategy max="10"/>
</RollingFile>
<RollingFile name="error-log" fileName="${log-path}/${log-name}-error.log"
filePattern="${log-path}/${log-name}-error-%d{yyyy-MM-dd}.log">
<PatternLayout>
<pattern>[%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %c{1} - %msg%n
</pattern>
</PatternLayout>
<Policies>
<TimeBasedTriggeringPolicy interval="1" modulate="true" />
</Policies>
<SizeBasedTriggeringPolicy size="10 MB" />
<DefaultRolloverStrategy max="10"/>
</RollingFile>
</Appenders>
<Loggers>
<!-- CXF is used heavily by Mule for web services -->
<AsyncLogger name="org.apache.cxf" level="WARN"/>
<!-- Apache Commons tend to make a lot of noise which can clutter the log-->
<AsyncLogger name="org.apache" level="WARN"/>
<!-- Reduce startup noise -->
<AsyncLogger name="org.springframework.beans.factory" level="WARN"/>
<!-- Mule classes -->
<AsyncLogger name="org.mule" level="INFO"/>
<AsyncLogger name="com.mulesoft" level="INFO"/>
<!-- Reduce DM verbosity -->
<AsyncLogger name="org.jetel" level="WARN"/>
<AsyncLogger name="Tracking" level="WARN"/>
<AsyncRoot level="DEBUG">
<appender-ref ref="info-log" level="info" />
<appender-ref ref="trace-log" level="trace" />
<appender-ref ref="debug-log" level="debug" />
<appender-ref ref="error-log" level="error" />
<appender-ref ref="console-log" level="debug" />
</AsyncRoot>
</Loggers>
</Configuration>
对于工作室,请在运行配置中指定MULE_HOME的位置 - &gt;环境 - &gt; new-&gt;名称 - &gt; MULE_HOME和值 - &gt; c:/ test
答案 1 :(得分:0)
尝试将fileName更改为fileName =&#34; C:/Users/Guest/Desktop/Mule.log"