H5W3
当前位置:H5W3 > 其他技术问题 > 正文

slf4j+logback日志文件不输出

日志文件不输出,当前项目下的依赖:

 <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>1.7.26</version>
        </dependency>
        <dependency>
            <groupId>ch.qos.logback</groupId>
            <artifactId>logback-access</artifactId>
            <version>1.2.3</version>
        </dependency>
        <dependency>
            <groupId>ch.qos.logback</groupId>
            <artifactId>logback-classic</artifactId>
            <version>1.2.3</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>ch.qos.logback</groupId>
            <artifactId>logback-core</artifactId>
            <version>1.2.3</version>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>jcl-over-slf4j</artifactId>
            <version>1.7.26</version>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>jul-to-slf4j</artifactId>
            <version>1.7.26</version>
        </dependency>

项目最初不是本人构建的,有些包我之前也没遇到过,但是我看了一下具体就这些跟日志相关的jar包,无法输出日志,idea中控制台同样没有log形式的日志输出,代码中使用了log.info(msg)形式输出了日志

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <property name="project" value="testproject"/>
    <property name="filePath" value="D:/serverlog/" />
    <!--<property name="filePath" value="/opt/serverlog/" />-->
    <contextName>${project}</contextName>
    <appender name="logfile" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <Encoding>UTF-8</Encoding>
        <File>${filePath}${project}.log</File>
        <layout class="ch.qos.logback.classic.PatternLayout">
            <pattern>%date [%level] [%thread] %logger{80} [%file : %line] %msg%n</pattern>
        </layout>
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            <fileNamePattern>${filePath}${project}.%d{yyyy-MM-dd}.%i.log</fileNamePattern>
            <timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
                <maxFileSize>50MB</maxFileSize>
            </timeBasedFileNamingAndTriggeringPolicy>
        </rollingPolicy>
    </appender>
    <logger name="org.hibernate" level="ERROR"/>
    <logger name="org.springframework" level="ERROR"/>
    <logger name="com.testproject" level="DEBUG"/>
    <root level="DEBUG">
        <appender-ref ref="logfile"/>
    </root>
</configuration>

这个是logback.xml配置文件内容
项目启动时又发现:

clipboard.png
但是并不影响项目正常运行,然后根据这个提示,添加了一个相关jar包:

<dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-nop</artifactId>
            <version>1.7.21</version>
        </dependency>

上面那段报错就没有了,依旧无法输出日志信息
求大佬帮忙看看怎么一回事

本文地址:H5W3 » slf4j+logback日志文件不输出

评论 0

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址