Top | Previous | Next |
system.util.getLogger |
Description Returns a Logger object that can be used to log messages to the console.
Each Logger has a name, which is typically structured hierarchically using periods, indicating where in the project the Logger is used. You can use any naming scheme you like, however a well-planned naming scheme makes finding log entries and setting log levels much easier. Loggers can be shared between scripts simply by giving them the same name.
Six levels of logging are available:
To view log messages from Gateway scripts, in the Gateway go to Configure > System > Console > Logs. To view log messages from Client scripts, including scripts in components, in the Client go to Help > Diagnostics > Log Viewer, or in the Designer go to Tools > Console.
The default logging level is info, meaning that all messages with level info or higher are logged, and messages with a level or debug or trace are discarded. To change the logging level for a Logger in a Gateway script, go to Configure > System > Console > Levels. The new logging level will remain until it is changed or the Gateway is restarted. To change the logging level in a Client script, go to Help > Diagnostics > Logging Levels. Logging levels can not be changed in the Designer.
The following methods are available to a Logger:
Syntax system.util.getLogger(name) Parameters String name - The name of a logger to create. Returns LoggerEx - A new Logger object used to log informational and error messages. Scope All Examples Example 1:
# This code would log a message with level info logger = system.util.getLogger("myLogger") logger.info("Hello, world.")
Example 2:
# This code would log a formatted message with level info. # Note the 'f' at the end of the method name. who = 'Bob Jones' num = 5 logger = system.util.getLogger("myLogger") logger.infof("Machine started by %s, employee ID %d", who, num)
Example 3:
# This code would check if the debug level is enabled for this logger before # executing the remaining code. Although not needed for a simple log entry like # in this example, it can eliminate expensive function calls in a more complex # log entry. logger = system.util.getLogger("myLogger") if logger.isDebugEnabled(): logger.debug("Hello, world!")
|