/usr/share/pyshared/circuits/app/log.py is in python-circuits 2.1.0-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 | # Module: logging
# Date: 11th June 2006
# Author: James Mills <prologic@shortcircuit.net.au>
"""Logging Components"""
import sys
import logging
from logging import DEBUG, INFO, WARNING, WARN, ERROR, CRITICAL
from circuits.core import handler, Event, BaseComponent
class Log(Event):
"""Log Event"""
channels = ("logger",)
class Logger(BaseComponent):
channel = "logger"
LEVELS = {
"debug": DEBUG, "info": INFO, "warning": WARNING,
"warn": WARN, "error": ERROR, "exception": ERROR,
"critical": CRITICAL
}
def __init__(self, filename, name, type, level, channel=channel):
super(Logger, self).__init__(channel=channel)
self.logger = logging.getLogger(name)
type = type.lower()
if type == "file":
hdlr = logging.FileHandler(filename)
elif type in ["winlog", "eventlog", "nteventlog"]:
# Requires win32 extensions
hdlr = logging.handlers.NTEventLogHandler(name, type="Application")
elif type in ["syslog", "unix"]:
hdlr = logging.handlers.SysLogHandler("/dev/log")
elif type in ["stderr"]:
hdlr = logging.StreamHandler(sys.stderr)
else:
raise ValueError
format = name + "[%(module)s] %(levelname)s: %(message)s"
if type == "file":
format = "%(asctime)s " + format
dateFormat = ""
level = level.upper()
if level in ["DEBUG", "ALL"]:
self.logger.setLevel(logging.DEBUG)
dateFormat = "%X"
elif level == "INFO":
self.logger.setLevel(logging.INFO)
elif level == "ERROR":
self.logger.setLevel(logging.ERROR)
elif level == "CRITICAL":
self.logger.setLevel(logging.CRITICAL)
else:
self.logger.setLevel(logging.WARNING)
formatter = logging.Formatter(format, dateFormat)
hdlr.setFormatter(formatter)
self.logger.addHandler(hdlr)
@handler("log")
def _on_log(self, level, msg, *args, **kwargs):
self.logger.log(self.LEVELS[level.lower()], msg, *args, **kwargs)
def debug(self, msg, *args, **kwargs):
self.logger.debug(msg, *args, **kwargs)
def info(self, msg, *args, **kwargs):
self.logger.info(msg, *args, **kwargs)
def warning(self, msg, *args, **kwargs):
self.logger.warning(msg, *args, **kwargs)
warn = warning
def error(self, msg, *args, **kwargs):
self.logger.error(msg, *args, **kwargs)
def exception(self, msg, *args, **kwargs):
self.logger.exception(msg, *args)
def critical(self, msg, *args, **kwargs):
self.logger.critical(msg, *args, **kwargs)
|