Logging in Maximo Jython scripts
When you develop scripts with more than a couple of lines of code it is always useful to write some information to a log. Maximo has a very powerful logging engine based on the Apache log4j Java based logging utility.
In the first part of this Blog I will show you how the logging engine will be configured. In the second part we will discover the technics to utilize the logging system from our Jython scripts.
Preparation of Maximo Logging
The Logging configuration in Maximo can be found in the following menu:
Goto > System Configuration > Plattform Configuration > Logging
The first think we have to do is to create a new Appender. This is basically the definition of the logfile where the log is written to. You can either define a common customscript logfile or define different logs for larger scripts. From the Logging application select the Action „Manage Appenders“ and the following screen occurs:
By selecting „New Row“ you can add an additional Appender. Fill in the values as shown below and press OK at the end.
You are now back at the entry screen for logging. Go to the Filter bar an search for the „autoscript“ Root Logger entry.
As you can see there are no specific Loggers defined under this entry. You can now define your own Customscript Logger by pressing the „New Row“ button in the Loggers section. Fill in the following values:
Important is to select the „Appenders“ entry „customscript“. This is the additional appender for this Logger which will write to the customscript.log file.
To apply your new settings there is no save button. You have to select the Action „Apply Settings“ to enable the new Logger you just have defined.
Using the customscript Logger
To use the scripting engine you first have to initialize a new Logger. This can be done by the following statement:
myLogger = MXLoggerFactory.getLogger(„maximo.script.customscript")
After that the logger can be easily used:
myLogger.info(“<message>”) writes one line to the log with the selected message level. Only levels equals or higher then selected in the customscript logger are really written to the logfile.
A complete example looks like this:
from psdi.util.logging import MXLoggerFactory myLogger = MXLoggerFactory.getLogger("maximo.script.customscript") myLogger.debug(“This is a debug entry") myLogger.info(“This is an info entry") myLogger.warn(“This is a warning entry") myLogger.error(“This is an error entry") myLogger.fatal(“This is a fatal entry")
Thank you for advising to create a new logger.
People using maximo.script is a real problem.
you may want to consider using a completely custom logger as a number of articles/technotes say to use maximo.script
That way if people start setting maximo.script to DEBUG (and related children) this script won’t be affected