Error: “setFile(null,false) call failed” when using log4j

I suspect that the variable ${file.name} is not substituted correctly. As a result, the value of log4j.appender.FILE.File becomes logs/. As such, Java tries to create a log file named logs/, but probably it is an existing directory, so you get the exception. As a quick remedy, change the log4j.appender.FILE.File setting to point to file by … Read more

What is log4j’s default log file dumping path

To redirect your logs output to a file, you need to use the FileAppender and need to define other file details in your log4j.properties/xml file. Here is a sample properties file for the same: # Root logger option log4j.rootLogger=INFO, file # Direct log messages to a log file log4j.appender.file=org.apache.log4j.RollingFileAppender log4j.appender.file.File=C:\\loging.log log4j.appender.file.MaxFileSize=1MB log4j.appender.file.MaxBackupIndex=1 log4j.appender.file.layout=org.apache.log4j.PatternLayout log4j.appender.file.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} … Read more

How to specify Log4J 2.x config location?

You could use the static method #initialize(String contextName, ClassLoader loader, String configLocation) (see source here) in org.apache.logging.log4j.core.config.Configurator. (You can pass null for the class loader.) Be aware that this class is not part of the public API so your code may break with any minor release. For completeness, you can also specify the location of … Read more

Does log4j support JSON format?

this is official JSON layout https://github.com/logstash/log4j-jsonevent-layout 1) Add maven dependency https://mvnrepository.com/artifact/net.logstash.log4j/jsonevent-layout <dependency> <groupId>net.logstash.log4j</groupId> <artifactId>jsonevent-layout</artifactId> <version>1.7</version> </dependency> 2) Add configuration to your log4j.properties file log4j.rootCategory=WARN, RollingLog log4j.appender.RollingLog=org.apache.log4j.DailyRollingFileAppender log4j.appender.RollingLog.Threshold=TRACE log4j.appender.RollingLog.File=api.log log4j.appender.RollingLog.DatePattern=.yyyy-MM-dd log4j.appender.RollingLog.layout=net.logstash.log4j.JSONEventLayoutV1

How can I access the configured Log4J appenders at runtime?

Appenders are generally added to the root logger. Here’s some pseudocode // get the root logger and remove the appender we want Logger logger = Logger.getRootLogger(); Appender appender = logger.getAppender(“foo”); logger.removeAppender(appender) // when we want to add it back… logger.addAppender(appender); I’m pretty sure you can do this on other loggers than the root logger as … Read more

External log4j.xml file

When using the -jar switch to launch an executable jar file, the classpath is obtained from the jar file’s manifest. The -cp switch, if given, is ignored. Jeff Storey’s answer is going to be the easiest solution. Alternatively, you could add a Class-Path attribute to the jar file’s manifest. EDIT Try enabling log4j debugging, and … Read more

Is Logback also affected by the Log4j zero-day vulnerability issue in Spring Boot? [closed]

From the Spring blog: Spring Boot users are only affected by this vulnerability if they have switched the default logging system to Log4J2. The log4j-to-slf4j and log4j-api jars that we include in spring-boot-starter-logging cannot be exploited on their own. Only applications using log4j-core and including user input in log messages are vulnerable. Useful explanation points: … Read more