无法在控制台和文件中

时间:2018-11-20 09:41:40

标签: java logging logback logback-classic

首先它现在可以正常工作了。我需要打印错误,所以我的登录配置是这样:

<configuration>


    <!-- Appenders -->
    <appender name="console" class="ch.qos.logback.core.ConsoleAppender">
        <encoder>
            <pattern>%d{yyyy-MM-dd HH:mm:ss} [%-5level - %class.%method :
                %line] %msg %n</pattern>
        </encoder>
    </appender>


  <appender name="file" class="ch.qos.logback.core.FileAppender">
    <file>C:\Work\xxx\xxx\src\main\resources\logs\logFile.log</file>
    <append>true</append>
    <!-- set immediateFlush to false for much higher logging throughput -->
    <immediateFlush>true</immediateFlush>
    <!-- encoders are assigned the type
         ch.qos.logback.classic.encoder.PatternLayoutEncoder by default -->
    <encoder>
      <pattern>%d{yyyy-MM-dd HH:mm:ss} [%-5level - %class.%method :
                %line] %msg %n</pattern>
    </encoder>
  </appender>


    <!-- Logger for my project -->
    <logger name="example">
        <appender-ref ref="console" />
        <appender-ref ref="file" /> 
    </logger>

    <root level="error">
        <appender-ref ref="console" />
        <appender-ref ref="file" /> 

    </root>

</configuration>

logback.xml在此路径/src/main/resources/中,日志文件位于/src/main/resources/logs/logFile.log中。发生异常后,它会在文件中打印我的日志,现在它确实不起作用。有人可以帮助我吗?

0 个答案:

没有答案