I use logj2

log4j2.xml

<?xml version="1.0" encoding="UTF-8"?> <configuration monitorInterval="3"> <appenders> <File name="FILE" fileName="logs/error.log"/> </appenders> <loggers> <root level="error"> <appender-ref ref="FILE"/> </root> </loggers> </configuration> 

There is MainClass: Start

If I write in Start

 public static Logger log = LogManager.getLogger(Start.class); 

then everything is fine, the logs are written If I write such lines, for example in SomeClass

 public static Logger log = LogManager.getLogger(SomeClass.class); 

then log4j issues at runtime

log4j: WARN No appenders could be found for logger (some.SomeClass). and logs are not written for this class

    1 answer 1

    You do not write the configuration correctly, try the following, and then add an appender file there.

     <?xml version="1.0" encoding="UTF-8"?> <Configuration status="WARN"> <Appenders> <Console name="Console" target="SYSTEM_OUT"> <PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/> </Console> </Appenders> <Loggers> <Root level="error"> <AppenderRef ref="Console"/> </Root> </Loggers> </Configuration> 
    • same result - Dmitry
    • Add a logger for the package to the configuration. - Roman C
    • do not quite understand. <Loggers> <Logger name = "some.SomeClass"> ... </ Logger> ... </ Loggers> - was that meant? - Dmitry
    • something like a package only. - Roman C