Skip to content

Commit

Permalink
switch to explicit call to logging.setup()
Browse files Browse the repository at this point in the history
  • Loading branch information
vishvananda committed Feb 21, 2011
1 parent c7d83e2 commit 29644fe
Show file tree
Hide file tree
Showing 18 changed files with 61 additions and 28 deletions.
2 changes: 1 addition & 1 deletion bin/nova-ajax-console-proxy
Expand Up @@ -25,7 +25,6 @@ from eventlet.green import urllib2

import exceptions
import gettext
import logging
import os
import sys
import time
Expand Down Expand Up @@ -130,6 +129,7 @@ class AjaxConsoleProxy(object):
if __name__ == '__main__':
utils.default_flagfile()
FLAGS(sys.argv)
logging.setup()
server = wsgi.Server()
acp = AjaxConsoleProxy()
acp.register_listeners()
Expand Down
2 changes: 1 addition & 1 deletion bin/nova-api
Expand Up @@ -40,7 +40,6 @@ from nova import version
from nova import wsgi

LOG = logging.getLogger('nova.api')
LOG.setLevel(logging.DEBUG)

FLAGS = flags.FLAGS

Expand Down Expand Up @@ -80,6 +79,7 @@ def run_app(paste_config_file):

if __name__ == '__main__':
FLAGS(sys.argv)
logging.setup()
LOG.audit(_("Starting nova-api node (version %s)"),
version.version_string_with_vcs())
conf = wsgi.paste_config_file('nova-api.conf')
Expand Down
1 change: 1 addition & 0 deletions bin/nova-combined
Expand Up @@ -49,6 +49,7 @@ FLAGS = flags.FLAGS
if __name__ == '__main__':
utils.default_flagfile()
FLAGS(sys.argv)
logging.setup()

compute = service.Service.create(binary='nova-compute')
network = service.Service.create(binary='nova-network')
Expand Down
5 changes: 5 additions & 0 deletions bin/nova-compute
Expand Up @@ -36,10 +36,15 @@ if os.path.exists(os.path.join(possible_topdir, 'nova', '__init__.py')):

gettext.install('nova', unicode=1)

from nova import flags
from nova import log as logging
from nova import service
from nova import utils

if __name__ == '__main__':
utils.default_flagfile()
flags.FLAGS(sys.argv)
logging.setup()

service.serve()
service.wait()
4 changes: 4 additions & 0 deletions bin/nova-console
Expand Up @@ -35,10 +35,14 @@ if os.path.exists(os.path.join(possible_topdir, 'nova', '__init__.py')):

gettext.install('nova', unicode=1)

from nova import flags
from nova import log as logging
from nova import service
from nova import utils

if __name__ == '__main__':
utils.default_flagfile()
flags.FLAGS(sys.argv)
logging.setup()
service.serve()
service.wait()
3 changes: 2 additions & 1 deletion bin/nova-dhcpbridge
Expand Up @@ -102,6 +102,7 @@ def main():
flagfile = os.environ.get('FLAGFILE', FLAGS.dhcpbridge_flagfile)
utils.default_flagfile(flagfile)
argv = FLAGS(sys.argv)
logging.setup()
interface = os.environ.get('DNSMASQ_INTERFACE', 'br0')
if int(os.environ.get('TESTING', '0')):
FLAGS.fake_rabbit = True
Expand All @@ -112,7 +113,7 @@ def main():
FLAGS.num_networks = 5
path = os.path.abspath(os.path.join(os.path.dirname(__file__),
'..',
'nova.sqlite'))
'tests.sqlite'))
FLAGS.sql_connection = 'sqlite:///%s' % path
action = argv[1]
if action in ['add', 'del', 'old']:
Expand Down
2 changes: 2 additions & 0 deletions bin/nova-direct-api
Expand Up @@ -35,6 +35,7 @@ if os.path.exists(os.path.join(possible_topdir, 'nova', '__init__.py')):
gettext.install('nova', unicode=1)

from nova import flags
from nova import log as logging
from nova import utils
from nova import wsgi
from nova.api import direct
Expand All @@ -48,6 +49,7 @@ flags.DEFINE_string('direct_host', '0.0.0.0', 'Direct API host')
if __name__ == '__main__':
utils.default_flagfile()
FLAGS(sys.argv)
logging.setup()

direct.register_service('compute', compute_api.API())
direct.register_service('reflect', direct.Reflection())
Expand Down
2 changes: 2 additions & 0 deletions bin/nova-import-canonical-imagestore
Expand Up @@ -41,6 +41,7 @@ if os.path.exists(os.path.join(possible_topdir, 'nova', '__init__.py')):
gettext.install('nova', unicode=1)

from nova import flags
from nova import log as logging
from nova import utils
from nova.objectstore import image

Expand Down Expand Up @@ -92,6 +93,7 @@ def main():
"""Main entry point."""
utils.default_flagfile()
argv = FLAGS(sys.argv)
logging.setup()
images = get_images()

if len(argv) == 2:
Expand Down
3 changes: 0 additions & 3 deletions bin/nova-instancemonitor
Expand Up @@ -41,9 +41,6 @@ from nova import utils
from nova import twistd
from nova.compute import monitor

# TODO(todd): shouldn't this be done with flags? And what about verbose?
logging.getLogger('boto').setLevel(logging.WARN)

LOG = logging.getLogger('nova.instancemonitor')


Expand Down
2 changes: 2 additions & 0 deletions bin/nova-manage
Expand Up @@ -77,6 +77,7 @@ from nova import crypto
from nova import db
from nova import exception
from nova import flags
from nova import log as logging
from nova import quota
from nova import rpc
from nova import utils
Expand Down Expand Up @@ -707,6 +708,7 @@ def main():
"""Parse options and call the appropriate class/method."""
utils.default_flagfile()
argv = FLAGS(sys.argv)
logging.setup()

script_name = argv.pop(0)
if len(argv) < 1:
Expand Down
4 changes: 4 additions & 0 deletions bin/nova-network
Expand Up @@ -36,10 +36,14 @@ if os.path.exists(os.path.join(possible_topdir, 'nova', '__init__.py')):

gettext.install('nova', unicode=1)

from nova import flags
from nova import log as logging
from nova import service
from nova import utils

if __name__ == '__main__':
utils.default_flagfile()
flags.FLAGS(sys.argv)
logging.setup()
service.serve()
service.wait()
4 changes: 4 additions & 0 deletions bin/nova-scheduler
Expand Up @@ -36,10 +36,14 @@ if os.path.exists(os.path.join(possible_topdir, 'nova', '__init__.py')):

gettext.install('nova', unicode=1)

from nova import flags
from nova import log as logging
from nova import service
from nova import utils

if __name__ == '__main__':
utils.default_flagfile()
flags.FLAGS(sys.argv)
logging.setup()
service.serve()
service.wait()
4 changes: 4 additions & 0 deletions bin/nova-volume
Expand Up @@ -36,10 +36,14 @@ if os.path.exists(os.path.join(possible_topdir, 'nova', '__init__.py')):

gettext.install('nova', unicode=1)

from nova import flags
from nova import log as logging
from nova import service
from nova import utils

if __name__ == '__main__':
utils.default_flagfile()
flags.FLAGS(sys.argv)
logging.setup()
service.serve()
service.wait()
44 changes: 25 additions & 19 deletions nova/log.py
Expand Up @@ -65,6 +65,7 @@
flags.DEFINE_list('default_log_levels',
['amqplib=WARN',
'sqlalchemy=WARN',
'boto=WARN',
'eventlet.wsgi.server=WARN'],
'list of logger=LEVEL pairs')

Expand Down Expand Up @@ -263,26 +264,8 @@ def setup_from_flags(self):
self.setLevel(INFO)


if not isinstance(logging.root, NovaRootLogger):
logging._acquireLock()
for handler in logging.root.handlers:
logging.root.removeHandler(handler)
logging.root = NovaRootLogger("nova")
for logger in NovaLogger.manager.loggerDict.itervalues():
logger.root = logging.root
NovaLogger.root = logging.root
NovaLogger.manager.root = logging.root
NovaLogger.manager.loggerDict["nova"] = logging.root
logging._releaseLock()
root = logging.root


def handle_exception(type, value, tb):
root.critical(str(value), exc_info=(type, value, tb))


sys.excepthook = handle_exception
logging.setLoggerClass(NovaLogger)
logging.root.critical(str(value), exc_info=(type, value, tb))


def reset():
Expand All @@ -292,6 +275,29 @@ def reset():
logger.setup_from_flags()


def setup():
"""Setup nova logging."""
if not isinstance(logging.root, NovaRootLogger):
logging._acquireLock()
for handler in logging.root.handlers:
logging.root.removeHandler(handler)
logging.root = NovaRootLogger("nova")
NovaLogger.root = logging.root
NovaLogger.manager.root = logging.root
for logger in NovaLogger.manager.loggerDict.itervalues():
logger.root = logging.root
if isinstance(logger, logging.Logger):
NovaLogger.manager._fixupParents(logger)
NovaLogger.manager.loggerDict["nova"] = logging.root
logging._releaseLock()
sys.excepthook = handle_exception
reset()


root = logging.root
logging.setLoggerClass(NovaLogger)


def audit(msg, *args, **kwargs):
"""Shortcut for logging to root log with sevrity 'AUDIT'."""
logging.root.log(AUDIT, msg, *args, **kwargs)
2 changes: 0 additions & 2 deletions nova/service.py
Expand Up @@ -214,8 +214,6 @@ def report_state(self):


def serve(*services):
FLAGS(sys.argv)

if not services:
services = [Service.create()]

Expand Down
1 change: 1 addition & 0 deletions nova/twistd.py
Expand Up @@ -148,6 +148,7 @@ def parseOptions(self, options=None):
options.insert(0, '')

args = FLAGS(options)
logging.setup()
argv = args[1:]
# ignore subcommands

Expand Down
2 changes: 1 addition & 1 deletion nova/utils.py
Expand Up @@ -55,7 +55,7 @@ def import_class(import_str):
__import__(mod_str)
return getattr(sys.modules[mod_str], class_str)
except (ImportError, ValueError, AttributeError), exc:
LOG.info(_('Inner Exception: %s'), exc)
LOG.debug(_('Inner Exception: %s'), exc)
raise exception.NotFound(_('Class %s cannot be found') % class_str)


Expand Down
2 changes: 2 additions & 0 deletions run_tests.py
Expand Up @@ -26,6 +26,7 @@
from nose import result
from nose import core

from nova import log as logging

class NovaTestResult(result.TextTestResult):
def __init__(self, *args, **kw):
Expand Down Expand Up @@ -60,6 +61,7 @@ def _makeResult(self):
if __name__ == '__main__':
if os.path.exists("tests.sqlite"):
os.unlink("tests.sqlite")
logging.setup()
c = config.Config(stream=sys.stdout,
env=os.environ,
verbosity=3,
Expand Down

0 comments on commit 29644fe

Please sign in to comment.