I have a maven project which logs using Lombok's inbuilt @Slf4j. Currently my logs are visible in console as below
06-Apr-2020 17:42:38.217 INFO [RMI TCP Connection(2)-127.0.0.1] org.apache.jasper.servlet.TldScanner.scanJars At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
[2020-04-06 05:42:40,701] Artifact Tarkshala-Scholars-Engine:war exploded: Artifact is deployed successfully
[2020-04-06 05:42:40,701] Artifact Tarkshala-Scholars-Engine:war exploded: Deploy took 4,521 milliseconds
[http-nio-8080-exec-1] INFO com.tarkshala.scholars.engine.webservices.AuthenticationService - Welcome to Tarkshala Scholar APIs
[http-nio-8080-exec-3] INFO com.tarkshala.scholars.engine.webservices.AuthenticationService - Welcome to Tarkshala Scholar APIs
06-Apr-2020 17:42:45.808 INFO [Catalina-utility-2] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory [/Users/kuldeep/Work/apps/apache-tomcat-9/webapps/manager]
06-Apr-2020 17:42:45.843 INFO [Catalina-utility-2] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory [/Users/kuldeep/Work/apps/apache-tomcat-9/webapps/manager] has finished in [35] ms
Pair of lines in the middle are the one logged by slf4j.
resources/log4j.properties looks like below
# Root logger option
log4j.rootLogger=DEBUG, stdout, file
# Redirect log messages to console
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
# Redirect log messages to a log file, support file rolling.
log4j.appender.file=org.apache.log4j.RollingFileAppender
log4j.appender.file.File=/Users/kuldeep/Work/repos/Tarkshala-Scholars-APIs/logs/application.log
log4j.appender.file.MaxFileSize=5MB
log4j.appender.file.MaxBackupIndex=10
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
pom.xml looks like below:
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.30</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.7.30</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.10</version>
<scope>provided</scope>
</dependency>
Java class looks like this:
@Slf4j
@Path("/authentication")
@Authorization
public class AuthenticationService extends SpringApplication {
@Path("/greet")
@GET
@Produces(MediaType.TEXT_PLAIN)
@PubliclyAllowed
public Response greet(){
log.info("Welcome to Tarkshala Scholar APIs");
return getBean(AuthenticationServiceHandler.class).greet();
}
}
I have few problems:
- Statement formatting, it should contain time in square brackets[].
- logs are not added to file given in configuration, infact I believe the configuration is not getting picked from the file.
No idea what exactly am I missing. Any help/hint is appreciated.
