简体   繁体   中英

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM