From mboxrd@z Thu Jan 1 00:00:00 1970 From: Anthony Heading To: development@lists.ipfire.org Subject: [PATCH 3/3] unbound-dhcp-leases-bridge : minor logging improvements Date: Mon, 21 Mar 2022 23:47:56 -0400 Message-ID: <20220322034756.36327-3-ajrh@ajrh.net> In-Reply-To: <20220322034756.36327-1-ajrh@ajrh.net> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="===============8383287611620836056==" List-Id: --===============8383287611620836056== Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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 =20 LOCAL_TTL =3D 60 =20 +log =3D logging.getLogger("dhcp-bridge") + def setup_logging(loglevel=3Dlogging.INFO): - log =3D logging.getLogger("dhcp") log.setLevel(loglevel) - - handler =3D logging.handlers.SysLogHandler(address=3D"/dev/log", facility= =3D"daemon") + if args.daemon: + handler =3D logging.handlers.SysLogHandler(address=3D"/dev/log", facility= =3D"daemon") + else: + handler =3D logging.StreamHandler(sys.stderr) handler.setLevel(loglevel) =20 - formatter =3D logging.Formatter("%(name)s[%(process)d]: %(message)s") + formatter =3D logging.Formatter("%(name)s: %(message)s") handler.setFormatter(formatter) =20 log.addHandler(handler) =20 - return log - -log =3D logging.getLogger("dhcp") - def ip_address_to_reverse_pointer(address): parts =3D address.split(".") parts.reverse() @@ -602,7 +602,7 @@ if __name__ =3D=3D "__main__": bridge =3D UnboundDHCPLeasesBridge(args.dhcp_leases, args.fix_leases, args.unbound_leases, args.hosts) =20 - ctx =3D daemon.DaemonContext(detach_process=3Dargs.daemon) + ctx =3D daemon.DaemonContext(detach_process=3Dargs.daemon, stderr=3D(None i= f args.daemon else sys.stderr)) ctx.signal_map =3D { signal.SIGHUP : bridge.update_dhcp_leases, signal.SIGTERM : bridge.terminate, --=20 2.34.1 --===============8383287611620836056==--