Im having a bad day. The logging module refused to send anything to syslog no matter what I did, so discovering the syslog module & thought, for what I need I will write a simple class to do the job.
class kmotion_logger: def __init__(self, ident, min_priority): # min_priority must be one of ... # EMERG, ALERT, CRIT, ERR, WARNING, NOTICE, INFO, DEBUG self.case = {'EMERG': syslog.LOG_EMERG, 'ALERT': syslog.LOG_ALERT, 'CRIT': syslog.LOG_CRIT, 'ERR': syslog.LOG_ERR, 'WARNING': syslog.LOG_WARNING, 'NOTICE': syslog.LOG_NOTICE, 'INFO': syslog.LOG_INFO, 'DEBUG': syslog.LOG_DEBUG} self.ident = ident print 'log up to & inclusive of ... ', self.case[min_priority] syslog.setlogmask(syslog.LOG_UPTO(self.case[min_priority])) def log(self, msg, priority): print 'sending message at level ...', self.case[priority] syslog.openlog(self.ident , syslog.LOG_PID, (self.case[priority] | syslog.LOG_USER)) syslog.syslog(msg) syslog.closelog() And call it with ... import kmotion_logger # EMERG, ALERT, CRIT, ERR, WARNING, NOTICE, INFO, DEBUG logger = kmotion_logger.kmotion_logger("kmotion", "DEBUG") logger.log("TESTING", "ALERT") And it worked as I wanted, it logs to syslog (cheers, jumps for joy) :) Then I noticed several inconsistencys, the following also works AOK ... import kmotion_logger # EMERG, ALERT, CRIT, ERR, WARNING, NOTICE, INFO, DEBUG logger = kmotion_logger.kmotion_logger("kmotion", "INFO") logger.log("TESTING", "ALERT") But the next one fails to log ... import kmotion_logger # EMERG, ALERT, CRIT, ERR, WARNING, NOTICE, INFO, DEBUG logger = kmotion_logger.kmotion_logger("kmotion", "NOTICE") logger.log("TESTING", "ALERT") ALERT is above NOTICE & should log .... I am suspicious of '(self.case[priority] | syslog.LOG_USER)' although it looks right and have tried LOG_LOCAL6 etc but still no joy I have even tried explaining it to my cat, no joy Any ideas anyone ? Cheers A very log frustrated programmer Dave -- Please avoid sending me Word or PowerPoint attachments. See http://www.gnu.org/philosophy/no-word-attachments.html _______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor