Jason S
Jason S

Reputation: 189856

error setting up log4j configuration file

I must be doing something stupid here:

C:\tmp\log>java -jar logorrhea.jar -Dlog4j.configurationFile=c:/tmp/log/mblog4j.properties

ERROR StatusLogger No log4j2 configuration file found. Using default configuration: logging only errors to the console.

I'm following the directions in https://logging.apache.org/log4j/2.x/manual/configuration.html to set the log4j.configurationFile system property but it doesn't seem to work. (and there is a file called c:/tmp/log/mblog4j.properties present)

What could be going wrong?

My mblog4j.properties file looks like this:

# Setup loggers: default threshold = ERROR, but special stuff = INFO
log4j.rootLogger=ERROR,FILE
log4j.logger.com.example.mypackage=INFO,FILE

log4j.appender.FILE=org.apache.log4j.FileAppender
log4j.appender.FILE.File=c:/tmp/log/mb4j.log
log4j.appender.FILE.ImmediateFlush=true
# Set the append to false, overwrite
log4j.appender.FILE.Append=false
log4j.appender.FILE.layout=org.apache.log4j.PatternLayout
log4j.appender.FILE.layout.ConversionPattern= %-4r [%t] %-5p %c %x - %m%n

Upvotes: 0

Views: 1264

Answers (1)

Jason S
Jason S

Reputation: 189856

The problem was that the -Dlog4j.configurationFile needs to go before the -jar logorrhea.jar (and the file: prefix needs to be there as stdunbar says)

correct syntax:

java -Dlog4j.configurationFile=file:c:/tmp/log/mblog4j.properties -jar logorrhea.jar 

Also, the log4j 2 configuration is totally different than log4j 1.x; I had to revise my log configuration file to:

# Setup loggers: default threshold = ERROR, but special stuff = ALL
name = PropertiesConfig

property.filename = c:/tmp/log/mb4j.log

appenders = FILE

appender.FILE.type=File
appender.FILE.name=File
appender.FILE.append=false
appender.FILE.immediateFlush=true
appender.FILE.fileName=${filename}
appender.FILE.layout.type=PatternLayout
appender.FILE.layout.pattern= %-4r [%t] %-5p %c %x - %m%n

loggers = mb

logger.mb.name = com.example.mypackage
logger.mb.level = all
logger.mb.appenderRefs = FILE
logger.mb.appenderRef.FILE.ref = File

Upvotes: 1

Related Questions