tweaked logging config

This commit is contained in:
Lance Edgar 2012-07-08 13:43:28 -05:00
parent c371a2d997
commit bb7d234778
6 changed files with 22 additions and 37 deletions

View file

@ -70,15 +70,17 @@ class AppConfigParser(ConfigParser.SafeConfigParser):
file, and passes that to ``logging.config.fileConfig()``.
"""
if self.getboolean(self.appname, 'basic_logging', default=False):
edbob.basic_logging(self.appname)
path = edbob.temp_path(suffix='.conf')
self.save(path)
try:
logging.config.fileConfig(path)
except ConfigParser.NoSectionError:
pass
os.remove(path)
if self.getboolean('edbob', 'basic_logging', default=False):
edbob.basic_logging()
if self.getboolean('edbob', 'configure_logging', default=False):
path = edbob.temp_path(suffix='.conf')
self.save(path)
try:
logging.config.fileConfig(path, disable_existing_loggers=False)
except ConfigParser.NoSectionError:
pass
os.remove(path)
log.debug("Configured logging")
def get(self, section, option, raw=False, vars=None, default=None):
"""
@ -243,7 +245,6 @@ class AppConfigParser(ConfigParser.SafeConfigParser):
config.has_option('edbob', 'include_config')):
include = config.get('edbob', 'include_config')
if include:
log.debug("Including config: %s" % include)
for p in eval(include):
self.read_path(os.path.abspath(p))
ConfigParser.SafeConfigParser.read(self, path)

View file

@ -71,7 +71,9 @@ def basic_logging():
handler = logging.StreamHandler()
handler.setFormatter(logging.Formatter(
'%(levelname)-5.5s [%(name)s][%(threadName)s] %(message)s'))
logging.getLogger().addHandler(handler)
root = logging.getLogger()
root.addHandler(handler)
root.setLevel(logging.INFO)
def get_uuid():

View file

@ -51,7 +51,6 @@ def main(global_config, **settings):
# Configure edbob. Note that this is done last, primarily to allow logging
# to leverage edbob's config inheritance.
edbob.basic_logging()
edbob.init('{{package}}', os.path.abspath(settings['edbob.config']))
return config.make_wsgi_app()

View file

@ -27,10 +27,7 @@ whatever = you like
use = egg:{{package}}
pyramid.reload_templates = true
pyramid.debug_authorization = false
pyramid.debug_notfound = false
pyramid.debug_routematch = false
pyramid.debug_templates = true
pyramid.debug_all = true
pyramid.default_locale_name = en
pyramid.includes =
pyramid_debugtoolbar
@ -51,9 +48,6 @@ port = 6543
[edbob]
include_config = ['%(here)s/production.ini']
[edbob.db]
sqlalchemy.url = sqlite:///{{package}}.sqlite
####################
# logging
@ -62,8 +56,5 @@ sqlalchemy.url = sqlite:///{{package}}.sqlite
[logger_root]
level = INFO
[logger_edbob]
level = INFO
[logger_{{package_logger}}]
level = DEBUG

View file

@ -21,10 +21,7 @@ whatever = you like
use = egg:{{package}}
pyramid.reload_templates = false
pyramid.debug_authorization = false
pyramid.debug_notfound = false
pyramid.debug_routematch = false
pyramid.debug_templates = false
pyramid.debug_all = false
pyramid.default_locale_name = en
# Hack so edbob can find this file from within WSGI app.
@ -56,6 +53,8 @@ sqlalchemy.url = postgresql://user:pass@localhost/{{package}}
[edbob]
init = edbob.time, edbob.db
basic_logging = True
configure_logging = True
# shell.python = ipython
[edbob.db]
@ -82,7 +81,7 @@ timezone = US/Central
####################
[loggers]
keys = root, edbob, {{package_logger}}
keys = root, {{package_logger}}
[handlers]
keys = file, console, email
@ -95,15 +94,10 @@ keys = generic, console
handlers = file, console
level = WARNING
[logger_edbob]
qualname = edbob
handlers =
# level = INFO
[logger_{{package_logger}}]
qualname = {{package}}
handlers =
level = WARNING
# level = NOTSET
[handler_file]
class = FileHandler
@ -114,12 +108,10 @@ formatter = generic
class = StreamHandler
args = (sys.stderr,)
formatter = console
# level = NOTSET
[handler_email]
class = handlers.SMTPHandler
args = ('mail.example.com', '{{package}}@example.com', ['support@example.com'], '[{{project}} error]',
('user', 'pass'))
args = ('mail.example.com', '{{package}}@example.com', ['support@example.com'], '[{{project}} error]', ('user', 'pass'))
level = ERROR
formatter = generic

View file

@ -47,7 +47,7 @@ def init(config):
tz = config.get('edbob.time', 'timezone')
if tz:
set_timezone(tz)
log.debug("Timezone set to '%s'" % tz)
log.info("Timezone set to '%s'" % tz)
else:
log.warning("No timezone configured; falling back to US/Central")
set_timezone('US/Central')