Logs are not displayed in stdout.

I use for logging slf4j and slf4j .

Initially, when the project was not multi-modular, everything worked perfectly. But as soon as I made a maven multi-module project out of it, then all the logs were no longer displayed (except for the standard INFO level).

slf4j and slf4j connected in the parent pom.xml :

 <?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/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>department-app</groupId> <artifactId>department-app</artifactId> <version>1.0-SNAPSHOT</version> <packaging>pom</packaging> <name>department</name> <modules> <module>rest</module> <module>web-app</module> </modules> <dependencies> <dependency> <groupId>log4j</groupId> <artifactId>log4j</artifactId> <version>1.2.17</version> </dependency> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-simple</artifactId> <version>1.5.6</version> </dependency> </dependencies> </project> 

Configure log4j:

 log4j.rootLogger=DEBUG, stdout 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 

There is also logging in the controller, but it also does not work:

 private final Logger logger = LoggerFactory.getLogger(EmployeesController.class); @RequestMapping(value = "/remove/employee/{id}", method = RequestMethod.POST) public List<Employees> deleteEmployeeById(@PathVariable("id") Long id){ employeesService.delete(id); logger.info(id + "deleted successful"); return employeesService.getAll(); } 
  • is there spring-boot? If so, then there it is necessary to remove spring-boot-logger dependencies, maybe it slips its version of log4j. And what at the start of the application writes? Should swear if it does not find the configuration file, if there is nothing like that, then you need to check the settings of the logger. - Artem Konovalov
  • no, I don't use it - BigBadDev
  • And how to check these settings? - BigBadDev
  • Why do you use two loggers together? What kind of project is spring, jersey? Little information I can not give you a piece of advice. - Artem Konovalov
  • This is spring project - BigBadDev

1 answer 1

Here is an example of log4j.properties and pom.xml . Try to do as I have in the example. I also use modules in my project, which have separate pom.xml. My example below pom.xml belongs to the module, not the main project. Example log4j.properties , in which settings are specified for both stdout and log file:

 #Root logger option log4j.rootLogger = INFO, CONSOLE, SYSLOG, FILE log4j.logger.org.springframework.data.mongodb = ERROR log4j.logger.путь.к.вашему.каталогу = DEBUG #Direct log messages to stdout log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender log4j.appender.CONSOLE.Target=System.out log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout log4j.appender.CONSOLE.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p [%t] %c{1}:%L - %m%n # Syslog appender log4j.appender.SYSLOG = org.apache.log4j.net.SyslogAppender log4j.appender.SYSLOG.syslogHost = localhost log4j.appender.SYSLOG.layout=org.apache.log4j.EnhancedPatternLayout log4j.appender.SYSLOG.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss}{UTC} %-5p [%t] %c{1}:%L - %m%n log4j.appender.SYSLOG.Facility = LOCAL0 # Direct log messages to a log file #log4j.appender.FILE=org.apache.log4j.FileAppender log4j.appender.FILE=org.apache.log4j.RollingFileAppender log4j.appender.FILE.File=/var/log/ваш_название/ваш_название.log log4j.appender.FILE.MaxFileSize=100MB log4j.appender.FILE.MaxBackupIndex=10 log4j.appender.FILE.layout=org.apache.log4j.EnhancedPatternLayout log4j.appender.FILE.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss}{UTC} %-5p [%t] %c{1}:%L - %m%n 

In pom.xml there will be only those dependencies that are needed for log4j :

org.slf4j slf4j-api 1.7.7

 <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-log4j12</artifactId> <version>1.7.7</version> </dependency> <dependency> <groupId>log4j</groupId> <artifactId>apache-log4j-extras</artifactId> <version>1.2.17</version> </dependency>