I have built a Java command-line tool that uses SLF4J (the simple
binding) for logging. Throughout its codebase I have many different INFO
, TRACE
, WARN
and ERROR
statements. Normally, when users run this tool, I would like it to only log INFO
and above (so: INFO
, WARN
and ERROR
). However, I would like users to be able to supply a --verbose
(or -v
) option at the command-line, and have TRACE
messages get logged as well.
To reiterate, normal command-line invocation:
java -jar mytool.jar --fizz "30" --buzz "true"
But in "verbose mode":
java -jar mytool.jar --fizz "30" --buzz "true" --verbose
I know I can configure SLF4J setting from the command line like so:
java -jar -Dorg.slf4j.simpleLogger.defaultLogLevel "trace" mytool.jar --fizz "30" --buzz "true"
But this isn't as user friendly, and it also "leaks" the fact that SLF4J is the underlying logging system to the end user. Not that I'm worried about security, it just feels like a less-than-elegant config solution. IMHO, the end user of this tool shouldn't have to know any implementation details about the tool in order to run it, especially what a TRACE
log level means or represents.
Any ideas?