Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

logback : does not creates log file

First of all, I tried every solution that exist, but nothing is working, so I don't want from anyone to say this question is duplicated.

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

My logback.xml file content:

<?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 even tried to give all users the permission to write in the folder, but this doesn't work.

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

I repeat again, I tried every solution that exists, but nothing is working.

like image 642
h.zak Avatar asked Apr 29 '16 09:04

h.zak


1 Answers

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.

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> --------------> 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.

like image 72
gbii Avatar answered Sep 18 '22 11:09

gbii