[707] | 1 | # PyKota |
---|
| 2 | # |
---|
| 3 | # PyKota : Print Quotas for CUPS |
---|
| 4 | # |
---|
| 5 | # (c) 2003 Jerome Alet <alet@librelogiciel.com> |
---|
| 6 | # You're welcome to redistribute this software under the |
---|
| 7 | # terms of the GNU General Public Licence version 2.0 |
---|
| 8 | # or, at your option, any higher version. |
---|
| 9 | # |
---|
| 10 | # You can read the complete GNU GPL in the file COPYING |
---|
| 11 | # which should come along with this software, or visit |
---|
| 12 | # the Free Software Foundation's WEB site http://www.fsf.org |
---|
| 13 | # |
---|
| 14 | # $Id$ |
---|
| 15 | # |
---|
| 16 | # $Log$ |
---|
[825] | 17 | # Revision 1.4 2003/02/27 23:48:41 jalet |
---|
| 18 | # Correctly maps PyKota's log levels to syslog log levels |
---|
| 19 | # |
---|
[824] | 20 | # Revision 1.3 2003/02/27 22:55:20 jalet |
---|
| 21 | # WARN log priority doesn't exist. |
---|
| 22 | # |
---|
[710] | 23 | # Revision 1.2 2003/02/05 23:47:54 jalet |
---|
| 24 | # Forgotten default argument |
---|
| 25 | # |
---|
[707] | 26 | # Revision 1.1 2003/02/05 23:09:20 jalet |
---|
| 27 | # Name conflict |
---|
| 28 | # |
---|
| 29 | # |
---|
| 30 | # |
---|
| 31 | |
---|
| 32 | import sys |
---|
| 33 | import syslog |
---|
| 34 | |
---|
| 35 | class Logger : |
---|
| 36 | """A logger class which logs to syslog.""" |
---|
[825] | 37 | levels = { "error" : "ERR", "warn": "WARNING", "info": "INFO", "debug": "DEBUG" } |
---|
[707] | 38 | def __init__(self) : |
---|
| 39 | """Opens the logging subsystem.""" |
---|
| 40 | syslog.openlog("PyKota", 0, syslog.LOG_LPR) |
---|
| 41 | |
---|
| 42 | def __del__(self) : |
---|
| 43 | """Ensures the logging subsystem is closed.""" |
---|
| 44 | syslog.closelog() |
---|
| 45 | |
---|
[710] | 46 | def log_message(self, message, level="info") : |
---|
[707] | 47 | """Sends the message to syslog.""" |
---|
[825] | 48 | priority = getattr(syslog, "LOG_%s" % self.levels.get(level.lower(), "DEBUG").upper(), syslog.LOG_DEBUG) |
---|
[707] | 49 | syslog.syslog(priority, message) |
---|