|
From: <ni...@us...> - 2010-11-05 10:25:19
|
Revision: 80
http://openautomation.svn.sourceforge.net/openautomation/?rev=80&view=rev
Author: nilss1
Date: 2010-11-05 10:25:12 +0000 (Fri, 05 Nov 2010)
Log Message:
-----------
fix loglevel notice, disable user switching until permissions fixed
Modified Paths:
--------------
PyWireGate/trunk/WireGate.py
PyWireGate/trunk/log/__init__.py
Modified: PyWireGate/trunk/WireGate.py
===================================================================
--- PyWireGate/trunk/WireGate.py 2010-11-04 22:27:12 UTC (rev 79)
+++ PyWireGate/trunk/WireGate.py 2010-11-05 10:25:12 UTC (rev 80)
@@ -22,8 +22,9 @@
import signal
import traceback
import daemon
-import log as logging
+import log
+
import ConfigParser
import datastore
@@ -142,20 +143,23 @@
startuser=pwd.getpwuid(os.getuid())
try:
runasuser=pwd.getpwnam(self.config['WireGate']['user'])
-
- ##Set Permissions
+ getpath = lambda x: "/".join(x.split("/")[:-1])
+
+ ##Set Permissions on
os.chown(self.config['WireGate']['pidfile'],runasuser[2],runasuser[3])
os.chown(self.config['WireGate']['logfile'],runasuser[2],runasuser[3])
os.chown(self.config['WireGate']['datastore'],runasuser[2],runasuser[3])
- os.setregid(runasuser[3],runasuser[3])
- os.setreuid(runasuser[2],runasuser[2])
+
+ ##removed until fixing permissions
+ #os.setregid(runasuser[3],runasuser[3])
+ #os.setreuid(runasuser[2],runasuser[2])
- self.log("Change User/Group from %s(%d) to %s(%d)" % (startuser[0],startuser[2],runasuser[0],runasuser[2]))
+ self.log("Change User/Group from %s(%d) to %s(%d) FIXME: disabled" % (startuser[0],startuser[2],runasuser[0],runasuser[2]))
except KeyError:
pass
- if os.getuid()==0:
- self.log("\n### Run as root is not recommend\n### set user in pywiregate.conf\n\n")
+ if os.getuid() == 0:
+ self.log("### Run as root is not recommend ### set user in pywiregate.conf",'warn')
## Mainloop only checking for Watchdog
while True:
@@ -224,16 +228,16 @@
maxlevel = self.config['WireGate']['loglevel']
if not filename:
filename = self.config['WireGate']['logfile']
- 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)
+ LEVELS = {'debug': log.logging.DEBUG,'info': log.logging.INFO,'notice': log.logging.NOTICE,'warning': log.logging.WARNING,'error': log.logging.ERROR,'critical': log.logging.CRITICAL}
+ level = LEVELS.get(maxlevel, log.logging.NOTSET)
# create logger
- formatter = logging.Formatter('%(asctime)s %(name)-12s: %(levelname)-8s %(message)s')
- logger = logging.getLogger(instance)
+ formatter = log.logging.Formatter('%(asctime)s %(name)-12s: %(levelname)-8s %(message)s')
+ logger = log.logging.getLogger(instance)
logger.setLevel(level)
if filename:
## python handle logrotating
- handler = logging.handlers.TimedRotatingFileHandler(filename,'MIDNIGHT',encoding='utf-8',backupCount=7)
+ handler = log.logging.handlers.TimedRotatingFileHandler(filename,'MIDNIGHT',encoding='utf-8',backupCount=7)
## Handler if logrotate handles Logfiles
#handler = logging.handlers.WatchedFileHandle(filename)
@@ -245,7 +249,7 @@
# create console handler and set level to debug
if self.REDIRECTIO:
#console = logging.StreamHandler()
- console = logging.isoStreamHandler()
+ console = log.isoStreamHandler()
console.setFormatter(formatter)
logger.addHandler(console)
return logger
@@ -257,24 +261,31 @@
except KeyError:
logger = self.LOGGER[instance] = self.createLog(instance)
pass
- if severity=="debug":
- logger.debug(msg)
- elif severity=="info":
- logger.info(msg)
- elif severity=="notice":
- logger.notice(msg)
- elif severity=="warning":
- logger.warning(msg)
- elif severity=="warn":
- logger.warning(msg)
- elif severity=="error":
- logger.error(msg)
- elif severity=="critical":
- logger.critical(msg)
- else:
- logger.info(msg)
+ try:
+ if severity=="debug":
+ logger.debug(msg)
+ elif severity=="info":
+ logger.info(msg)
+ elif severity=="notice":
+ logger.notice(msg)
+ elif severity=="warning":
+ logger.warning(msg)
+ elif severity=="warn":
+ #print "SEVERITY: %r " % logging._levelNames
+ logger.warning(msg)
+ elif severity=="error":
+ logger.error(msg)
+ elif severity=="critical":
+ logger.critical(msg)
+ else:
+ logger.info(msg)
+ except:
+ ## logging shouldnt break execution
+ #pass
+ raise
+
def debug(self,msg):
self.log(msg,"debug")
Modified: PyWireGate/trunk/log/__init__.py
===================================================================
--- PyWireGate/trunk/log/__init__.py 2010-11-04 22:27:12 UTC (rev 79)
+++ PyWireGate/trunk/log/__init__.py 2010-11-05 10:25:12 UTC (rev 80)
@@ -1,25 +1,29 @@
# -*- coding: iso8859-1 -*-
-from logging import *
-import logging.handlers as handlers
+## add notice as loglevel
+import logging
+import logging.handlers
+import sys
+
+logging._acquireLock()
## 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
+logging.FATAL = logging.CRITICAL = FATAL = CRITICAL = 60
+logging.ERROR = ERROR = 50
+logging.WARN = logging.WARNING = WARN = WARNING = 40
+logging.NOTICE = 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')
+logging.addLevelName(NOTICE, 'NOTICE')
+logging.addLevelName(WARNING, 'WARNING')
+logging.addLevelName(WARN, 'WARN')
+logging.addLevelName(ERROR, 'ERROR')
+logging.addLevelName(FATAL, 'FATAL')
+logging.addLevelName(CRITICAL, 'CRITICAL')
# define a new logger function for notice
# this is exactly like existing info, critical, debug...etc
@@ -39,7 +43,7 @@
apply(self._log, (NOTICE, msg, args), kwargs)
# make the notice function known in the system Logger class
-Logger.notice = Logger_notice
+logging.Logger.notice = Logger_notice
# define a new root level notice function
# this is exactly like existing info, critical, debug...etc
@@ -52,17 +56,18 @@
apply(root.notice, (msg,)+args, kwargs)
# make the notice root level function known
-notice = root_notice
+logging.notice = root_notice
# add NOTICE to the priority map of all the levels
-handlers.SysLogHandler.priority_map['NOTICE'] = 'notice'
+logging.handlers.SysLogHandler.priority_map['NOTICE'] = 'notice'
+logging._releaseLock()
-class isoStreamHandler(StreamHandler):
+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)
- StreamHandler.emit(self,record)
+ logging.StreamHandler.emit(self,record)
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|