Author: justi9
Date: 2008-06-24 15:44:41 -0400 (Tue, 24 Jun 2008)
New Revision: 2158
Modified:
mgmt/cumin/python/cumin/__init__.py
Log:
Change the logging defaults:
- Make --debug mode produce DEBUG level output to the console
- Make non debug mode only log to file, at WARN level
- Introduce formatters
Modified: mgmt/cumin/python/cumin/__init__.py
===================================================================
--- mgmt/cumin/python/cumin/__init__.py 2008-06-24 15:56:25 UTC (rev 2157)
+++ mgmt/cumin/python/cumin/__init__.py 2008-06-24 19:44:41 UTC (rev 2158)
@@ -173,33 +173,46 @@
self.add_param("debug", bool, False, summ)
def init(self):
- root = logging.getLogger()
-
self.load_defaults()
self.load_args(sys.argv)
- h = logging.StreamHandler()
- root.addHandler(h)
+ handler = logging.StreamHandler()
+ log.addHandler(handler)
self.load_file(os.path.join(self.home, "etc", "cumin.conf"))
self.load_file(os.path.join(os.path.expanduser("~"),
".cumin.conf"))
self.load_args(sys.argv)
- root.removeHandler(h)
+ log.removeHandler(handler)
+ mlog = logging.getLogger("mint")
+
if self.debug:
- h = logging.StreamHandler()
- h.setLevel(logging.DEBUG)
- root.addHandler(h)
+ level = logging.DEBUG
+ formatter = logging.Formatter("%(name)-12s - %(message)s")
+
+ log.setLevel(level)
+ mlog.setLevel(level)
- try:
- h = logging.FileHandler(self.log_file)
- except IOError, e:
- root.warn("Can't write to log file '%s': %s" %
(self.log_file, e))
+ handler = logging.StreamHandler()
+ handler.setLevel(level)
+ handler.setFormatter(formatter)
- h.setLevel(self.debug and logging.DEBUG or logging.INFO)
- root.addHandler(h)
+ log.addHandler(handler)
+ mlog.addHandler(handler)
+ else:
+ level = logging.WARN
+ formatter = logging.Formatter \
+ ("%(asctime)s %(levelname)-8s %(message)s")
- log.setLevel(self.debug and logging.DEBUG or logging.INFO)
+ log.setLevel(level)
+ mlog.setLevel(level)
- def get_console_handler(self):
- h = logging.StreamHandler()
- return h
+ try:
+ handler = logging.FileHandler(self.log_file)
+ handler.setLevel(level)
+ handler.setFormatter(formatter)
+
+ log.addHandler(handler)
+ mlog.addHandler(handler)
+ except IOError, e:
+ clog.warn("Can't write to log file '%s': %s" % \
+ (self.log_file, e))
Show replies by date