Minor tweaks to logging which were helpful while debugging, including logging to stderr when running in foreground. --- unbound-dhcp-leases-bridge | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-)
diff --git unbound-dhcp-leases-bridge unbound-dhcp-leases-bridge index 814cf0c..17a00f6 100644 --- unbound-dhcp-leases-bridge +++ unbound-dhcp-leases-bridge @@ -26,6 +26,7 @@ import ipaddress import logging import logging.handlers import os +import sys import re import signal import stat @@ -36,22 +37,21 @@ import inotify.adapters
LOCAL_TTL = 60
+log = logging.getLogger("dhcp-bridge") + def setup_logging(loglevel=logging.INFO): - log = logging.getLogger("dhcp") log.setLevel(loglevel) - - handler = logging.handlers.SysLogHandler(address="/dev/log", facility="daemon") + if args.daemon: + handler = logging.handlers.SysLogHandler(address="/dev/log", facility="daemon") + else: + handler = logging.StreamHandler(sys.stderr) handler.setLevel(loglevel)
- formatter = logging.Formatter("%(name)s[%(process)d]: %(message)s") + formatter = logging.Formatter("%(name)s: %(message)s") handler.setFormatter(formatter)
log.addHandler(handler)
- return log - -log = logging.getLogger("dhcp") - def ip_address_to_reverse_pointer(address): parts = address.split(".") parts.reverse() @@ -602,7 +602,7 @@ if __name__ == "__main__": bridge = UnboundDHCPLeasesBridge(args.dhcp_leases, args.fix_leases, args.unbound_leases, args.hosts)
- ctx = daemon.DaemonContext(detach_process=args.daemon) + ctx = daemon.DaemonContext(detach_process=args.daemon, stderr=(None if args.daemon else sys.stderr)) ctx.signal_map = { signal.SIGHUP : bridge.update_dhcp_leases, signal.SIGTERM : bridge.terminate,