简体   繁体   English

Logback不会将日志写入文件

[英]Logback does not write logs to a file

I have a Java-standalone REST application, which is inside Tomсat. 我有一个Java独立的REST应用程序,它位于Tomсat中。 I need to output logs to a file, I use logback. 我需要将日志输出到文件,我使用logback。 But logs are not written to the file. 但是日志未写入文件。 They are displayed in the console, although I removed the console appender. 尽管我删除了控制台附加程序,但它们仍显示在控制台中。 If you try on a Windows machine, everything goes fine. 如果您尝试在Windows计算机上运行,​​一切都会很好。 Trying on RedHat (does not have a GUI), the logs are not output to the file (although they should) and are output to the console (although they should not be displayed). 尝试使用RedHat(没有GUI)时,日志不会输出到文件(尽管应该),也不会输出到控制台(尽管不应显示)。 The application works exactly, responds to queries. 该应用程序可以正常运行,对查询做出响应。

Logback.xml: Logback.xml:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <property name="DEV_HOME" value="/var/tmp" />
    <appender name="file" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <file>${DEV_HOME}/mytest.log</file>
        <rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
            <fileNamePattern>${DEV_HOME}/mytest-%d{yyyy-MM-dd}.%i.log</fileNamePattern>
            <maxFileSize>2KB</maxFileSize>
            <maxHistory>4</maxHistory>
            <totalSizeCap>10KB</totalSizeCap>
        </rollingPolicy>
        <encoder class="net.logstash.logback.encoder.LogstashEncoder">
            <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
        </encoder>
    </appender>
    <root level="INFO">
        <appender-ref ref="file" />
    </root>
</configuration>

In Eclipse I do export to Runnable jar file, I throw it on a Linux machine. 在Eclipse中,我确实导出到Runnable jar文件,然后将其扔到Linux机器上。 I run as follows: 我运行如下:

java -jar test.jar & 

Yes I had the same scenario with jboss EAP 7.0 every thing was working fine on the window machine but as soon as i was taking it to linux machine . 是的,我在jboss EAP 7.0中具有相同的场景,在Windows机器上一切正常,但是一旦我将其带到linux机器上。 it wont write a single word. 它不会写一个字。 [application.properties for logging] [用于记录的application.properties]

second i had move log4j.properties in Jboss bin folder. 第二,我在Jboss bin文件夹中移动了log4j.properties。 application.properties file and the same file in springboot application resources. application.properties文件和springboot应用程序资源中的相同文件。

在此处输入图片说明

After that restart the server and you will found the loggs written on the specified folder 重新启动服务器后,您会发现写在指定文件夹中的logg

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM