Closed remkop closed 4 years ago
I made the following changes:
src\main\resources\log4j2.xml
:
logs/ami.log
file (overwrite on each command)AbstractAMITool.addLoggingLevel
with plain logging and showstopperEncountered
flag AbstractAMIDictTool.addLoggingLevel
with plain logging and showstopperEncountered
flag DebugPrint.*Println
with plain logging with "DebugPrint" Marker
. We can configure this later to be routed to the console appender or something.AbstractAMITool.amiDebug
with plain logging with "amiDebug" Marker
. We can configure this later to be routed to the console appender or something.The log4j2.xml configuration by itself does 99% of the work: all WARN and ERROR level messages are printed to the console by default. (INFO, DEBUG and TRACE level messages only go to the log file).
The user has some control via the --verbose
and --log4j
options in ami
and amidict
. We use a custom picocli execution strategy to update the logging configuration before executing the command. If the user specifies -v
, then INFO level messages are also shown on the console. If the user specified -vv
, then DEBUG level messages are shown on the console, etc.
See AMI.LoggingOptions#reconfigureLogging for details.
Note that this reconfiguration is done by setting the log level of the Console Appender in the log4j configuration. We no longer use Logger.setLevel
to change the log level of individual loggers.
One issue remains to complete this topic:
many tools print the values of the @Option
-annotated fields in the parseSpecifics
method, for troubleshooting purposes.
The majority of the tools use System.out.println
for this. Peter and I agreed in a Skype call earlier that it is better to use the logging library for this so that the values are also captured in the log file instead of only on the console.
My question is, what log level to use for this: WARN
(visible by default) or INFO
(only visible if users specify --verbose
on the console)? My intuition is to be quiet by default, so I would use INFO, but perhaps others have a different view?
I think quiet by default because when we have trouble we can switch the -v
on. It's also useful to keep test output brief.
And many thanks to @remkop for managing this.
Closing, I believe our logging strategy is working well.
I created https://github.com/petermr/ami3/issues/54 as a follow-up item.
From the Slack chat: