|
From: <ni...@us...> - 2010-11-04 22:27:19
|
Revision: 79
http://openautomation.svn.sourceforge.net/openautomation/?rev=79&view=rev
Author: nilss1
Date: 2010-11-04 22:27:12 +0000 (Thu, 04 Nov 2010)
Log Message:
-----------
put logging to subfolder and include loglevel notice
Modified Paths:
--------------
PyWireGate/trunk/WireGate.py
Added Paths:
-----------
PyWireGate/trunk/log/
PyWireGate/trunk/log/__init__.py
Modified: PyWireGate/trunk/WireGate.py
===================================================================
--- PyWireGate/trunk/WireGate.py 2010-11-04 21:54:13 UTC (rev 78)
+++ PyWireGate/trunk/WireGate.py 2010-11-04 22:27:12 UTC (rev 79)
@@ -22,12 +22,10 @@
import signal
import traceback
import daemon
-import logging
-import logging.handlers
+import log as logging
import ConfigParser
-
import datastore
class WireGate(daemon.Daemon):
@@ -64,11 +62,10 @@
'loglevel': 'info'
}
+ self.checkconfig("WireGate",defaultconfig)
## Remove this later
if "plugins" in self.config['WireGate']:
self.log("old Config",'critical')
-
- self.checkconfig("WireGate",defaultconfig)
@@ -227,7 +224,7 @@
maxlevel = self.config['WireGate']['loglevel']
if not filename:
filename = self.config['WireGate']['logfile']
- LEVELS = {'debug': logging.DEBUG,'info': logging.INFO,'warning': logging.WARNING,'error': logging.ERROR,'critical': logging.CRITICAL}
+ LEVELS = {'debug': logging.DEBUG,'info': logging.INFO,'notice': logging.NOTICE,'warning': logging.WARNING,'error': logging.ERROR,'critical': logging.CRITICAL}
level = LEVELS.get(maxlevel, logging.NOTSET)
# create logger
@@ -248,7 +245,7 @@
# create console handler and set level to debug
if self.REDIRECTIO:
#console = logging.StreamHandler()
- console = isoStreamHandler()
+ console = logging.isoStreamHandler()
console.setFormatter(formatter)
logger.addHandler(console)
return logger
@@ -265,7 +262,7 @@
elif severity=="info":
logger.info(msg)
elif severity=="notice":
- logger.info(msg)
+ logger.notice(msg)
elif severity=="warning":
logger.warning(msg)
elif severity=="warn":
@@ -287,13 +284,6 @@
os.umask(0)
-class isoStreamHandler(logging.StreamHandler):
- def emit(self,record):
- #record.message = record.message.decode('utf-8').encode('iso-8859-15')
- record.message = record.message.encode(sys.stderr.encoding)
- logging.StreamHandler.emit(self,record)
-
-
if __name__ == "__main__":
try:
import os
@@ -340,4 +330,3 @@
-
Added: PyWireGate/trunk/log/__init__.py
===================================================================
--- PyWireGate/trunk/log/__init__.py (rev 0)
+++ PyWireGate/trunk/log/__init__.py 2010-11-04 22:27:12 UTC (rev 79)
@@ -0,0 +1,68 @@
+# -*- coding: iso8859-1 -*-
+from logging import *
+import logging.handlers as handlers
+
+
+## redefine logging
+# Change the default levels to include NOTICE in
+# the proper order of priority
+FATAL = CRITICAL = 60
+ERROR = 50
+WARN = WARNING = 40
+NOTICE = 30
+
+# insert the levels with all the redefined values
+# anything below NOTICE we don't have to add back in, its
+# not getting redefined above with a new value
+addLevelName(NOTICE, 'NOTICE')
+addLevelName(WARNING, 'WARNING')
+addLevelName(WARN, 'WARN')
+addLevelName(ERROR, 'ERROR')
+addLevelName(FATAL, 'FATAL')
+addLevelName(CRITICAL, 'CRITICAL')
+
+# define a new logger function for notice
+# this is exactly like existing info, critical, debug...etc
+def Logger_notice(self, msg, *args, **kwargs):
+ """
+ Log 'msg % args' with severity 'NOTICE'.
+
+ To pass exception information, use the keyword argument exc_info
+with
+ a true value, e.g.
+
+ logger.notice("Houston, we have a %s", "major disaster", exc_info=1)
+ """
+ if self.manager.disable >= NOTICE:
+ return
+ if NOTICE >= self.getEffectiveLevel():
+ apply(self._log, (NOTICE, msg, args), kwargs)
+
+# make the notice function known in the system Logger class
+Logger.notice = Logger_notice
+
+# define a new root level notice function
+# this is exactly like existing info, critical, debug...etc
+def root_notice(msg, *args, **kwargs):
+ """
+ Log a message with severity 'NOTICE' on the root logger.
+ """
+ if len(root.handlers) == 0:
+ basicConfig()
+ apply(root.notice, (msg,)+args, kwargs)
+
+# make the notice root level function known
+notice = root_notice
+
+# add NOTICE to the priority map of all the levels
+handlers.SysLogHandler.priority_map['NOTICE'] = 'notice'
+
+
+class isoStreamHandler(StreamHandler):
+ def emit(self,record):
+ #record.message = record.message.decode('utf-8').encode('iso-8859-15')
+ record.message = record.message.encode(sys.stderr.encoding)
+ StreamHandler.emit(self,record)
+
+
+
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|