]> git.ipfire.org Git - people/ms/bricklayer.git/commitdiff
Add logging
authorMichael Tremer <michael.tremer@ipfire.org>
Wed, 5 May 2021 14:55:33 +0000 (14:55 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Wed, 5 May 2021 14:55:33 +0000 (14:55 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
Makefile.am
src/bricklayer
src/python/__init__.py
src/python/logger.py [new file with mode: 0644]

index 77fc6234661f761e4d39572dc581de9bfc57adfc..8cb73c241a0ae53b996a5c008e1499ca2fd26fca 100644 (file)
@@ -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
index e8546b88af4ffd51b27cb95eba96920100653117..aa02d9038020fca23c28f64c852dc9bdedc993a6 100644 (file)
@@ -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()
index bd0baed1353f83c9f628e9c293a1709c12c3c8d6..6653880c6fad07a5d7e86629a708e0c381eb012d 100644 (file)
 #                                                                             #
 ###############################################################################
 
+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 (file)
index 0000000..7f20265
--- /dev/null
@@ -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 <http://www.gnu.org/licenses/>.       #
+#                                                                             #
+###############################################################################
+
+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)