[master] Log storage in the same format as the main anaconda log (a part of #524980)

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

 



:: the entry format and date format is standardized: do not show date but always show miliseconds
:: includes a cleanup in the storage/storage_log.py code to use AnacondaLog
---
 anaconda_log.py        |    8 +++++---
 storage/storage_log.py |   16 +++-------------
 2 files changed, 8 insertions(+), 16 deletions(-)

diff --git a/anaconda_log.py b/anaconda_log.py
index 99ae58e..78ffbed 100644
--- a/anaconda_log.py
+++ b/anaconda_log.py
@@ -27,6 +27,8 @@ import logging
 from logging.handlers import SysLogHandler, SYSLOG_UDP_PORT
 
 DEFAULT_LEVEL = logging.INFO
+DEFAULT_ENTRY_FORMAT = "%(asctime)s,%(msecs)d %(levelname)-8s: %(message)s"
+DEFAULT_DATE_FORMAT = "%H:%M:%S"
 
 logFile = "/tmp/anaconda.log"
 
@@ -72,15 +74,15 @@ class AnacondaLog:
 
     # Add a simple handler - file or stream, depending on what we're given.
     def addFileHandler (self, file, addToLogger, minLevel=DEFAULT_LEVEL,
-                        fmtStr="%(asctime)s %(levelname)-8s: %(message)s",
+                        fmtStr=DEFAULT_ENTRY_FORMAT,
                         autoSetLevel=True):
-        if type (file) == type ("string"):
+        if isinstance(file, str):
             logfileHandler = logging.FileHandler(file)
         else:
             logfileHandler = logging.StreamHandler(file)
 
         logfileHandler.setLevel(minLevel)
-        logfileHandler.setFormatter (logging.Formatter (fmtStr, "%H:%M:%S"))
+        logfileHandler.setFormatter(logging.Formatter(fmtStr, DEFAULT_DATE_FORMAT))
         addToLogger.addHandler(logfileHandler, autoSetLevel=autoSetLevel)
 
     # Add another logger to the hierarchy.  For best results, make sure
diff --git a/storage/storage_log.py b/storage/storage_log.py
index a771154..66a101e 100644
--- a/storage/storage_log.py
+++ b/storage/storage_log.py
@@ -1,17 +1,7 @@
 import logging
-
-
-#handler = logging.StreamHandler()
-file_handler = logging.FileHandler("/tmp/storage.log")
-formatter = logging.Formatter("[%(asctime)s] %(levelname)8s: %(message)s")
-file_handler.setFormatter(formatter)
-
-tty3_handler = logging.FileHandler("/dev/tty3")
-tty3_handler.setFormatter(formatter)
+import anaconda_log
 
 logger = logging.getLogger("storage")
-logger.addHandler(file_handler)
-logger.addHandler(tty3_handler)
 logger.setLevel(logging.DEBUG)
-
-
+anaconda_log.logger.addFileHandler("/tmp/storage.log", logger, logging.DEBUG)
+anaconda_log.logger.addFileHandler("/dev/tty3", logger, logging.DEBUG)
-- 
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