/usr/share/pyshared/childsplay_sp/SPLogging.py is in childsplay 1.6-1.
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 | # provides a logging object
# All modules get the same logger so this must called asap
### example "application" code to use in your module
##import logging
##module_logger = logging.getLogger("schoolsplay.<name of your module>")
##logger.debug("debug message")
##logger.info("info message")
##logger.warn("warn message")
##logger.error("error message")
##logger.critical("critical message")
##logger.exception("exception message")
import os
from SPConstants import HOMEDIR
LOGPATH = os.path.join(HOMEDIR, "schoolsplay.log")
# remove old log
if os.path.exists(LOGPATH):
try:
os.remove(LOGPATH)
except Exception, info:
print "Failed to remove old log"
print info
else:
print "removed old logpath"
# set loglevel, possible values:
# logging.DEBUG
# logging.INFO
# logging.WARNING
# logging.ERROR
# logging.CRITICAL
import logging, logging.handlers
def set_level(level):
global CONSOLELOGLEVEL, FILELOGLEVEL
lleveldict = {'debug':logging.DEBUG,
'info':logging.INFO,
'warning':logging.WARNING,
'error':logging.ERROR,
'critical':logging.CRITICAL}
if not lleveldict.has_key(level):
print "Invalid loglevel: %s, setting loglevel to 'debug'" % level
llevel = lleveldict['debug']
else:
llevel = lleveldict[level]
CONSOLELOGLEVEL = llevel
FILELOGLEVEL = llevel
def start():
global CONSOLELOGLEVEL, FILELOGLEVEL
#create logger
logger = logging.getLogger("schoolsplay")
logger.setLevel(CONSOLELOGLEVEL)
#create console handler and set level
ch = logging.StreamHandler()
ch.setLevel(CONSOLELOGLEVEL)
#create file handler and set level
if FILELOGLEVEL == logging.DEBUG:
fh = logging.FileHandler(LOGPATH)
fh.setLevel(FILELOGLEVEL)
#create formatter
formatter = logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s")
#add formatter to ch and fh
ch.setFormatter(formatter)
if FILELOGLEVEL == logging.DEBUG:
fh.setFormatter(formatter)
#add ch and fh to logger
logger.addHandler(ch)
if FILELOGLEVEL == logging.DEBUG:
logger.addHandler(fh)
logger.info("File logger created: %s" % LOGPATH)
# test
module_logger = logging.getLogger("schoolsplay.SPLogging")
module_logger.info("logger created, start logging")
import Version
module_logger.info("Starting childsplay version: %s" % Version.version)
|