fix logging and configfile location on freebsd

This commit is contained in:
Fredrik Eriksson 2020-12-21 17:01:38 +01:00
parent 3d6997b3be
commit d1d9c3ca15
Signed by: feffe
GPG Key ID: F4329687B0FA7F8D

View File

@ -288,7 +288,8 @@ def weed_snapshots(fslist, snapshots, config, failed_snapshots):
def main(): def main():
config = configparser.ConfigParser() config = configparser.ConfigParser()
config.read('/etc/zsnapper.ini') config.read('/usr/local/etc/zsnapper.ini', '/etc/zsnapper.ini')
ret = RET_CODES['SUCCESS'] ret = RET_CODES['SUCCESS']
log = logging.getLogger(LOGGER) log = logging.getLogger(LOGGER)
@ -403,9 +404,22 @@ if __name__ == '__main__':
handler.setLevel(logging.WARNING) handler.setLevel(logging.WARNING)
log.addHandler(handler) log.addHandler(handler)
handler = logging.handlers.SysLogHandler(address='/dev/log') handler = None
formatter = logging.Formatter(fmt='zsnapper[%(process)s] %(message)s') for logsocket in ('/var/run/log', '/dev/log'):
handler.setFormatter(formatter) try:
handler.setLevel(logging.INFO) mode = os.stat(logsocket).st_mode
log.addHandler(handler) except FileNotFoundError:
continue
if stat.S_ISSOCK(mode):
handler = logging.handlers.SysLogHandler(address=logsocket)
formatter = logging.Formatter(fmt='zsnapper[%(process)s] %(message)s')
handler.setFormatter(formatter)
handler.setLevel(logging.INFO)
log.addHandler(handler)
break
if not handler:
log.warning('No syslog socket found, will not log to syslog')
sys.exit(main()) sys.exit(main())