Tuesday, July 30, 2024

Maximo Loggers and Appenders

What is Logging ?
  • Logging is required for investigating issues in Live system. 
  • Without logging, it's very difficult to identify the source of the problem for resolution
Maximo Logging
  • Maximo Uses Log4j. Log4j is an open source independent logging framework developed by Apache. It's not part of standard Java API.
  • Log4j provides the ability to selectively enable or disable logging requests based on Maximo logger.
  • Log4j allows logging requests to print to multiple destinations (or Maximo Appenders). 
Logging properties in Maximo
  • Logging properties are available inside Maximo application (System Configuration --> Platform Configuration --> Logging) and stored in the database.
  • There are 3 components on properties: Loggers, Log Appenders and Layout
What are Maximo Loggers ? 
  • Loggers are the component of Maximo that prepare log statements
  • It follows hierarchical naming rules with dot notation

How Log statements are handled ? 

         Log statements are either written to User Interface consoles or sent as output to log files.

What is Maximo Root Logger ? 
  • Root Loggers are at top application functional level or main subtopic of loggers.
  • A logger is said to be an parent of another logger if its name followed by a dot is a prefix of the child logger name.
  • Without root (or main) logger, no logging will work in Maximo.

What is a child logger ? 
  • Parents are root loggers and child loggers are the loggers that inherit the log message level of the root logger. 
  • They contain the name of the root logger in their names.
Can we deactivate loggers ? 
  • Root Loggers can't be deactivated, but child loggers can be deactivated.
  • System Users determine the size that is required for Appenders. 
What is an Appender ? 
  • An Appender is a log file or location created by Maximo where log information is written.
  • Each enabled logging request for a given logger will be forwarded to all the linked Appenders as well as the Appenders higher in the hierarchy.
  • Appenders are used to forward log messages to different destinations such as files, databases, console, cloud etc.,
  • Log4j appenders exist for the Console, files, GUI components, remote socket servers, JMS, NT Event Loggers, and remote UNIX Syslog daemons. 
  • Maximo uses only file type Appenders.  
Maximo has 3 predefined Appenders:
  • Console - Writes log information to Console or std.out (SystemOut.log file)
  • RollingWrites log information to specified file name and rolls to a new file when size is reached
  • Daily RollingWrites log information to specified file name and rolls to a new file by EOD
MX File Appender is Maximo's extension of Log4J Appenders: 
psdi.util.logging.MXDailyFileAppender.MXFileAppender psdi.util.logging.MXDailyFileAppender.MXDailyFileAppender

Log Appender Layout
  • Layout is used to format the log output written to a file.
  • A layout is associated with a Log4J appender
    • log4j.appender.Console.layout=psdi.util.logging.MaxPatternLayout
    • log4j.appender.Console.layout.ConversionPattern=%d{dd MMM yyyy HH:mm:ss:SSS} [%-2p] [%s] [%q] %m %n %C{1} %M{1} %L %t
    


      • %d - date format given inside brackets{ } 22 JUL 2024 16:40:57:636
      • %-2p - log level [INFO] priority of logging event, left justified to a width of 2 characters
      • %s - Maximo Server Name  [MXServer-UI1]
      • %q - Log correlation entries in format [CID-TYPE-NUMBER]. TYPE is CRON or UI. To enable this property, we need to activate a couple of system properties: mxe.logging.CorrelationEnabled=true Crontask & REST correlation will be enabled. A child property mxe.webclient.logging.CorrelationEnabled=false for enabling UI request Correlation. Logger pattern [%q] and System property both need to be enabled to display correlation log ID. Each Correlation type has its own set of properties and they are printed at end of correlation log. UI request correlation prints out app name, UI session id, UI event identifier, client IP, elapse time etc. Crontask action correlation prints out Crontask name, instance name and elapse time.
      • %m - Maximo message BMXAA6719I
      • %n - System independent new line separator
      • %C - fully qualified class name of the caller issuing the logging request psdi.app.actionscfg.CustomClass %C{1} - CustomClass
      • %L - line number of the code  psdi.app.actionscfg.CustomClass 272
      • %M - method name of the Class issuing the logging request
      • %t - thread name that generated the logging event
      • %F - File name 
      •      


How do Loggers and Appenders interact ? 
  • A Logger can have either one or multiple Appenders. 
  • An Appender can have output from either one or multiple loggers. 
Log Message Levels
  • Every loggers needs a log level There are 5 log message levels in Maximo: FATAL < ERROR < WARN < INFO < DEBUG
  • If a given logger is not assigned a level, then it inherits one from its closest ancestor with an assigned level
Logger in Automation Script
from psdi.util.logging import MXLoggerFactory  
logger = MXLoggerFactory.getLogger("maximo.script")

logger.debug ("Debug level log messages")
logger.info ("Info level log messages")
logger.warn ("Warn level log messages")
logger.error ("Error level log messages")
logger.fatal ("Fatal level log messages")
Impacts
  • Enabling UI correlation causes a delay because of light weight filter for UI events.
  • Enabling %C caller class name, %M method name, %L caller class line number and %F file location are extremely slow and should only be activated on critical investigation or performance is not an issue.
References: