Search code examples
javalog4jsyslog

How do you change the level translation for log4j SyslogAppender?


By default, the FATAL level in log4j will map to emergency in Syslog. Because of IT syslog usage requirements in our corporation, I need FATAL to map to syslog alert instead.

Does anyone know of a simple way to accomplish this?


Solution

  • There is guidance here on how to do this by overriding the append method in the SyslogAppender class. afai can see the mappings in log4j are hard-coded.

    If you use logger.fatal(), the standard log4j syslog appender will log this message with the highest syslog severity, which is level 0, "emerg". This level is usually reserved for the most urgent operating system related messages and on most Unix systems will print the message on the terminal session of every logged in user. For most applications, this is probably not what you want. If an application encounters a fatal error, it should log the message as a lower level like "critical", level 2. You can do this by implementing an appender which overrides the "append" method.