Logging formats are now env variables; added log_format_stderr_debug format used when env.debug is True

This commit is contained in:
Jason Gerard DeRose
2008-10-31 18:55:32 -06:00
parent a23d41a57f
commit 5269d1396c
3 changed files with 43 additions and 28 deletions

View File

@@ -22,10 +22,38 @@
All constants centralized in one file.
"""
# The section to read in the config files, i.e. [global]
CONFIG_SECTION = 'global'
# Log format for console output
LOG_FORMAT_STDERR = ': '.join([
'%(name)s',
'%(levelname)s',
'%(message)s',
])
# Log format for console output when env.dubug is True:
LOG_FORMAT_STDERR_DEBUG = ' '.join([
'%(levelname)s',
'%(message)r',
'%(lineno)d',
'%(filename)s',
])
# Tab-delimited log format for file (easy to opened in a spreadsheet):
LOG_FORMAT_FILE = ' '.join([
'%(created)f',
'%(levelname)s',
'%(message)r', # Using %r for repr() so message is a single line
'%(lineno)d',
'%(pathname)s',
])
# The default configuration for api.env
# This is a tuple instead of a dict so that it is immutable.
# To create a dict with this config, just "d = dict(DEFAULT_CONFIG)".
@@ -55,6 +83,11 @@ DEFAULT_CONFIG = (
('debug', False),
('mode', 'production'),
# Logging:
('log_format_stderr', LOG_FORMAT_STDERR),
('log_format_stderr_debug', LOG_FORMAT_STDERR_DEBUG),
('log_format_file', LOG_FORMAT_FILE),
# ********************************************************
# The remaining keys are never set from the values here!
# ********************************************************
@@ -87,20 +120,3 @@ DEFAULT_CONFIG = (
('log', None), # Path to log file
)
LOGGING_CONSOLE_FORMAT = ': '.join([
'%(name)s',
'%(levelname)s',
'%(message)s',
])
# Tab-delimited format designed to be easily opened in a spreadsheet:
LOGGING_FILE_FORMAT = ' '.join([
'%(created)f',
'%(levelname)s',
'%(message)r', # Using %r for repr() so message is a single line
'%(pathname)s',
'%(lineno)d',
])

View File

@@ -35,7 +35,7 @@ from os import path
import errors
from errors import check_type, check_isinstance
from config import Environment, Env
from constants import LOGGING_FILE_FORMAT, LOGGING_CONSOLE_FORMAT, DEFAULT_CONFIG
from constants import DEFAULT_CONFIG
import util
@@ -785,14 +785,15 @@ class API(DictProxy):
# Add stderr handler:
stderr = logging.StreamHandler()
stderr.setFormatter(logging.Formatter(LOGGING_CONSOLE_FORMAT))
format = self.env.log_format_stderr
if self.env.debug:
level = logging.DEBUG
format = self.env.log_format_stderr_debug
stderr.setLevel(logging.DEBUG)
elif self.env.verbose:
level = logging.INFO
stderr.setLevel(logging.INFO)
else:
level = logging.WARNING
stderr.setLevel(level)
stderr.setLevel(logging.WARNING)
stderr.setFormatter(logging.Formatter(format))
log.addHandler(stderr)
# Add file handler:
@@ -806,12 +807,11 @@ class API(DictProxy):
log.warn('Could not create log_dir %r', log_dir)
return
handler = logging.FileHandler(self.env.log)
handler.setFormatter(logging.Formatter(LOGGING_FILE_FORMAT))
handler.setFormatter(logging.Formatter(self.env.log_format_file))
if self.env.debug:
level = logging.DEBUG
handler.setLevel(logging.DEBUG)
else:
level = logging.INFO
handler.setLevel(level)
handler.setLevel(logging.INFO)
log.addHandler(handler)
def bootstrap_from_options(self, options=None, context=None):

View File

@@ -26,7 +26,6 @@ from os import path
import imp
import optparse
import krbV
from constants import LOGGING_CONSOLE_FORMAT, LOGGING_FILE_FORMAT
def xmlrpc_marshal(*args, **kw):