tweaked logging config
This commit is contained in:
parent
c371a2d997
commit
bb7d234778
6 changed files with 22 additions and 37 deletions
|
@ -70,15 +70,17 @@ class AppConfigParser(ConfigParser.SafeConfigParser):
|
||||||
file, and passes that to ``logging.config.fileConfig()``.
|
file, and passes that to ``logging.config.fileConfig()``.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if self.getboolean(self.appname, 'basic_logging', default=False):
|
if self.getboolean('edbob', 'basic_logging', default=False):
|
||||||
edbob.basic_logging(self.appname)
|
edbob.basic_logging()
|
||||||
path = edbob.temp_path(suffix='.conf')
|
if self.getboolean('edbob', 'configure_logging', default=False):
|
||||||
self.save(path)
|
path = edbob.temp_path(suffix='.conf')
|
||||||
try:
|
self.save(path)
|
||||||
logging.config.fileConfig(path)
|
try:
|
||||||
except ConfigParser.NoSectionError:
|
logging.config.fileConfig(path, disable_existing_loggers=False)
|
||||||
pass
|
except ConfigParser.NoSectionError:
|
||||||
os.remove(path)
|
pass
|
||||||
|
os.remove(path)
|
||||||
|
log.debug("Configured logging")
|
||||||
|
|
||||||
def get(self, section, option, raw=False, vars=None, default=None):
|
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')):
|
config.has_option('edbob', 'include_config')):
|
||||||
include = config.get('edbob', 'include_config')
|
include = config.get('edbob', 'include_config')
|
||||||
if include:
|
if include:
|
||||||
log.debug("Including config: %s" % include)
|
|
||||||
for p in eval(include):
|
for p in eval(include):
|
||||||
self.read_path(os.path.abspath(p))
|
self.read_path(os.path.abspath(p))
|
||||||
ConfigParser.SafeConfigParser.read(self, path)
|
ConfigParser.SafeConfigParser.read(self, path)
|
||||||
|
|
|
@ -71,7 +71,9 @@ def basic_logging():
|
||||||
handler = logging.StreamHandler()
|
handler = logging.StreamHandler()
|
||||||
handler.setFormatter(logging.Formatter(
|
handler.setFormatter(logging.Formatter(
|
||||||
'%(levelname)-5.5s [%(name)s][%(threadName)s] %(message)s'))
|
'%(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():
|
def get_uuid():
|
||||||
|
|
|
@ -51,7 +51,6 @@ def main(global_config, **settings):
|
||||||
|
|
||||||
# Configure edbob. Note that this is done last, primarily to allow logging
|
# Configure edbob. Note that this is done last, primarily to allow logging
|
||||||
# to leverage edbob's config inheritance.
|
# to leverage edbob's config inheritance.
|
||||||
edbob.basic_logging()
|
|
||||||
edbob.init('{{package}}', os.path.abspath(settings['edbob.config']))
|
edbob.init('{{package}}', os.path.abspath(settings['edbob.config']))
|
||||||
|
|
||||||
return config.make_wsgi_app()
|
return config.make_wsgi_app()
|
||||||
|
|
|
@ -27,10 +27,7 @@ whatever = you like
|
||||||
use = egg:{{package}}
|
use = egg:{{package}}
|
||||||
|
|
||||||
pyramid.reload_templates = true
|
pyramid.reload_templates = true
|
||||||
pyramid.debug_authorization = false
|
pyramid.debug_all = true
|
||||||
pyramid.debug_notfound = false
|
|
||||||
pyramid.debug_routematch = false
|
|
||||||
pyramid.debug_templates = true
|
|
||||||
pyramid.default_locale_name = en
|
pyramid.default_locale_name = en
|
||||||
pyramid.includes =
|
pyramid.includes =
|
||||||
pyramid_debugtoolbar
|
pyramid_debugtoolbar
|
||||||
|
@ -51,9 +48,6 @@ port = 6543
|
||||||
[edbob]
|
[edbob]
|
||||||
include_config = ['%(here)s/production.ini']
|
include_config = ['%(here)s/production.ini']
|
||||||
|
|
||||||
[edbob.db]
|
|
||||||
sqlalchemy.url = sqlite:///{{package}}.sqlite
|
|
||||||
|
|
||||||
|
|
||||||
####################
|
####################
|
||||||
# logging
|
# logging
|
||||||
|
@ -62,8 +56,5 @@ sqlalchemy.url = sqlite:///{{package}}.sqlite
|
||||||
[logger_root]
|
[logger_root]
|
||||||
level = INFO
|
level = INFO
|
||||||
|
|
||||||
[logger_edbob]
|
|
||||||
level = INFO
|
|
||||||
|
|
||||||
[logger_{{package_logger}}]
|
[logger_{{package_logger}}]
|
||||||
level = DEBUG
|
level = DEBUG
|
||||||
|
|
|
@ -21,10 +21,7 @@ whatever = you like
|
||||||
use = egg:{{package}}
|
use = egg:{{package}}
|
||||||
|
|
||||||
pyramid.reload_templates = false
|
pyramid.reload_templates = false
|
||||||
pyramid.debug_authorization = false
|
pyramid.debug_all = false
|
||||||
pyramid.debug_notfound = false
|
|
||||||
pyramid.debug_routematch = false
|
|
||||||
pyramid.debug_templates = false
|
|
||||||
pyramid.default_locale_name = en
|
pyramid.default_locale_name = en
|
||||||
|
|
||||||
# Hack so edbob can find this file from within WSGI app.
|
# Hack so edbob can find this file from within WSGI app.
|
||||||
|
@ -56,6 +53,8 @@ sqlalchemy.url = postgresql://user:pass@localhost/{{package}}
|
||||||
|
|
||||||
[edbob]
|
[edbob]
|
||||||
init = edbob.time, edbob.db
|
init = edbob.time, edbob.db
|
||||||
|
basic_logging = True
|
||||||
|
configure_logging = True
|
||||||
# shell.python = ipython
|
# shell.python = ipython
|
||||||
|
|
||||||
[edbob.db]
|
[edbob.db]
|
||||||
|
@ -82,7 +81,7 @@ timezone = US/Central
|
||||||
####################
|
####################
|
||||||
|
|
||||||
[loggers]
|
[loggers]
|
||||||
keys = root, edbob, {{package_logger}}
|
keys = root, {{package_logger}}
|
||||||
|
|
||||||
[handlers]
|
[handlers]
|
||||||
keys = file, console, email
|
keys = file, console, email
|
||||||
|
@ -95,15 +94,10 @@ keys = generic, console
|
||||||
handlers = file, console
|
handlers = file, console
|
||||||
level = WARNING
|
level = WARNING
|
||||||
|
|
||||||
[logger_edbob]
|
|
||||||
qualname = edbob
|
|
||||||
handlers =
|
|
||||||
# level = INFO
|
|
||||||
|
|
||||||
[logger_{{package_logger}}]
|
[logger_{{package_logger}}]
|
||||||
qualname = {{package}}
|
qualname = {{package}}
|
||||||
handlers =
|
handlers =
|
||||||
level = WARNING
|
# level = NOTSET
|
||||||
|
|
||||||
[handler_file]
|
[handler_file]
|
||||||
class = FileHandler
|
class = FileHandler
|
||||||
|
@ -114,12 +108,10 @@ formatter = generic
|
||||||
class = StreamHandler
|
class = StreamHandler
|
||||||
args = (sys.stderr,)
|
args = (sys.stderr,)
|
||||||
formatter = console
|
formatter = console
|
||||||
# level = NOTSET
|
|
||||||
|
|
||||||
[handler_email]
|
[handler_email]
|
||||||
class = handlers.SMTPHandler
|
class = handlers.SMTPHandler
|
||||||
args = ('mail.example.com', '{{package}}@example.com', ['support@example.com'], '[{{project}} error]',
|
args = ('mail.example.com', '{{package}}@example.com', ['support@example.com'], '[{{project}} error]', ('user', 'pass'))
|
||||||
('user', 'pass'))
|
|
||||||
level = ERROR
|
level = ERROR
|
||||||
formatter = generic
|
formatter = generic
|
||||||
|
|
||||||
|
|
|
@ -47,7 +47,7 @@ def init(config):
|
||||||
tz = config.get('edbob.time', 'timezone')
|
tz = config.get('edbob.time', 'timezone')
|
||||||
if tz:
|
if tz:
|
||||||
set_timezone(tz)
|
set_timezone(tz)
|
||||||
log.debug("Timezone set to '%s'" % tz)
|
log.info("Timezone set to '%s'" % tz)
|
||||||
else:
|
else:
|
||||||
log.warning("No timezone configured; falling back to US/Central")
|
log.warning("No timezone configured; falling back to US/Central")
|
||||||
set_timezone('US/Central')
|
set_timezone('US/Central')
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue