Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why catalina.home_IS_UNDEFINED directory is generated by Logback in the same project directory?

I have written logback configuration file for my application, but when I was doing maven clean install(mvn clean install), it generated a catalina.home_IS_UNDEFINED directory with log file in the project directory. Why this directory generated ?

I don't want it to be in my project directory.

Any help to address this issue ?

Here is the configuration file.

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

    <appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
        <encoder>
            <pattern>%date{HH:mm:ss.SSS} %-5p [%t] %c{1} - %m%n</pattern>
        </encoder>
    </appender>

    <appender name="MY_APP_LOG" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <file>${catalina.home}/logs/myApplication.log</file>
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            <FileNamePattern>${catalina.home}/logs/myApplication.%d{yyyy-MM-dd}.log</FileNamePattern>
        </rollingPolicy>
        <encoder>
            <pattern>%-5p  %date{HH:mm:ss.SSS} [%t] %c{1} - %m%n</pattern>
        </encoder>
        <append>true</append>
    </appender>

    <logger name="org.springframework" level="WARN"/>


    <root>
        <priority value="INFO"/>
        <appender-ref ref="CONSOLE"/>
        <appender-ref ref="MY_APP_LOG"/>
    </root>

</configuration>
like image 493
snehal Avatar asked Jun 12 '14 12:06

snehal


People also ask

Which of the following is the configuration file for logback?

xml. As mentioned earlier, logback will try to configure itself using the files logback-test. xml or logback. xml if found on the class path.

How do I use Logback xml in spring boot?

Logback Rolling File Logging via XML Configuration file To configure Logback for a Spring Boot project via XML, create the logback. xml or logback-spring. xml file under the src/main/resources folder. The configuration in XML file will override the logging properties in the application.

What is logback access xml?

By default, RequestLogImpl looks for a logback configuration file called logback-access. xml, in the same folder where jetty. xml is located. This configuration file contains directives for configuring logback components such as appenders and layouts.


1 Answers

I would suggest not relying on the janino dependency (1 MB for nothing in this case) there is a simpler solution using the logback's default value implementation like this:

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

    <property name="base.folder" value="${catalina.home:-./target}"/>

    <appender name="MY_APP_LOG" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <file>${base.folder}/logs/myApplication.log</file>
        ...
    </appender>

    ...

</configuration>

Look for the :- characters beetween the variable name and the default value. If the ${catalina.home} variable is empty the default value (in this case ./target) will be used.

like image 116
Miklos Krivan Avatar answered Oct 02 '22 09:10

Miklos Krivan