[master 1/2] logging: get rid of storage_log.py

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

 



It duplicates code in anaconda_log and log_method_call() could be used by
somewhere else then storage too sometime.
---
 anaconda                                |    4 +-
 pyanaconda/anaconda_log.py              |   60 +++++++++++++++++++++++--------
 pyanaconda/storage/__init__.py          |    1 -
 pyanaconda/storage/devices.py           |    2 +-
 pyanaconda/storage/devicetree.py        |    2 +-
 pyanaconda/storage/formats/__init__.py  |    2 +-
 pyanaconda/storage/formats/disklabel.py |    2 +-
 pyanaconda/storage/formats/dmraid.py    |    2 +-
 pyanaconda/storage/formats/fs.py        |    2 +-
 pyanaconda/storage/formats/luks.py      |    2 +-
 pyanaconda/storage/formats/lvmpv.py     |    2 +-
 pyanaconda/storage/formats/mdraid.py    |    2 +-
 pyanaconda/storage/formats/multipath.py |    2 +-
 pyanaconda/storage/formats/swap.py      |    2 +-
 pyanaconda/storage/storage_log.py       |   34 -----------------
 15 files changed, 58 insertions(+), 63 deletions(-)
 delete mode 100644 pyanaconda/storage/storage_log.py

diff --git a/anaconda b/anaconda
index 3602cfd..cd5f80d 100755
--- a/anaconda
+++ b/anaconda
@@ -271,7 +271,8 @@ def setupLoggingFromOpts(opts):
         level = anaconda_log.logLevelMap[opts.loglevel]
         anaconda_log.logger.tty_loglevel = level
         anaconda_log.setHandlersLevel(log, level)
-        anaconda_log.setHandlersLevel(pyanaconda.storage.storage_log.logger, level)
+        storage_log = logging.getLogger("storage")
+        anaconda_log.setHandlersLevel(storage_log, level)
 
     if opts.syslog:
         anaconda_log.logger.remote_syslog = opts.syslog
@@ -502,7 +503,6 @@ if __name__ == "__main__":
     from pyanaconda import vnc
     from pyanaconda import users
     from pyanaconda import kickstart
-    import pyanaconda.storage.storage_log
 
     # the following makes me very sad. -- katzj
     # we have a slightly different set of udev rules in the second 
diff --git a/pyanaconda/anaconda_log.py b/pyanaconda/anaconda_log.py
index c298b4e..c570024 100644
--- a/pyanaconda/anaconda_log.py
+++ b/pyanaconda/anaconda_log.py
@@ -22,11 +22,12 @@
 #            Michael Fulbright <msf@xxxxxxxxxx>
 #
 
+import inspect
+import logging
+from logging.handlers import SysLogHandler, SYSLOG_UDP_PORT
 import os
 import signal
 import sys
-import logging
-from logging.handlers import SysLogHandler, SYSLOG_UDP_PORT
 import types
 
 import iutil
@@ -41,6 +42,7 @@ DATE_FORMAT = "%H:%M:%S"
 MAIN_LOG_FILE = "/tmp/anaconda.log"
 MAIN_LOG_TTY = "/dev/tty3"
 PROGRAM_LOG_FILE = "/tmp/program.log"
+STORAGE_LOG_FILE = "/tmp/storage.log"
 ANACONDA_SYSLOG_FACILITY = SysLogHandler.LOG_LOCAL1
 
 logLevelMap = {"debug": logging.DEBUG, "info": logging.INFO,
@@ -56,10 +58,29 @@ def setHandlersLevel(logger, level):
     map(lambda hdlr: hdlr.setLevel(level),
         filter (lambda hdlr: hasattr(hdlr, "autoSetLevel") and hdlr.autoSetLevel, logger.handlers))
 
+def log_method_call(d, *args, **kwargs):
+    classname = d.__class__.__name__
+    stack = inspect.stack()
+    methodname = stack[1][3]
+
+    spaces = len(stack) * ' '
+    fmt = "%s%s.%s:"
+    fmt_args = [spaces, classname, methodname]
+
+    for arg in args:
+        fmt += " %s ;"
+        fmt_args.append(arg)
+
+    for k, v in kwargs.items():
+        fmt += " %s: %s ;"
+        fmt_args.extend([k, v])
+
+    logging.getLogger("storage").debug(fmt % tuple(fmt_args))
+
 class AnacondaSyslogHandler(SysLogHandler):
-    def __init__(self, 
+    def __init__(self,
                  address=('localhost', SYSLOG_UDP_PORT),
-                 facility=SysLogHandler.LOG_USER, 
+                 facility=SysLogHandler.LOG_USER,
                  tag=''):
         self.tag = tag
         SysLogHandler.__init__(self, address, facility)
@@ -78,17 +99,26 @@ class AnacondaLog:
         logging.addLevelName(logging.WARNING, "WARN")
         logging.addLevelName(logging.ERROR, "ERR")
         logging.addLevelName(logging.CRITICAL, "CRIT")
-        # Create the base of the logger hierarcy.
-        logger = logging.getLogger("anaconda")
-        logger.setLevel(logging.DEBUG)
-        self.addFileHandler(MAIN_LOG_FILE, logger,
+
+        # Create the base of the logger hierarchy.
+        anaconda_logger = logging.getLogger("anaconda")
+        self.addFileHandler(MAIN_LOG_FILE, anaconda_logger,
                             minLevel=logging.DEBUG)
-        self.forwardToSyslog(logger)
-        # Log to tty3.
-        if not iutil.isS390() and os.access(MAIN_LOG_TTY, os.W_OK):
-            self.addFileHandler(MAIN_LOG_TTY, logger,
-                                fmtStr=TTY_FORMAT,
-                                autoLevel=True)
+
+        # Create the storage logger.
+        storage_logger = logging.getLogger("storage")
+        self.addFileHandler(STORAGE_LOG_FILE, storage_logger,
+                            minLevel=logging.DEBUG)
+
+        # Set the common parameters for anaconda and storage loggers.
+        for logger in [anaconda_logger, storage_logger]:
+            logger.setLevel(logging.DEBUG)
+            self.forwardToSyslog(logger)
+            # Logging of basic stuff and storage to tty3.
+            if not iutil.isS390() and os.access(MAIN_LOG_TTY, os.W_OK):
+                self.addFileHandler(MAIN_LOG_TTY, logger,
+                                    fmtStr=TTY_FORMAT,
+                                    autoLevel=True)
 
         # External program output log
         program_logger = logging.getLogger("program")
@@ -135,7 +165,7 @@ class AnacondaLog:
             return
 
         syslogHandler = AnacondaSyslogHandler(
-            '/dev/log', 
+            '/dev/log',
             ANACONDA_SYSLOG_FACILITY,
             logger.name)
         syslogHandler.setLevel(logging.DEBUG)
diff --git a/pyanaconda/storage/__init__.py b/pyanaconda/storage/__init__.py
index bf74f88..4747deb 100644
--- a/pyanaconda/storage/__init__.py
+++ b/pyanaconda/storage/__init__.py
@@ -36,7 +36,6 @@ from pyanaconda.constants import *
 from pykickstart.constants import *
 from pyanaconda.flags import flags
 
-import storage_log
 from errors import *
 from devices import *
 from devicetree import DeviceTree
diff --git a/pyanaconda/storage/devices.py b/pyanaconda/storage/devices.py
index 5462eee..02a806e 100644
--- a/pyanaconda/storage/devices.py
+++ b/pyanaconda/storage/devices.py
@@ -110,7 +110,7 @@ import block
 from errors import *
 from pyanaconda.iutil import notify_kernel, numeric_type
 from pyanaconda.flags import flags
-from .storage_log import log_method_call
+from pyanaconda.anaconda_log import log_method_call
 from udev import *
 from formats import get_device_format_class, getFormat, DeviceFormat
 
diff --git a/pyanaconda/storage/devicetree.py b/pyanaconda/storage/devicetree.py
index 8cc61b9..e500520 100644
--- a/pyanaconda/storage/devicetree.py
+++ b/pyanaconda/storage/devicetree.py
@@ -38,9 +38,9 @@ import devicelibs.lvm
 import devicelibs.mpath
 import devicelibs.loop
 from udev import *
-from .storage_log import log_method_call
 from pyanaconda import iutil
 from pyanaconda import tsort
+from pyanaconda.anaconda_log import log_method_call
 import parted
 import _ped
 
diff --git a/pyanaconda/storage/formats/__init__.py b/pyanaconda/storage/formats/__init__.py
index f5377c6..5c1d62f 100644
--- a/pyanaconda/storage/formats/__init__.py
+++ b/pyanaconda/storage/formats/__init__.py
@@ -26,7 +26,7 @@ from pyanaconda.baseudev import udev_get_device
 from pyanaconda.iutil import notify_kernel
 from pyanaconda.iutil import get_sysfs_path_by_name
 from pyanaconda.iutil import execWithRedirect
-from ..storage_log import log_method_call
+from pyanaconda.anaconda_log import log_method_call
 from ..errors import *
 from ..devicelibs.dm import dm_node_from_name
 from ..udev import udev_device_get_major, udev_device_get_minor
diff --git a/pyanaconda/storage/formats/disklabel.py b/pyanaconda/storage/formats/disklabel.py
index 3222b67..e986b5e 100644
--- a/pyanaconda/storage/formats/disklabel.py
+++ b/pyanaconda/storage/formats/disklabel.py
@@ -23,7 +23,7 @@
 import os
 import copy
 
-from ..storage_log import log_method_call
+from pyanaconda.anaconda_log import log_method_call
 import parted
 import _ped
 from pyanaconda import platform
diff --git a/pyanaconda/storage/formats/dmraid.py b/pyanaconda/storage/formats/dmraid.py
index e201c5f..5df3a1d 100644
--- a/pyanaconda/storage/formats/dmraid.py
+++ b/pyanaconda/storage/formats/dmraid.py
@@ -20,7 +20,7 @@
 # Red Hat Author(s): Dave Lehman <dlehman@xxxxxxxxxx>
 #
 
-from ..storage_log import log_method_call
+from pyanaconda.anaconda_log import log_method_call
 from pyanaconda.flags import flags
 from ..errors import *
 from . import DeviceFormat, register_device_format
diff --git a/pyanaconda/storage/formats/fs.py b/pyanaconda/storage/formats/fs.py
index f055ce2..d5bf11e 100644
--- a/pyanaconda/storage/formats/fs.py
+++ b/pyanaconda/storage/formats/fs.py
@@ -39,7 +39,7 @@ from . import DeviceFormat, register_device_format
 from pyanaconda import iutil
 from pyanaconda.flags import flags
 from parted import fileSystemType
-from ..storage_log import log_method_call
+from pyanaconda.anaconda_log import log_method_call
 
 import logging
 log = logging.getLogger("storage")
diff --git a/pyanaconda/storage/formats/luks.py b/pyanaconda/storage/formats/luks.py
index 8b541e1..6734721 100644
--- a/pyanaconda/storage/formats/luks.py
+++ b/pyanaconda/storage/formats/luks.py
@@ -29,7 +29,7 @@ try:
 except ImportError:
     volume_key = None
 
-from ..storage_log import log_method_call
+from pyanaconda.anaconda_log import log_method_call
 from ..errors import *
 from ..devicelibs import crypto
 from . import DeviceFormat, register_device_format
diff --git a/pyanaconda/storage/formats/lvmpv.py b/pyanaconda/storage/formats/lvmpv.py
index 6a9f492..196ae3d 100644
--- a/pyanaconda/storage/formats/lvmpv.py
+++ b/pyanaconda/storage/formats/lvmpv.py
@@ -22,7 +22,7 @@
 
 import os
 
-from ..storage_log import log_method_call
+from pyanaconda.anaconda_log import log_method_call
 from parted import PARTITION_LVM
 from ..errors import *
 from ..devicelibs import lvm
diff --git a/pyanaconda/storage/formats/mdraid.py b/pyanaconda/storage/formats/mdraid.py
index 339f7aa..fe536d3 100644
--- a/pyanaconda/storage/formats/mdraid.py
+++ b/pyanaconda/storage/formats/mdraid.py
@@ -22,7 +22,7 @@
 
 import os
 
-from ..storage_log import log_method_call
+from pyanaconda.anaconda_log import log_method_call
 from pyanaconda.flags import flags
 from parted import PARTITION_RAID
 from ..errors import *
diff --git a/pyanaconda/storage/formats/multipath.py b/pyanaconda/storage/formats/multipath.py
index 86c05d6..e4c3c6b 100644
--- a/pyanaconda/storage/formats/multipath.py
+++ b/pyanaconda/storage/formats/multipath.py
@@ -24,7 +24,7 @@
 # Red Hat Author(s): Peter Jones <pjones@xxxxxxxxxx>
 #
 
-from ..storage_log import log_method_call
+from pyanaconda.anaconda_log import log_method_call
 from ..errors import *
 from . import DeviceFormat, register_device_format
 
diff --git a/pyanaconda/storage/formats/swap.py b/pyanaconda/storage/formats/swap.py
index 0d0a89d..222a459 100644
--- a/pyanaconda/storage/formats/swap.py
+++ b/pyanaconda/storage/formats/swap.py
@@ -22,7 +22,7 @@
 
 from pyanaconda.iutil import numeric_type
 from parted import PARTITION_SWAP, fileSystemType
-from ..storage_log import log_method_call
+from pyanaconda.anaconda_log import log_method_call
 from ..errors import *
 from ..devicelibs import swap
 from . import DeviceFormat, register_device_format
diff --git a/pyanaconda/storage/storage_log.py b/pyanaconda/storage/storage_log.py
deleted file mode 100644
index 56cd8e3..0000000
--- a/pyanaconda/storage/storage_log.py
+++ /dev/null
@@ -1,34 +0,0 @@
-import logging
-from pyanaconda import anaconda_log
-import os
-import inspect
-
-def log_method_call(d, *args, **kwargs):
-    classname = d.__class__.__name__
-    stack = inspect.stack()
-    methodname = stack[1][3]
-
-    spaces = len(stack) * ' '
-    fmt = "%s%s.%s:"
-    fmt_args = [spaces, classname, methodname]
-
-    for arg in args:
-        fmt += " %s ;"
-        fmt_args.append(arg)
-
-    for k, v in kwargs.items():
-        fmt += " %s: %s ;"
-        fmt_args.extend([k, v])
-
-    logger.debug(fmt % tuple(fmt_args))
-
-
-logger = logging.getLogger("storage")
-logger.setLevel(logging.DEBUG)
-anaconda_log.logger.addFileHandler("/tmp/storage.log", logger, logging.DEBUG)
-if os.access(anaconda_log.MAIN_LOG_TTY, os.W_OK):
-    anaconda_log.logger.addFileHandler(anaconda_log.MAIN_LOG_TTY, logger,
-                                   anaconda_log.DEFAULT_TTY_LEVEL,
-                                   anaconda_log.TTY_FORMAT,
-                                   autoLevel=True)
-anaconda_log.logger.forwardToSyslog(logger)
-- 
1.7.3.3

_______________________________________________
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