logback:不创建日志文件 [英] logback : does not creates log file

查看:257
本文介绍了logback:不创建日志文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先:我尝试了所有存在的解决方案,但没有任何工作,所以我不希望任何人说这个问题是重复的

我无法使用 logback 登录该文件,但我可以毫无问题地登录到控制台,

I cannot log to the file using logback,but I can log to console without problems,

我的 logback .xml 文件内容

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

  <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
    <!-- encoders are assigned the type
                  ch.qos.logback.classic.encoder.PatternLayoutEncoder by default -->
    <encoder>
      <pattern>%-4relative [%thread] %-5level %logger{35} - %msg %n</pattern>
    </encoder>
  </appender>

<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
    <!--See http://logback.qos.ch/manual/appenders.html#RollingFileAppender-->
    <!--and http://logback.qos.ch/manual/appenders.html#TimeBasedRollingPolicy-->
    <!--for further documentation-->
    <append>true</append>
    <File>/root/connector/logs/connector.log</File>
    <encoder>
        <!-- was: %d{yyyy-MM-dd HH:mm:ss}%5p [%t] (%F:%L) - %msg%n -->
      <pattern>%d{yyyy-MM-dd HH:mm:ss} %-5level [%thread] \(%class{25}:%line\) - %msg%n</pattern>
    </encoder>
    <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
      <!-- By setting the name to .gz here, we get free compression. -->
      <fileNamePattern>/root/connector/logs/connector.log.%d{yyyy-MM-dd}.gz</fileNamePattern>
    </rollingPolicy>
  </appender>

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

我甚至尝试给所有用户写入文件夹的权限,但这不起作用

I tried even to give all users the permission to write in the folder, but this doesn't work


drwxrwxrwx。 2没人没人4096 4月29日08:24日志

drwxrwxrwx. 2 nobody nobody 4096 Apr 29 08:24 logs

我再说一次,我尝试了所有存在的解决方案,但没有什么是工作

推荐答案

也许以下链接可以帮助您。

Maybe the following link will help you.

https://dzone.com/articles/do-not-use -relative-path

编辑:此链接显示不使用带有回溯的相对路径。但我找到了测试它的机会。我发现了一些奇怪的输出。

EDIT: This link says that "don't use relative path with logback". But I found an opportunity to test it. And I found some strange outputs.

我的测试平台是一个Web应用程序,这个应用程序在Windows上的Apache Tomcat下运行。
配置和输出

My test platform is an web application and this app is running under Apache Tomcat on Windows. Configuration and outputs:

< file> ; /logs/output.log< / file> -------------->在C:\ logs文件夹中创建日志文件
< file> C:/logs/output.log< / file> ----------->在C:\\\ logs文件夹$ b中创建日志文件$ b < file> ../ logs / output.log< / file> ----------->在tomcat logs文件夹中创建日志文件
< file> logs / output.log< / file> --------------->创建日志文件tomcat bin \logs文件夹

<file>/logs/output.log</file> --------------> Creates log file in C:\logs folder <file>C:/logs/output.log</file> -----------> Creates log file in C:\logs folder <file>../logs/output.log</file> -----------> Creates log file in tomcat logs folder <file>logs/output.log</file> ---------------> Creates log file in tomcat bin\logs folder

有时候我没有创建日志文件,主要原因是缺少用户/应用程序的创建文件权限。

Sometimes the log file is not created, I think, the main reason of it is lack of create file permission of user/application.

这篇关于logback:不创建日志文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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