登录未使用配置文件 [英] Logback is not using configuration file

查看:97
本文介绍了登录未使用配置文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将进程日志保存到文件中.当我在netbeans中运行类时,此方法工作正常,但是在导出JAR文件后,该进程将无法选择logback.xml.

i'm trying to save the log of a process to a file. This works fine when I run the class in netbeans, but after I export the JAR file there is no way the process pick the logback.xml.

jar文件与logback.xml位于同一路径.我尝试使用在这里找到的所有示例:

The jar file is in the same path than logback.xml. I've tried using all the examples i've found here:

使用命令行文件:

java -Dlogback.configurationFile=logback.xml test.jar 

设置类路径:

java =cp "./" -jar test.jar 

这是配置文件:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>

    <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
        <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
            <!--<Pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} %M:%L- %msg%n</Pattern> -->
            <Pattern>%d{HH:mm:ss.SSS} %-5level %logger{36} %M:%L - %msg%n
            </Pattern>
            <!--<Pattern>%d{dd/MM/yyyy HH:mm:ss.SSS} [%thread] %-5level %C{0}:%L - 
                %msg%n</Pattern> -->
        </encoder>
    </appender>



    <appender name="FILE"
        class="ch.qos.logback.core.rolling.RollingFileAppender">
        <file>test.log</file>
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            <!-- daily rollover -->
            <fileNamePattern>test.%d{yyyy-MM-dd}.log</fileNamePattern>
            <!-- keep 30 days' worth of history -->
            <maxHistory>30</maxHistory>
        </rollingPolicy>

        <encoder>
            <!--<pattern>%-4relative [%thread] %-5level %logger{35} - %msg%n</pattern> -->
            <pattern>%d{dd/MM/yyyy HH:mm:ss.SSS} [%thread] %-5level %C{0}:%L -
                %msg%n</pattern>
        </encoder>
    </appender>

    <root level="DEBUG">
        <appender-ref ref="FILE" />
        <appender-ref ref="STDOUT" />
    </root>
</configuration>

请帮助!谢谢

推荐答案

我发现了问题:

我的类路径中有logback.*.jar和slf4j-api-simple-1.7.12.jar.因此,它使用的是简单而不是登录.

I had logback.*.jar and slf4j-api-simple-1.7.12.jar in my classpath. So It was using simple instead of logback.

我删除的很简单,现在可以正常使用了.

I deleted simple, now works perfect.

谢谢!

这篇关于登录未使用配置文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆