From 8fa310cc7a7f989dc480bd96e2ec083722a1f2cc Mon Sep 17 00:00:00 2001 From: Flaper Fesp Date: Thu, 13 Jun 2013 11:32:19 +0200 Subject: [PATCH] Move log.setup to Bootstrap and use cfg.CONF opts This patch uses cfg.CONF as ConfigOpts in common/config instead of creating a new instance of it. This is needed since most of Oslo's modules use the global CONF object to register their config parameters. The patch also moves log.setup call into Bootstrap and calls it after configs are loaded. Fixes bug: #1190524 Change-Id: Ib601418a7dbcad84c79b640b93bc5798ec4a62c4 --- etc/logging.conf-sample | 59 ++++++++++++++++------------------------ etc/marconi.conf-sample | 23 ++++++++++++++-- marconi/bootstrap.py | 8 ++++++ marconi/cmd/server.py | 2 -- marconi/common/config.py | 2 +- 5 files changed, 52 insertions(+), 42 deletions(-) diff --git a/etc/logging.conf-sample b/etc/logging.conf-sample index d5e3d0578..4c3f0f628 100644 --- a/etc/logging.conf-sample +++ b/etc/logging.conf-sample @@ -1,45 +1,37 @@ -; Loaded via logging.config.fileConfig -; @todo Customize for Marconi loggers - [loggers] -keys=root +keys=root,server,combined + +[formatters] +keys=normal,normal_with_name,debug [handlers] keys=production,file,devel -[formatters] -keys=minimal,normal,debug - - -########### -# Loggers # -########### - [logger_root] -level=WARNING -handlers=file +level=NOTSET +handlers=devel -[logger_access] -level=INFO -qualname=access -handlers=access_file +[logger_server] +level=DEBUG +handlers=devel +qualname=marconi-server - -################ -# Log Handlers # -################ +[logger_combined] +level=DEBUG +handlers=devel +qualname=marconi-combined [handler_production] class=handlers.SysLogHandler level=ERROR -formatter=normal +formatter=normal_with_name args=(('localhost', handlers.SYSLOG_UDP_PORT), handlers.SysLogHandler.LOG_USER) [handler_file] -class=handlers.WatchedFileHandler -level=WARNING -formatter=normal -args=('error.log',) +class=FileHandler +level=DEBUG +formatter=normal_with_name +args=('marconi.log', 'w') [handler_devel] class=StreamHandler @@ -47,16 +39,11 @@ level=NOTSET formatter=debug args=(sys.stdout,) - -################## -# Log Formatters # -################## - -[formatter_minimal] -format=%(message)s - [formatter_normal] +format=%(asctime)s %(levelname)s %(message)s + +[formatter_normal_with_name] format=(%(name)s): %(asctime)s %(levelname)s %(message)s [formatter_debug] -format=(%(name)s): %(asctime)s %(levelname)s %(module)s %(funcName)s %(message)s \ No newline at end of file +format=(%(name)s): %(asctime)s %(levelname)s %(module)s %(funcName)s %(message)s diff --git a/etc/marconi.conf-sample b/etc/marconi.conf-sample index 969ed85b2..04b5b1b7b 100644 --- a/etc/marconi.conf-sample +++ b/etc/marconi.conf-sample @@ -1,7 +1,24 @@ [DEFAULT] -; debug = False -; verbose = False -; auth_strategy = +# Show more verbose log output (sets INFO log level output) +#verbose = False + +# Show debugging output in logs (sets DEBUG log level output) +#debug = False + +# Log to this file! +log_file = /var/log/marconi/server.log + +; auth_strategy = + +# ================= Syslog Options ============================ + +# Send logs to syslog (/dev/log) instead of to file specified +# by `log_file` +#use_syslog = False + +# Facility to use. If unset defaults to LOG_USER. +#syslog_log_facility = LOG_LOCAL0 + [drivers] # Transport driver module (e.g., marconi.transport.wsgi, marconi.transport.zmq) diff --git a/marconi/bootstrap.py b/marconi/bootstrap.py index dca3c1abf..164ff7f10 100644 --- a/marconi/bootstrap.py +++ b/marconi/bootstrap.py @@ -17,6 +17,7 @@ from marconi.common import config from marconi.common import decorators from marconi.common import exceptions from marconi.openstack.common import importutils +from marconi.openstack.common import log from marconi import transport # NOQA. @@ -25,6 +26,8 @@ cfg = config.namespace('drivers').from_options( transport='marconi.transport.wsgi', storage='marconi.storage.sqlite') +LOG = log.getLogger(__name__) + class Bootstrap(object): """Defines the Marconi bootstrapper. @@ -35,14 +38,19 @@ class Bootstrap(object): def __init__(self, config_file=None, cli_args=None): cfg_handle.load(filename=config_file, args=cli_args) + log.setup("marconi") @decorators.lazy_property(write=False) def storage(self): + msg = _("Loading Storage Driver") + LOG.debug(msg) storage_module = import_driver(cfg.storage) return storage_module.Driver() @decorators.lazy_property(write=False) def transport(self): + msg = _("Loading Transport Driver") + LOG.debug(msg) transport_module = import_driver(cfg.transport) return transport_module.Driver(self.storage) diff --git a/marconi/cmd/server.py b/marconi/cmd/server.py index e45d31790..9c7649952 100644 --- a/marconi/cmd/server.py +++ b/marconi/cmd/server.py @@ -16,7 +16,6 @@ import sys from marconi import bootstrap -from marconi.openstack.common import log def fail(returncode, e): @@ -26,7 +25,6 @@ def fail(returncode, e): def run(): try: - log.setup('marconi') server = bootstrap.Bootstrap(cli_args=sys.argv[1:]) server.run() except KeyboardInterrupt: diff --git a/marconi/common/config.py b/marconi/common/config.py index 56bed2360..59e4d53a7 100644 --- a/marconi/common/config.py +++ b/marconi/common/config.py @@ -71,7 +71,7 @@ def _init(): __getattr__ = dict.__getitem__ __setattr__ = dict.__setitem__ - conf = cfg.ConfigOpts() + conf = cfg.CONF def namespace(name, title=None): """Create a config namespace.