system.util.getLogger
This function is used in Python Scripting.
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:
- Fatal - A severe error that will cause termination of the script.
- Error - A runtime error or other unexpected condition.
- Warn - An undesired condition, but one that does not interfere with execution.
- Info - An event that should be noted on the console, but is not an error.
- Debug - Detailed information useful in debugging.
- Trace - Highly detailed information.
To view log messages from Gateway scripts, in the Gateway go to Status > Diagnostics > 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 of debug or trace are discarded.
To change the logging level for a Logger in a Gateway script, go to Status > Diagnostics > Logs > Click the Settings () button. 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:
- Logger.fatal(String) - Logs a message with level fatal.
- Logger.fatalf(String, Args...) - Logs a formatted message with level fatal, using Java's Formatter syntax.
- Logger.error(String) - Logs a message with level error.
- Logger.errorf(String, Args...) - Logs a formatted message with level error, using Java's Formatter syntax.
- Logger.warn(String) - Logs a message with level warn.
- Logger.warnf(String, Args...) - Logs a formatted message with level warn, using Java's Formatter syntax.
- Logger.info(String) - Logs a message with level info.
- Logger.infof(String, Args...) - Logs a formatted message with level info, using Java's Formatter syntax.
- Logger.debug(String) - Logs a message with level debug.
- Logger.debugf(String, Args...) - Logs a formatted message with level debug, using Java's Formatter syntax.
- Logger.trace(String) - Logs a message with level trace.
- Logger.tracef(String, Args...) - Logs a formatted message with level trace, using Java's Formatter syntax.
- Logger.isTraceEnabled() - Returns True if the current log level is at least trace.
- Logger.isDebugEnabled() - Returns True if the current log level is at least debug.
- Logger.isInfoEnabled() - Returns True if the current log level is at least info.
Client Permission Restrictions
This scripting function has no Client Permission restrictions.
Syntax
system.util.getLogger(name)
Parameters
Type | Parameter | Description |
---|---|---|
String | name | The name of a logger to create. |
Returns
LoggerEx - A new Logger object used to log informational and error messages.
Scope
All
Code Examples
# This code would log a message with level info
logger = system.util.getLogger("myLogger")
logger.info("Hello, world.")
# This code would log a formatted message with level info.
who = 'Bob Jones'
num = 5
logger = system.util.getLogger("myLogger")
logger.info("Machine started by %s, employee ID %d"% (who, num))
# This code would log a formatted message with level info. Similar to the "Python String Formatting syntax" example above, but using Java's Formatter syntax
# 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)
# 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!")