From patchwork Wed Mar 30 09:56:31 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Tremer X-Patchwork-Id: 5414 Return-Path: Received: from mail01.ipfire.org (mail01.haj.ipfire.org [172.28.1.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) client-signature ECDSA (P-384)) (Client CN "mail01.haj.ipfire.org", Issuer "R3" (verified OK)) by web04.haj.ipfire.org (Postfix) with ESMTPS id 4KT2034rVjz3wf7 for ; Wed, 30 Mar 2022 09:56:51 +0000 (UTC) Received: from mail02.haj.ipfire.org (mail02.haj.ipfire.org [172.28.1.201]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) client-signature ECDSA (P-384)) (Client CN "mail02.haj.ipfire.org", Issuer "R3" (verified OK)) by mail01.ipfire.org (Postfix) with ESMTPS id 4KT1zy2q8yz3vv; Wed, 30 Mar 2022 09:56:46 +0000 (UTC) Received: from mail02.haj.ipfire.org (localhost [127.0.0.1]) by mail02.haj.ipfire.org (Postfix) with ESMTP id 4KT1zy1ssYz2yr2; Wed, 30 Mar 2022 09:56:46 +0000 (UTC) Received: from mail01.ipfire.org (mail01.haj.ipfire.org [172.28.1.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) client-signature ECDSA (P-384)) (Client CN "mail01.haj.ipfire.org", Issuer "R3" (verified OK)) by mail02.haj.ipfire.org (Postfix) with ESMTPS id 4KT1zw4G4mz2y0B for ; Wed, 30 Mar 2022 09:56:44 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by mail01.ipfire.org (Postfix) with ESMTPSA id 4KT1zv580Hz39V; Wed, 30 Mar 2022 09:56:43 +0000 (UTC) DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=ipfire.org; s=202003ed25519; t=1648634203; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=hawIf6nZ1XIeqwg4aT1ilIpV1RFZZ8WQ+Qs1WZKYJqc=; b=XGs7Zjmd9/jbMIG/k2+jiy/yPn3Vwhymd0wd8mZH7Ona4kKw9tLfS5nqA+B3bCkuc5EE9+ 6zcCQrpcG04h2pDw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ipfire.org; s=202003rsa; t=1648634203; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=hawIf6nZ1XIeqwg4aT1ilIpV1RFZZ8WQ+Qs1WZKYJqc=; b=wqh3RyWBj7TwecxNTNJnzEjen0ZZ2wYn941xarj4o9d10oH8RQ9RhzzLzLqu5tqWaCdHAA n/RMFcgd9r45YPjmiPkNgvXpHZrFLvZBC6KxxWPMdtZ/t8+JC+SG8wBFwt0DZSXERdC67i d0Wudak0ZYcVwVEvjspju5Zk0vc88C+bemSR0Cv7ZLrHvsQnpWf5cA9TwwysKdkoEDFH9V F0Od9Rr3Kj1gR9jUUKVFP7mgzCvc3v3Aq0bZhm9g8X9KydcfmHoEByEbLeGegHxP283sZN XTZkS8zDylr/MHdV2gDWnjppg/EERPDp3KPfCFNBtFJKSb6TXh7lw7JALB0+og== From: Michael Tremer To: development@lists.ipfire.org Subject: [PATCH v2 1/5] unbound-dhcp-leases-bridge: Improve logging Date: Wed, 30 Mar 2022 09:56:31 +0000 Message-Id: <20220330095635.621181-1-michael.tremer@ipfire.org> MIME-Version: 1.0 X-BeenThere: development@lists.ipfire.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: IPFire development talk List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Michael Tremer Errors-To: development-bounces@lists.ipfire.org Sender: "Development" This improves logging and enables logging to the console. Suggested-by: Anthony Heading Signed-off-by: Michael Tremer --- config/unbound/unbound-dhcp-leases-bridge | 26 ++++++++++++++++------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/config/unbound/unbound-dhcp-leases-bridge b/config/unbound/unbound-dhcp-leases-bridge index a2df5f101..ce0cb8614 100644 --- a/config/unbound/unbound-dhcp-leases-bridge +++ b/config/unbound/unbound-dhcp-leases-bridge @@ -30,27 +30,37 @@ import re import signal import stat import subprocess +import sys import tempfile import inotify.adapters LOCAL_TTL = 60 -def setup_logging(loglevel=logging.INFO): - log = logging.getLogger("dhcp") +log = logging.getLogger("dhcp") +log.setLevel(logging.DEBUG) + +def setup_logging(daemon=True, loglevel=logging.INFO): log.setLevel(loglevel) + # Log to syslog by default handler = logging.handlers.SysLogHandler(address="/dev/log", facility="daemon") - handler.setLevel(loglevel) + log.addHandler(handler) + # Format everything formatter = logging.Formatter("%(name)s[%(process)d]: %(message)s") handler.setFormatter(formatter) - log.addHandler(handler) + handler.setLevel(loglevel) - return log + # If we are running in foreground, we should write everything to the console, too + if not daemon: + handler = logging.StreamHandler() + log.addHandler(handler) -log = logging.getLogger("dhcp") + handler.setLevel(loglevel) + + return log def ip_address_to_reverse_pointer(address): parts = address.split(".") @@ -579,12 +589,12 @@ if __name__ == "__main__": elif args.verbose >= 2: loglevel = logging.DEBUG - setup_logging(loglevel) + setup_logging(daemon=args.daemon, loglevel=loglevel) 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=sys.stderr) ctx.signal_map = { signal.SIGHUP : bridge.update_dhcp_leases, signal.SIGTERM : bridge.terminate,