From: Michael Tremer Date: Wed, 5 May 2021 14:55:33 +0000 (+0000) Subject: Add logging X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=384bc6cf2198bcd4629d8cfbcc6b79ebade70b58;p=people%2Fms%2Fbricklayer.git Add logging Signed-off-by: Michael Tremer --- diff --git a/Makefile.am b/Makefile.am index 77fc623..8cb73c2 100644 --- a/Makefile.am +++ b/Makefile.am @@ -45,4 +45,5 @@ dist_bin_SCRIPTS = \ dist_pkgpython_PYTHON = \ src/python/__init__.py \ - src/python/i18n.py + src/python/i18n.py \ + src/python/logger.py diff --git a/src/bricklayer b/src/bricklayer index e8546b8..aa02d90 100644 --- a/src/bricklayer +++ b/src/bricklayer @@ -59,7 +59,7 @@ class Cli(object): def run_bricklayer(self, args): # Setup bricklayer - bl = bricklayer.Bricklayer() + bl = bricklayer.Bricklayer(**vars(args)) # Run it return bl() diff --git a/src/python/__init__.py b/src/python/__init__.py index bd0baed..6653880 100644 --- a/src/python/__init__.py +++ b/src/python/__init__.py @@ -18,12 +18,23 @@ # # ############################################################################### +import logging + +from . import logger + +# Setup logging +log = logging.getLogger("bricklayer") + class Bricklayer(object): """ Bricklayer's base class """ - def __init__(self): - pass + def __init__(self, test=False, debug=False): + # Enable debug logging + if debug: + log.setLevel(logging.DEBUG) + + log.info("Bricklayer initialized") def __call__(self): pass diff --git a/src/python/logger.py b/src/python/logger.py new file mode 100644 index 0000000..7f20265 --- /dev/null +++ b/src/python/logger.py @@ -0,0 +1,32 @@ +############################################################################### +# # +# Bricklayer - An Installer for IPFire # +# Copyright (C) 2021 IPFire Development Team # +# # +# This program is free software; you can redistribute it and/or # +# modify it under the terms of the GNU General Public License # +# as published by the Free Software Foundation; either version 2 # +# of the License, or (at your option) any later version. # +# # +# This program is distributed in the hope that it will be useful, # +# but WITHOUT ANY WARRANTY; without even the implied warranty of # +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # +# GNU General Public License for more details. # +# # +# You should have received a copy of the GNU General Public License # +# along with this program. If not, see . # +# # +############################################################################### + +import logging +import logging.handlers + +# Initialise root logger +log = logging.getLogger("bricklayer") +log.setLevel(logging.INFO) + +# Always log everything to syslog +handler = logging.handlers.SysLogHandler(address="/dev/log", + facility=logging.handlers.SysLogHandler.LOG_DAEMON) +handler.setLevel(logging.DEBUG) +log.addHandler(handler)