Resolves Issue #208

This commit is contained in:
BJ Dierkes 2013-10-22 14:05:38 -05:00
parent fce44b08fe
commit 1dfee2a4a5
4 changed files with 31 additions and 20 deletions

View File

@ -23,7 +23,8 @@ Bugs:
* :issue:`199` - Moved post_argument_parsing hook down, after
arguments_override_config logic happens.
* :issue:`208` - LoggingLogHandler does not honor Meta.config_section
Features:
* :issue:`194` - Added pre_argument_parsing/post_argument_parsing hooks

View File

@ -63,7 +63,8 @@ class CementBaseHandler(meta.MetaMixin):
(self._meta.interface.IMeta.label, self._meta.label)
if self._meta.config_defaults is not None:
LOG.debug("merging config defaults from '%s'" % self)
LOG.debug("merging config defaults from '%s' " % self +
"into section '%s'" % self._meta.config_section)
dict_obj = dict()
dict_obj[self._meta.config_section] = self._meta.config_defaults
self.app.config.merge(dict_obj, override=False)

View File

@ -31,7 +31,8 @@ class LoggingLogHandler(log.CementLogHandler):
Configuration Options
The following configuration options are recognized in this class:
The following configuration options are recognized in this class
(assuming that Meta.config_section is `log`):
log.level
@ -126,9 +127,10 @@ class LoggingLogHandler(log.CementLogHandler):
# hack for application debugging
if is_true(self.app._meta.debug):
self.app.config.set('log', 'level', 'DEBUG')
self.app.config.set(self._meta.config_section, 'level', 'DEBUG')
self.set_level(self.app.config.get('log', 'level'))
level = self.app.config.get(self._meta.config_section, 'level')
self.set_level(level)
# clear loggers?
if is_true(self._meta.clear_loggers):
@ -140,8 +142,8 @@ class LoggingLogHandler(log.CementLogHandler):
# file
self._setup_file_log()
self.debug("logging initialized for '%s' using LoggingLogHandler" %
self._meta.namespace)
self.debug("logging initialized for '%s' using %s" %
(self._meta.namespace, self.__class__.__name__))
def set_level(self, level):
"""
@ -178,8 +180,9 @@ class LoggingLogHandler(log.CementLogHandler):
def _setup_console_log(self):
"""Add a console log handler."""
if is_true(self.app.config.get('log', 'to_console')):
to_console = self.app.config.get(self._meta.config_section,
'to_console')
if is_true(to_console):
console_handler = logging.StreamHandler()
if self.get_level() == logging.getLevelName(logging.DEBUG):
format = logging.Formatter(self._meta.debug_format)
@ -195,18 +198,24 @@ class LoggingLogHandler(log.CementLogHandler):
def _setup_file_log(self):
"""Add a file log handler."""
if self.app.config.get('log', 'file'):
file_path = fs.abspath(self.app.config.get('log', 'file'))
file_path = self.app.config.get(self._meta.config_section, 'file')
rotate = self.app.config.get(self._meta.config_section, 'rotate')
max_bytes = self.app.config.get(self._meta.config_section,
'max_bytes')
max_files = self.app.config.get(self._meta.config_section,
'max_files')
if file_path:
file_path = fs.abspath(file_path)
log_dir = os.path.dirname(file_path)
if not os.path.exists(log_dir):
os.makedirs(log_dir)
if self.app.config.get('log', 'rotate'):
if rotate:
from logging.handlers import RotatingFileHandler
file_handler = RotatingFileHandler(
file_path,
maxBytes=int(self.app.config.get('log', 'max_bytes')),
backupCount=int(self.app.config.get('log', 'max_files')),
maxBytes=int(max_bytes),
backupCount=int(max_files),
)
else:
from logging import FileHandler

View File

@ -50,18 +50,18 @@ handle command dispatch and rapid development.
@controller.expose(hide=True, aliases=['run'])
def default(self):
self.log.info('Inside base.default function.')
if self.pargs.foo:
self.log.info("Recieved option 'foo' with value '%s'." % \
self.pargs.foo)
self.app.log.info('Inside base.default function.')
if self.app.pargs.foo:
self.app.log.info("Recieved option 'foo' with value '%s'." % \
self.app.pargs.foo)
@controller.expose(help="this command does relatively nothing useful.")
def command1(self):
self.log.info("Inside base.command1 function.")
self.app.log.info("Inside base.command1 function.")
@controller.expose(aliases=['cmd2'], help="more of nothing.")
def command2(self):
self.log.info("Inside base.command2 function.")
self.app.log.info("Inside base.command2 function.")
# create an application
app = foundation.CementApp('example', base_controller=MyAppBaseController)