Back to index

nordugrid-arc-nox  1.1.0~rc6
logger.py
Go to the documentation of this file.
00001 import arc
00002 import traceback
00003 
00004 log_levels = [arc.DEBUG, arc.VERBOSE, arc.INFO, arc.WARNING, arc.ERROR, arc.FATAL]
00005 
00006 def get_logger(system = '<UNKNOWN>'):
00007     return Logger(arc.Logger(arc.Logger_getRootLogger(), system))
00008 
00009 class Logger:
00010 
00011     def __init__(self, logger):
00012         self.logger = logger
00013 
00014     def msg(self, *args):
00015         """docstring for log"""
00016         # initializing logging facility
00017         args = list(args)
00018         if not args:
00019             severity = arc.VERBOSE
00020         elif args[0] in log_levels:
00021             severity = args.pop(0)
00022         else:
00023             severity = arc.VERBOSE
00024         if not args:
00025             args = ['Python exception:\n', traceback.format_exc()]
00026             severity = arc.ERROR
00027         mesg = ' '.join([str(arg) for arg in args])
00028         self.logger.msg(severity, mesg)
00029         return mesg