0

In my java application, I am using maven and springboot, log4j for logging. The problem is logging. The log4j does not have anymore logging control after starting up the springboot(SpringApplication.run(Starter.class);). Please see the main() below. After starting the springboot it obeys to logging.level.*. in the properties file. Not sure what I am doing wrong.

public static void main(String[] args) {
    logger.info("started"); //It logs this with log4j
    SpringApplication.run(Starter.class);
    logger.info("started");//but it does not log this. 
}


<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="WARN">
<Properties>
    <Property name="logPath">${sys:user.home}</Property>
    <Property name="logPattern">[%-5level] %d{HH:mm:ss.SSS} %logger{36}.[ %C{5} , %M , %F,%L ] - %msg%n</Property>
</Properties>
<Appenders>
    <RollingRandomAccessFile name="prodLog" fileName="${logPath}/log.log"
                             filePattern="${logPath}/log/%d{yyyy-MM-dd}-%i.log.zip">
        <PatternLayout
                pattern="${logPattern}"/>
        <Policies>
            <TimeBasedTriggeringPolicy interval="24" modulate="true"/>
            <SizeBasedTriggeringPolicy size="10 MB"/>
        </Policies>
        <DefaultRolloverStrategy max="5"/>
    </RollingRandomAccessFile>

    <Console name="STDOUT" target="SYSTEM_OUT">
        <PatternLayout
                pattern="${logPattern}"/>
    </Console>
</Appenders>
<Loggers>
    <AsyncRoot level="DEBUG" includeLocation="true">
        <AppenderRef ref="STDOUT"/>
        <AppenderRef ref="prodLog"/>
    </AsyncRoot>
</Loggers>

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.testApp.test</groupId>
<artifactId>testApp</artifactId>
<version>1.1.2-SNAPSHOT</version>
<properties/>
<packaging>jar</packaging>
<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.0.4.RELEASE</version>
    <relativePath/>
</parent>
<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.7.0</version>
            <configuration>
                <source>10</source>
                <target>10</target>
                <release>10</release>
                <compilerArgs>
                    <arg>-Xlint:all,-processing</arg>
                </compilerArgs>
                <showWarnings>true</showWarnings>
                <showDeprecation>true</showDeprecation>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.22.0</version>
        </plugin>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>
<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jpa</artifactId>
        <exclusions>
            <exclusion>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-logging</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-devtools</artifactId>
        <optional>true</optional>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-autoconfigure-processor</artifactId>
        <optional>true</optional>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-log4j2</artifactId>
    </dependency>
</dependencies>
</project>
Gayan Mettananda
  • 1,498
  • 14
  • 21
Akansha
  • 45
  • 1
  • 6
  • you can exclude the Logback from spring boot dependency. see [enter link description here](https://stackoverflow.com/questions/23984009/disable-logback-in-springboot) – Mahmoud Murad Dec 15 '18 at 06:32

1 Answers1

0

Thanks for the answers.

changing the lines below it worked fine .

 <Loggers>
    <AsyncRoot level="DEBUG" includeLocation="true">
        <AppenderRef ref="prodLog" level="INFO"/>
        <AppenderRef ref="STDOUT" level="WARN"/>
    </AsyncRoot>
</Loggers>
Akansha
  • 45
  • 1
  • 6