"""
Python standard logging doesn't super-intelligent and won't expose filehandles,
which we want. So we're not using it.
"""
import logging
import logging.config
import os
# Temporary hack, a clean solution seems to be tricky
# Defining a variable in our Apache startup code seem not to
# it is still set later when this code is executed via cobbler
# This is necessary to prevent apache to try to access the file
LOG_FILE = "/var/log/cobbler/cobbler.log"
try:
if not os.path.isfile(LOG_FILE):
open(LOG_FILE, 'a').close()
if os.access(LOG_FILE, os.W_OK):
logging.config.fileConfig('/etc/cobbler/logging_config.conf')
except Exception:
pass
[docs]class Logger(object):
def __init__(self, logfile=None):
if not logfile:
self.logger = logging.getLogger('root')
else:
self.logger = logging.getLogger(str(id(self)))
self.logger.propagate = False
self.logger.addHandler(logging.FileHandler(filename=logfile))
[docs] def critical(self, msg):
self.logger.critical(msg)
[docs] def error(self, msg):
self.logger.error(msg)
[docs] def warning(self, msg):
self.logger.warning(msg)
[docs] def info(self, msg):
self.logger.info(msg)
[docs] def debug(self, msg):
self.logger.debug(msg)
[docs] def flat(self, msg):
print(msg)