0.3.1 Release Notes
Bug Fix
- Fix Eclipse "flickering" of uncolored log messages. The ANSI codes are now reset for every log entry:
- Add cyan color to DEBUG and green color to TRACE
0.3.0 Release Notes
New Features
- Colored logs!
- Clickable location in Eclipse is back (added ".java")
Bug fixes
- Fix bug where setting `-Dlog.level=warn` would not set `us.ihmc` classes (Error rendering macro 'jira' : Unable to locate Jira server for this macro. It may be due to Application Link configuration.)
- Fix bug where order made a difference when setting multiple levels
0.2.2 Release Notes
Tuning
- Add logger name to all messages logged by non-IHMC loggers, as they do not normally include their source
- Use new date/time format:
20181005 13:13 [INFO] (LogTools:151): Granular logging mode enabled. Not realtime safe. 20181005 13:13 [ERROR] (LogToolsDemo:37): Demo there 20181005 13:13 [WARN] (LogToolsDemo:38): var1: 9, var2: false 20181005 13:13 [INFO] (LogToolsDemo:39): Demo there 20181005 13:13 [DEBUG] (LogToolsDemo:29): Hi I'm subclass 2
Bug fix
- Fix Gradle user logging properties not getting through to deployed applications
0.1.7 Release Notes
Bug Fix
- Add slf4j impl compatibility runtime library to fix external SLF4J logger bindings
0.1.6 Release Notes
Initial release!
Features
- Zero-configuration required API. Use
LogTools.info("msg")
right out of the box, from anywhere. - Realtime safe by default as long as info and higher level messages are non-recurring.
- Provides Java and Gradle properties for setting log levels.
- Granular non-realtime mode for setting log levels of packages and classes.
- Adds class name and line number to all log entries.
Download
plugins { id "us.ihmc.log-tools" version
} // Gradle plugin
compile group: "us.ihmc", name: "log-tools", version:
` // API`
API
To log messages, use the static LogTools
methods.
Log tools provides the following log levels: off
, fatal
, error
, warn
, info
, debug
, trace
, and all
.
Each levels has no special behavior other than it's importance to the end user. fatal
is most important and trace
is least important. Find conventional meanings for the levels here: https://en.wikipedia.org/wiki/Log4j#Log4jloglevels.
To set log levels you can pass JVM arguments: - -Dlog.level=<level>
: Set root log level, including all software on the classpath that uses SLF4J compatible log APIs. - -Dlog.granular=<true|false>
: Enable granular mode, allowing setting levels for arbitrary classpaths. (NOT realtime safe) - -Dlog.level.us.ihmc=<level>
: Set the log level of all IHMC software. In granular mode, this instead refers to all code in the us.ihmc
package. - -Dlog.level.<classpathPrefix>=<level>
: If granular mode is true
or unset: Set the log level of a package or class.
Note: For convenience, granular mode is automatically activates when at least one -Dlog.level.<classpathPrefix>=<level>
is present. Setting -Dlog.level.us.ihmc=<level>
or -Dlog.level=<level>
will NOT enable granular mode and are always safe to use.
Examples:
<pass nothing> // all log levels set to info, realtime safe
-Dlog.level=info // same as default, realtime safe
-Dlog.level=off // disable all SLF4J compatable logging, realtime safe
-Dlog.level.us.ihmc=debug // debug IHMC software only, realtime safe
-Dlog.level.us.ihmc.avatar.behaviors=debug // debug behaviors package only, NOT realtime safe
-Dlog.level.us.ihmc.variables.YoDouble=trace // Enables trace level on YoDouble class, NOT realtime safe
-Dlog.granular=true -Dlog.level.us.ihmc.communication=trace // Enables trace level on YoDouble class, NOT realtime safe
-Dlog.granular=false -Dlog.level.us.ihmc.communication=trace // Does NOT enable trace level on YoDouble class, realtime safe
Realtime safety
To ensure your code is realtime safe:
- Never build strings in a
LogTools
call. - Use the
LogTools.xxxx("var1: {}, var2: {}", var1, var2)
methods to build strings from variables. - Use a message
Supplier
to build complex messages, but do not inline it. - Do not log
info
,warn
,error
, orfatal
levels more than a predetermined maximum amount.- If an error message is printed on some math failure, have a counter such that it becomes silent after 5 or so occurances.
- Do not set
-Dlog.granular=true
or set any levels by package or class.- You may safely use
-Dlog.level=level
to set the global level (including non-ihmc messages) - You may safely use
-Dlog.level.us.ihmc
to set the log level of everything going though theLogTools
API - You may NOT safely set any other log level i.e.
-Dlog.level.*
, unless you explicity set-Dlog.granular=false
, which sets to ignore all-Dlog.level.*
property. This is to make it convenient to quickly switch between modes without deleting complex level settings.
- You may safely use
Some examples:
LogTools.info("str1 {}", someStrVariable) // SAFE
LogTools.info("str1" + someStrVariable) // NOT realtime safe
Supplier<String> supplier = () -> "string" + "builder"; // as field or existing method, created once
[...]
LogTools.info(supplier) // SAFE
LogTools.info(() -> { "string" + "builder"}) // NOT realtime safe, allocates new Supplier<String>()
Gradle plugin
The Gradle plugin exists solely to provide a wrapper for the JVM properties. All properties are the same as above. Just replace -D
with -P
.
The plugin applies the log settings to all JVMs spawned by Gradle to run your applications. This includes: - test
task JVMs - Custom, user defined, JavaExec
tasks - run
task provided by the application
plugin - Scripts generated by the installDist
task provided by the application
plugin
To run tests, only logging errors:
> gradle test -Plog.level=error