root / pykota / trunk / pykota / loggers / system.py @ 825

Revision 825, 1.4 kB (checked in by jalet, 21 years ago)

Correctly maps PyKota's log levels to syslog log levels

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
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$
17# Revision 1.4  2003/02/27 23:48:41  jalet
18# Correctly maps PyKota's log levels to syslog log levels
19#
20# Revision 1.3  2003/02/27 22:55:20  jalet
21# WARN log priority doesn't exist.
22#
23# Revision 1.2  2003/02/05 23:47:54  jalet
24# Forgotten default argument
25#
26# Revision 1.1  2003/02/05 23:09:20  jalet
27# Name conflict
28#
29#
30#
31
32import sys
33import syslog
34
35class Logger :
36    """A logger class which logs to syslog."""
37    levels = { "error" : "ERR", "warn": "WARNING", "info": "INFO", "debug": "DEBUG" }
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       
46    def log_message(self, message, level="info") :
47        """Sends the message to syslog."""
48        priority = getattr(syslog, "LOG_%s" % self.levels.get(level.lower(), "DEBUG").upper(), syslog.LOG_DEBUG)
49        syslog.syslog(priority, message)
Note: See TracBrowser for help on using the browser.