I use JSON logging and wanted use SysLogHandler with UDP port 514. Eventually got JSON handler config working. In the handlers section, I have:
{
"syslog": {
"class": "logging.handlers.SysLogHandler",
"address": ["127.0.0.1", 514],
"facility": "local6",
"formatter": "syslog_fmt"
}
Didn't find this anywhere else.
[Edit]
To be clearer about what is going on here: this is only for python code, and using python's built in logging module. The module allows format and destination(s) of the log messages to be configured. One way to configure the log format and destination(s) is by using a JSON file that is used to configure the logging.
The above example allowed me to send log messages to a syslog daemon.
A complete example of such a file is included below.
{
"version": 1,
"disable_existing_loggers": "False",
"formatters": {
"verbose": {
"format": "%(asctime)s:%(levelname)s:%(process)d:%(filename)s:%(funcName)s:L%(lineno)d:%(message)s"
},
"syslog": {
"format": "%(levelname)s:%(process)d:%(filename)s:%(funcName)s:L%(lineno)d:%(message)s"
}
},
"handlers": {
"console": {
"class":"logging.StreamHandler",
"formatter": "standard"
},
"syslog": {
"class": "logging.handlers.SysLogHandler",
"address": ["127.0.0.1", 514],
"facility": "local6",
"formatter": "syslog_fmt"
}
},
"loggers": {
"": {
"handlers": ["console","syslog"],
"level": "DEBUG",
"propagate": "True"
}
}
}
The example above sends python log messages to both syslog and the console. The format of messages for destinations is different (syslog already prefixes each message with a timestamp). For the syslog destination, the log uses facility LOCAL6.