mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-07-29 12:09:37 +00:00
Configure python logging via Django and remove custom logger
This commit is contained in:
parent
f4a2181762
commit
f88737b913
40
logger.py
40
logger.py
@ -1,40 +0,0 @@
|
||||
import cherrypy
|
||||
import inspect
|
||||
import cfg
|
||||
|
||||
|
||||
def init():
|
||||
"""Initialize logging"""
|
||||
cherrypy.log.error_file = cfg.status_log_file
|
||||
cherrypy.log.access_file = cfg.access_log_file
|
||||
if not cfg.no_daemon:
|
||||
cherrypy.log.screen = False
|
||||
|
||||
|
||||
class Logger(object):
|
||||
"""By convention, log levels are DEBUG, INFO, WARNING, ERROR and CRITICAL."""
|
||||
def log(self, msg, level="DEBUG"):
|
||||
cherrypy.log.error("%s %s" % (level, msg), inspect.stack()[2][3], 20)
|
||||
def __call__(self, *args):
|
||||
self.log(*args)
|
||||
|
||||
def debug(self, msg):
|
||||
self.log(msg)
|
||||
|
||||
def info(self, msg):
|
||||
self.log(msg, "INFO")
|
||||
|
||||
def warn(self, msg):
|
||||
self.log(msg, "WARNING")
|
||||
|
||||
def warning(self, msg):
|
||||
self.log(msg, "WARNING")
|
||||
|
||||
def error(self, msg):
|
||||
self.log(msg, "ERROR")
|
||||
|
||||
def err(self, msg):
|
||||
self.error(msg)
|
||||
|
||||
def critical(self, msg):
|
||||
self.log(msg, "CRITICAL")
|
||||
39
plinth.py
39
plinth.py
@ -17,9 +17,6 @@ import cfg
|
||||
import module_loader
|
||||
import service
|
||||
|
||||
import logger
|
||||
from logger import Logger
|
||||
|
||||
__version__ = "0.2.14"
|
||||
__author__ = "James Vasile"
|
||||
__copyright__ = "Copyright 2011-2013, James Vasile"
|
||||
@ -57,8 +54,13 @@ def parse_arguments():
|
||||
|
||||
def setup_logging():
|
||||
"""Setup logging framework"""
|
||||
cfg.log = Logger()
|
||||
logger.init()
|
||||
# Don't propagate cherrypy log messages to root logger
|
||||
logging.getLogger('cherrypy').propagate = False
|
||||
|
||||
cherrypy.log.error_file = cfg.status_log_file
|
||||
cherrypy.log.access_file = cfg.access_log_file
|
||||
if not cfg.no_daemon:
|
||||
cherrypy.log.screen = False
|
||||
|
||||
|
||||
def setup_paths():
|
||||
@ -134,6 +136,32 @@ def configure_django():
|
||||
'django.contrib.messages.context_processors.messages',
|
||||
'plinth.context_processor']
|
||||
|
||||
logging_configuration = {
|
||||
'version': 1,
|
||||
'disable_existing_loggers': False,
|
||||
'formatters': {
|
||||
'default': {
|
||||
'format':
|
||||
'[%(asctime)s] %(name)-14s %(levelname)-8s %(message)s',
|
||||
}
|
||||
},
|
||||
'handlers': {
|
||||
'file': {
|
||||
'class': 'logging.FileHandler',
|
||||
'filename': cfg.status_log_file,
|
||||
'formatter': 'default'
|
||||
},
|
||||
'console': {
|
||||
'class': 'logging.StreamHandler',
|
||||
'formatter': 'default'
|
||||
}
|
||||
},
|
||||
'root': {
|
||||
'handlers': ['console', 'file'],
|
||||
'level': 'DEBUG' if cfg.debug else 'INFO'
|
||||
}
|
||||
}
|
||||
|
||||
data_file = os.path.join(cfg.data_dir, 'plinth.sqlite3')
|
||||
|
||||
template_directories = module_loader.get_template_directories()
|
||||
@ -150,6 +178,7 @@ def configure_django():
|
||||
'django.contrib.auth',
|
||||
'django.contrib.contenttypes',
|
||||
'django.contrib.messages'],
|
||||
LOGGING=logging_configuration,
|
||||
LOGIN_URL=cfg.server_dir + '/accounts/login/',
|
||||
LOGIN_REDIRECT_URL=cfg.server_dir + '/',
|
||||
LOGOUT_URL=cfg.server_dir + '/accounts/logout/',
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user