NAMESPACE = 'gentoo-keys'
logger = None
Console_handler = None
-File_handler = None
log_levels = {
'CRITICAL': logging.CRITICAL,
def set_logger(namespace=None, logpath='', level=None):
- global logger, NAMESPACE, Console_handler, File_handler
+ global logger, NAMESPACE, Console_handler
if not namespace:
namespace = NAMESPACE
else:
if logpath:
logname = os.path.join(logpath,
'%s-%s.log' % (namespace,time.strftime('%Y%m%d-%H:%M')))
- File_handler = logging.FileHandler(logname)
+ file_handler = logging.FileHandler(logname)
if level:
#print "Setting cli log level", level, log_levels[level]
- File_handler.setLevel(log_levels[level])
+ file_handler.setLevel(log_levels[level])
else:
#print "Create file handler which logs even debug messages"
- File_handler.setLevel(log_levels['DEBUG'])
+ file_handler.setLevel(log_levels['DEBUG'])
+ file_handler.setFormatter(formatter)
+ logger.addHandler(file_handler)
- File_handler.setFormatter(formatter)
# create console handler with a higher log level
Console_handler = logging.StreamHandler()
Console_handler.setLevel(logging.ERROR)
#Console_handler.setFormatter(formatter)
logger.addHandler(Console_handler)
- logger.addHandler(File_handler)
- #print "File logger suppose to be initialized", logger, File_handler, Console_handler
+ #print "File logger suppose to be initialized", logger, Console_handler
logger.debug("Loggers initialized")
return logger