Windchill REST Services Framework Capabilities > Logging for Windchill REST Services
Logging for Windchill REST Services
Because Windchill REST Services is compiled and released across several Windchill releases a wrapper around logging has been created to support log4j versions 1 and 2. Two new classes are available for logging. They are mostly a drop in replacement for the log4j classes we use.
ODataLogger
ODataLogger is the main class for logging. It’s a replacement for the elog4j Logger class, so instead of:
Logger LOGGER = Logger.getLogger(Some.class);
you can use instead:
ODataLogger LOGGER= ODataLogger.getLogger(Some.class);
ODataLogger is a drop in replacement for the log4j Logger class, so updating existing code is a simple matter of replacing Logger with ODataLogger when creating the logger, otherwise all subsequent calls on the logger remain the same.
ODataLogLevel
A less likely use case is setting the log level on a logger. In fact log4j version 2 recommends you do not set the level programmatically and has removed the API from the public use. Nonetheless, ODataLogger has created a wrapper API to allow you set the level. Again, it is a drop in replacement for log4j:
(ODataLogger)LOGGER.setLevel(ODataLogLevel.WARN);
One note is that is it slightly different than the log4j version in that the parameter to setLevel is an Object type instead of a log4j Level type since the type will be different depending on whether or not you are using log4j version 1 or version 2. The return type of getLevel() is also an Object, so the latter will be:
Object originaLevel = LOGGER.getLevel();
LOGGER.setLevel(ODataLogLevel.WARN);
// Do stuff
LOGGER.setLevel(originalLevel);
LogR
Object originaLevel = LOGGER.getLevel(); LOGGER.setLevel(ODataLogLevel.WARN); // Do stuff LOGGER.setLevel(originalLevel);
LogR.getLogger(Some.class.getName())
use instead:
ODataLogger.getLoggerViaLogR(Some.class.getName());
这对您有帮助吗?