add support for syslog on freebsd
This commit is contained in:
parent
0e61eee899
commit
0708e200c8
@ -1,7 +1,9 @@
|
|||||||
import argparse
|
import argparse
|
||||||
import logging
|
import logging
|
||||||
import logging.handlers
|
import logging.handlers
|
||||||
|
import os
|
||||||
import re
|
import re
|
||||||
|
import stat
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
import rotator
|
import rotator
|
||||||
@ -83,11 +85,23 @@ def main():
|
|||||||
handler.setLevel(logging.WARNING)
|
handler.setLevel(logging.WARNING)
|
||||||
log.addHandler(handler)
|
log.addHandler(handler)
|
||||||
|
|
||||||
handler = logging.handlers.SysLogHandler(address='/dev/log')
|
handler = None
|
||||||
|
for logsocket in ('/var/run/log', '/dev/log'):
|
||||||
|
try:
|
||||||
|
mode = os.stat(logsocket).st_mode
|
||||||
|
except FileNotFoundError:
|
||||||
|
continue
|
||||||
|
|
||||||
|
if stat.S_ISSOCK(mode):
|
||||||
|
handler = logging.handlers.SysLogHandler(address=logsocket)
|
||||||
formatter = logging.Formatter(fmt='rotator[%(process)s] %(message)s')
|
formatter = logging.Formatter(fmt='rotator[%(process)s] %(message)s')
|
||||||
handler.setFormatter(formatter)
|
handler.setFormatter(formatter)
|
||||||
handler.setLevel(logging.INFO)
|
handler.setLevel(logging.INFO)
|
||||||
log.addHandler(handler)
|
log.addHandler(handler)
|
||||||
|
break
|
||||||
|
|
||||||
|
if not handler:
|
||||||
|
log.warning('No syslog socket found, will not log to syslog')
|
||||||
|
|
||||||
args = parse_args()
|
args = parse_args()
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user