mirror of
https://salsa.debian.org/freeipa-team/freeipa.git
synced 2025-02-25 18:55:28 -06:00
Logging formats are now env variables; added log_format_stderr_debug format used when env.debug is True
This commit is contained in:
@@ -22,10 +22,38 @@
|
|||||||
All constants centralized in one file.
|
All constants centralized in one file.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
# The section to read in the config files, i.e. [global]
|
# The section to read in the config files, i.e. [global]
|
||||||
CONFIG_SECTION = '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
|
# The default configuration for api.env
|
||||||
# This is a tuple instead of a dict so that it is immutable.
|
# 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)".
|
# To create a dict with this config, just "d = dict(DEFAULT_CONFIG)".
|
||||||
@@ -55,6 +83,11 @@ DEFAULT_CONFIG = (
|
|||||||
('debug', False),
|
('debug', False),
|
||||||
('mode', 'production'),
|
('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!
|
# The remaining keys are never set from the values here!
|
||||||
# ********************************************************
|
# ********************************************************
|
||||||
@@ -87,20 +120,3 @@ DEFAULT_CONFIG = (
|
|||||||
('log', None), # Path to log file
|
('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',
|
|
||||||
])
|
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ from os import path
|
|||||||
import errors
|
import errors
|
||||||
from errors import check_type, check_isinstance
|
from errors import check_type, check_isinstance
|
||||||
from config import Environment, Env
|
from config import Environment, Env
|
||||||
from constants import LOGGING_FILE_FORMAT, LOGGING_CONSOLE_FORMAT, DEFAULT_CONFIG
|
from constants import DEFAULT_CONFIG
|
||||||
import util
|
import util
|
||||||
|
|
||||||
|
|
||||||
@@ -785,14 +785,15 @@ class API(DictProxy):
|
|||||||
|
|
||||||
# Add stderr handler:
|
# Add stderr handler:
|
||||||
stderr = logging.StreamHandler()
|
stderr = logging.StreamHandler()
|
||||||
stderr.setFormatter(logging.Formatter(LOGGING_CONSOLE_FORMAT))
|
format = self.env.log_format_stderr
|
||||||
if self.env.debug:
|
if self.env.debug:
|
||||||
level = logging.DEBUG
|
format = self.env.log_format_stderr_debug
|
||||||
|
stderr.setLevel(logging.DEBUG)
|
||||||
elif self.env.verbose:
|
elif self.env.verbose:
|
||||||
level = logging.INFO
|
stderr.setLevel(logging.INFO)
|
||||||
else:
|
else:
|
||||||
level = logging.WARNING
|
stderr.setLevel(logging.WARNING)
|
||||||
stderr.setLevel(level)
|
stderr.setFormatter(logging.Formatter(format))
|
||||||
log.addHandler(stderr)
|
log.addHandler(stderr)
|
||||||
|
|
||||||
# Add file handler:
|
# Add file handler:
|
||||||
@@ -806,12 +807,11 @@ class API(DictProxy):
|
|||||||
log.warn('Could not create log_dir %r', log_dir)
|
log.warn('Could not create log_dir %r', log_dir)
|
||||||
return
|
return
|
||||||
handler = logging.FileHandler(self.env.log)
|
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:
|
if self.env.debug:
|
||||||
level = logging.DEBUG
|
handler.setLevel(logging.DEBUG)
|
||||||
else:
|
else:
|
||||||
level = logging.INFO
|
handler.setLevel(logging.INFO)
|
||||||
handler.setLevel(level)
|
|
||||||
log.addHandler(handler)
|
log.addHandler(handler)
|
||||||
|
|
||||||
def bootstrap_from_options(self, options=None, context=None):
|
def bootstrap_from_options(self, options=None, context=None):
|
||||||
|
|||||||
@@ -26,7 +26,6 @@ from os import path
|
|||||||
import imp
|
import imp
|
||||||
import optparse
|
import optparse
|
||||||
import krbV
|
import krbV
|
||||||
from constants import LOGGING_CONSOLE_FORMAT, LOGGING_FILE_FORMAT
|
|
||||||
|
|
||||||
|
|
||||||
def xmlrpc_marshal(*args, **kw):
|
def xmlrpc_marshal(*args, **kw):
|
||||||
|
|||||||
Reference in New Issue
Block a user