0
votes

I have two problems with log4j2:

  1. I cannot figure out how to specify the log root level in the command line.

I execute runnable jar with log4j2.xml config file

java -Dlog4j.configurationFile=log4j2.xml  -jar my.jar

The log4j2.xml has default loggers root log level set to INFO. But sometimes I need to specify DEBUG.

  1. -Dlog4j.configurationFile=log4j2.xml does not work on Windows though it works fine on Mac and Linux. log4j2.xml does exist in current folder.

I get error when executing above mentioned command line with Windows PowerShell

Error: Could not find or load main class .configurationFile=log4j2.xml

I tried -Dlog4j.configurationFile=file://log4j2.xml or -Dlog4j.configurationFile=./log4j2.xml or -Dlog4j.configurationFile=file://<full_path_to_log4j2.xml> the same error

1

1 Answers

0
votes
  1. Define a property named "rootLevel" as

    ${sys:rootLevel:=INFO}

then on your root Logger specify

<Root level="${rootLevel}">

The root level will now default to Info and you can override it with -DrootLevel=DEBUG on the command line.

  1. The problem is the dot in the property name. On Windows you need to put it in quotes.