Monday, January 9, 2017

Log4j Configuration in Spring Boot project

For log4j configuration, 3 things are done.

1st Step:


In src/main/resources Folder, I have created a file named application.properties.

application.properties

logging.file=project-server.log



2nd Step:

I have also created another file named  logback-spring.xml
logback-spring.xml
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <include resource="org/springframework/boot/logging/logback/defaults.xml" />
    <property name="LOG_FILE"
        value="${LOG_FILE:-${LOG_PATH:-${LOG_TEMP:-${java.io.tmpdir:-/tmp}}/}spring.log}" />
    <include resource="org/springframework/boot/logging/logback/file-appender.xml" />
    <root level="INFO">
        <appender-ref ref="FILE" />
    </root>
</configuration>




3rd Step:


In ServiceImpl.java class, I have added the following lines

ServiceImpl.java
 
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;


 @Service
public class ServiceImpl implements MyService {

private static final Logger logger = LoggerFactory.getLogger(ServiceImpl.class);


It gives me log file properly.
 

No comments:

Post a Comment