Project log4j Debugging on --verbose: Difference between revisions
(→API) |
|||
Line 18: | Line 18: | ||
</blockquote> | </blockquote> | ||
<tt>StderrVerboseLogging</tt> comes with an <tt>init()</tt> static utility method that looks at the "verbose" system property and turns on stderr logging. The recommended usage pattern is: | |||
<pre> | <pre> | ||
import io.novaordis.utilities.logging.StderrVerboseLogging; | import io.novaordis.utilities.logging.StderrVerboseLogging; | ||
StderrVerboseLogging.init(); | |||
</pre> | </pre> | ||
<tt>StderrVerboseLogging | You should call <tt>StderrVerboseLogging.init()</tt> as early as possible after the JVM starts running. For suggestion on how to pass the logging verbosity option from the shell wrapper to the JVM, see [[#Shell_Wrapper_Recommendations|Shell Wrapper Recommendations]] below. | ||
If you want to enable logging manually in the program, use: | |||
<pre> | <pre> | ||
import io.novaordis.utilities.logging.StderrVerboseLogging; | import io.novaordis.utilities.logging.StderrVerboseLogging; | ||
StderrVerboseLogging. | ... | ||
if (verbose) { | |||
StderrVerboseLogging.enable(); | |||
} | |||
... | |||
</pre> | </pre> | ||
Revision as of 20:51, 22 January 2017
Internal
Overview
This is a development pattern that routes log4j logging information to stderr if -v or --verbose command line options are used. Projects that implement it are clad, os-stats, gld, etc.
API
Use novaordis-utilities 4.2 or newer. novaordis-utilities 4.2.0 was the first release that contains StderrVerboseLogging.
For more details, see:
StderrVerboseLogging comes with an init() static utility method that looks at the "verbose" system property and turns on stderr logging. The recommended usage pattern is:
import io.novaordis.utilities.logging.StderrVerboseLogging; StderrVerboseLogging.init();
You should call StderrVerboseLogging.init() as early as possible after the JVM starts running. For suggestion on how to pass the logging verbosity option from the shell wrapper to the JVM, see Shell Wrapper Recommendations below.
If you want to enable logging manually in the program, use:
import io.novaordis.utilities.logging.StderrVerboseLogging; ... if (verbose) { StderrVerboseLogging.enable(); } ...
Shell Wrapper Recommendations
The recommended way to pass the "verbose" information that was already identified by a bash wrapper to the JVM is to use:
-Dverbose=true
Typical bash wrapper code:
verbose=false ... ${verbose} && verbose_system_property="-Dverbose=true" command="${java_bin} ... ${verbose_system_property} ${main_class}..."