]> git.ipfire.org Git - pakfire.git/commitdiff
builder: Refactor logging
authorMichael Tremer <michael.tremer@ipfire.org>
Thu, 4 Mar 2021 11:10:44 +0000 (11:10 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Thu, 4 Mar 2021 11:10:44 +0000 (11:10 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/pakfire/builder.py

index f858fe706e966dbf7fec5dbec10680cc26a5e084..7b2536f3ac8b5c592e89e096ff8061200bc2ef3d 100644 (file)
@@ -86,12 +86,12 @@ class Builder(object):
                # Add settings from keyword arguments
                self.settings.update(kwargs)
 
-               # Setup logging
-               self.setup_logging(logfile)
-
                # Generate a build ID
                self.build_id = build_id or "%s" % uuid.uuid4()
 
+               # Setup logging
+               self.log = self.setup_logging(logfile)
+
                # Path
                self.path = os.path.join(BUILD_ROOT, self.build_id)
 
@@ -133,23 +133,26 @@ class Builder(object):
                self._destroy()
 
        def setup_logging(self, logfile):
-               if logfile:
-                       self.log = log.getChild(self.build_id)
-                       # Propage everything to the root logger that we will see something
-                       # on the terminal.
-                       self.log.propagate = 1
-                       self.log.setLevel(logging.INFO)
+               l = log.getChild(self.build_id)
+               l.setLevel(logging.DEBUG)
 
-                       # Add the given logfile to the logger.
+               # Print everything to the console
+               l.addHandler(
+                       logging.StreamHandler(),
+               )
+
+               # If we have a log file, we write INFO and higher level messages to it
+               # using the build formatter which adds a timestamp
+               if logfile:
                        h = logging.FileHandler(logfile)
-                       self.log.addHandler(h)
+                       h.setLevel(logging.INFO)
+                       l.addHandler(h)
 
-                       # Format the log output for the file.
+                       # Set formatter
                        f = logger.BuildFormatter()
                        h.setFormatter(f)
-               else:
-                       # If no logile was given, we use the root logger.
-                       self.log = logging.getLogger("pakfire")
+
+               return l
 
        def _make_cgroup(self):
                """
@@ -367,6 +370,8 @@ class BuilderContext(object):
                        if not script:
                                continue
 
+                       self.log.debug("Running stage '%s'" % stage)
+
                        # Run it
                        self.pakfire.execute_script(script,
                                enable_network=False, interactive=False)