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
This commit is contained in:
Flaper Fesp 2013-06-13 11:32:19 +02:00
parent 2326efcd54
commit 8fa310cc7a
5 changed files with 52 additions and 42 deletions

View File

@ -1,45 +1,37 @@
; Loaded via logging.config.fileConfig
; @todo Customize for Marconi loggers
[loggers] [loggers]
keys=root keys=root,server,combined
[formatters]
keys=normal,normal_with_name,debug
[handlers] [handlers]
keys=production,file,devel keys=production,file,devel
[formatters]
keys=minimal,normal,debug
###########
# Loggers #
###########
[logger_root] [logger_root]
level=WARNING level=NOTSET
handlers=file handlers=devel
[logger_access] [logger_server]
level=INFO level=DEBUG
qualname=access handlers=devel
handlers=access_file qualname=marconi-server
[logger_combined]
################ level=DEBUG
# Log Handlers # handlers=devel
################ qualname=marconi-combined
[handler_production] [handler_production]
class=handlers.SysLogHandler class=handlers.SysLogHandler
level=ERROR level=ERROR
formatter=normal formatter=normal_with_name
args=(('localhost', handlers.SYSLOG_UDP_PORT), handlers.SysLogHandler.LOG_USER) args=(('localhost', handlers.SYSLOG_UDP_PORT), handlers.SysLogHandler.LOG_USER)
[handler_file] [handler_file]
class=handlers.WatchedFileHandler class=FileHandler
level=WARNING level=DEBUG
formatter=normal formatter=normal_with_name
args=('error.log',) args=('marconi.log', 'w')
[handler_devel] [handler_devel]
class=StreamHandler class=StreamHandler
@ -47,15 +39,10 @@ level=NOTSET
formatter=debug formatter=debug
args=(sys.stdout,) args=(sys.stdout,)
##################
# Log Formatters #
##################
[formatter_minimal]
format=%(message)s
[formatter_normal] [formatter_normal]
format=%(asctime)s %(levelname)s %(message)s
[formatter_normal_with_name]
format=(%(name)s): %(asctime)s %(levelname)s %(message)s format=(%(name)s): %(asctime)s %(levelname)s %(message)s
[formatter_debug] [formatter_debug]

View File

@ -1,8 +1,25 @@
[DEFAULT] [DEFAULT]
; debug = False # Show more verbose log output (sets INFO log level output)
; verbose = False #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 = ; 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] [drivers]
# Transport driver module (e.g., marconi.transport.wsgi, marconi.transport.zmq) # Transport driver module (e.g., marconi.transport.wsgi, marconi.transport.zmq)
transport = marconi.transport.wsgi transport = marconi.transport.wsgi

View File

@ -17,6 +17,7 @@ from marconi.common import config
from marconi.common import decorators from marconi.common import decorators
from marconi.common import exceptions from marconi.common import exceptions
from marconi.openstack.common import importutils from marconi.openstack.common import importutils
from marconi.openstack.common import log
from marconi import transport # NOQA. from marconi import transport # NOQA.
@ -25,6 +26,8 @@ cfg = config.namespace('drivers').from_options(
transport='marconi.transport.wsgi', transport='marconi.transport.wsgi',
storage='marconi.storage.sqlite') storage='marconi.storage.sqlite')
LOG = log.getLogger(__name__)
class Bootstrap(object): class Bootstrap(object):
"""Defines the Marconi bootstrapper. """Defines the Marconi bootstrapper.
@ -35,14 +38,19 @@ class Bootstrap(object):
def __init__(self, config_file=None, cli_args=None): def __init__(self, config_file=None, cli_args=None):
cfg_handle.load(filename=config_file, args=cli_args) cfg_handle.load(filename=config_file, args=cli_args)
log.setup("marconi")
@decorators.lazy_property(write=False) @decorators.lazy_property(write=False)
def storage(self): def storage(self):
msg = _("Loading Storage Driver")
LOG.debug(msg)
storage_module = import_driver(cfg.storage) storage_module = import_driver(cfg.storage)
return storage_module.Driver() return storage_module.Driver()
@decorators.lazy_property(write=False) @decorators.lazy_property(write=False)
def transport(self): def transport(self):
msg = _("Loading Transport Driver")
LOG.debug(msg)
transport_module = import_driver(cfg.transport) transport_module = import_driver(cfg.transport)
return transport_module.Driver(self.storage) return transport_module.Driver(self.storage)

View File

@ -16,7 +16,6 @@
import sys import sys
from marconi import bootstrap from marconi import bootstrap
from marconi.openstack.common import log
def fail(returncode, e): def fail(returncode, e):
@ -26,7 +25,6 @@ def fail(returncode, e):
def run(): def run():
try: try:
log.setup('marconi')
server = bootstrap.Bootstrap(cli_args=sys.argv[1:]) server = bootstrap.Bootstrap(cli_args=sys.argv[1:])
server.run() server.run()
except KeyboardInterrupt: except KeyboardInterrupt:

View File

@ -71,7 +71,7 @@ def _init():
__getattr__ = dict.__getitem__ __getattr__ = dict.__getitem__
__setattr__ = dict.__setitem__ __setattr__ = dict.__setitem__
conf = cfg.ConfigOpts() conf = cfg.CONF
def namespace(name, title=None): def namespace(name, title=None):
"""Create a config namespace. """Create a config namespace.