[master] Python logging is talking to the syslog daemon.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This allows anaconda to progressively send contents of anaconda.log and
storage.log to a remote machine.
---
 anaconda_log.py        |   30 +++++++++++++++++++++++++++---
 storage/storage_log.py |    1 +
 2 files changed, 28 insertions(+), 3 deletions(-)

diff --git a/anaconda_log.py b/anaconda_log.py
index 3be4e6a..f3da560 100644
--- a/anaconda_log.py
+++ b/anaconda_log.py
@@ -24,8 +24,8 @@
 
 import sys
 import logging
+import logging.handlers
 import types
-from logging.handlers import SysLogHandler, SYSLOG_UDP_PORT
 
 DEFAULT_LEVEL = logging.INFO
 DEFAULT_ENTRY_FORMAT = "%(asctime)s,%(msecs)03d %(levelname)-8s: %(message)s"
@@ -33,6 +33,7 @@ DEFAULT_DATE_FORMAT = "%H:%M:%S"
 
 MAIN_LOG_FILE = "/tmp/anaconda.log"
 PROGRAM_LOG_FILE = "/tmp/program.log"
+ANACONDA_SYSLOG_FACILITY = logging.handlers.SysLogHandler.LOG_LOCAL1
 
 logLevelMap = {"debug": logging.DEBUG, "info": logging.INFO,
                "warning": logging.WARNING, "error": logging.ERROR,
@@ -53,6 +54,18 @@ class LoggerClass(logging.Logger):
         setattr(hdlr, "autoSetLevel", autoSetLevel)
         logging.Logger.addHandler(self, hdlr)
 
+class AnacondaSyslogHandler(logging.handlers.SysLogHandler):
+    def __init__(self, 
+                 address=('localhost', logging.handlers.SYSLOG_UDP_PORT),
+                 facility=logging.handlers.SysLogHandler.LOG_USER, 
+                 tag=''):
+        self.tag = tag
+        logging.handlers.SysLogHandler.__init__(self, address, facility)
+
+    def emit(self, record):
+        record.msg = '%s: %s' %(self.tag, record.msg)
+        logging.handlers.SysLogHandler.emit(self, record)
+
 class AnacondaLog:
     def __init__ (self, minLevel=DEFAULT_LEVEL):
         # Create the base of the logger hierarcy.
@@ -60,6 +73,7 @@ class AnacondaLog:
         self.logger.setLevel(logging.DEBUG)
         self.addFileHandler(MAIN_LOG_FILE, self.logger,
                             autoSetLevel=False, minLevel=logging.DEBUG)
+        self.forwardLog(self.logger)
 
         # External program output log
         program_logger = logging.getLogger("program")
@@ -98,14 +112,24 @@ class AnacondaLog:
         newLogger.setLevel(minLevel)
 
     # Add a handler for remote syslogs.
-    def addSysLogHandler (self, logger, host, port=SYSLOG_UDP_PORT,
+    def addSysLogHandler (self, logger, host, port=logging.handlers.SYSLOG_UDP_PORT,
                           minLevel=DEFAULT_LEVEL):
         fmt = logging.Formatter("%(levelname)-8s %(message)s")
-        syslogHandler = SysLogHandler((host, port))
+        syslogHandler = logging.handlers.SysLogHandler((host, port))
         syslogHandler.setLevel(minLevel)
         syslogHandler.setFormatter(fmt)
         logger.addHandler(syslogHandler)
 
+    def forwardLog(self, logger):
+        """Forward everything that goes in the logger to the syslog daemon.
+        """
+        syslogHandler = AnacondaSyslogHandler(
+            '/dev/log', 
+            ANACONDA_SYSLOG_FACILITY,
+            logger.name)
+        syslogHandler.setLevel(logging.DEBUG)
+        logger.addHandler(syslogHandler)
+
 # Set base class for logger instances.
 logging.setLoggerClass(LoggerClass)
 logger = AnacondaLog()
diff --git a/storage/storage_log.py b/storage/storage_log.py
index 853b0cd..b637759 100644
--- a/storage/storage_log.py
+++ b/storage/storage_log.py
@@ -22,3 +22,4 @@ logger = logging.getLogger("storage")
 logger.setLevel(logging.DEBUG)
 anaconda_log.logger.addFileHandler("/tmp/storage.log", logger, logging.DEBUG)
 anaconda_log.logger.addFileHandler("/dev/tty3", logger, logging.DEBUG)
+anaconda_log.logger.forwardLog(logger)
-- 
1.6.2.5

_______________________________________________
Anaconda-devel-list mailing list
Anaconda-devel-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/anaconda-devel-list

[Index of Archives]     [Kickstart]     [Fedora Users]     [Fedora Legacy List]     [Fedora Maintainers]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]
  Powered by Linux