Switch to common logging.
I only just moved logging from nova to common, so behavior should remain the same. Change-Id: I1d7304ca200f9d024bb7244d25be2f9a670318fb
This commit is contained in:
parent
664b5767a8
commit
d9d38dd3b2
@ -41,8 +41,8 @@ if os.path.exists(os.path.join(possible_topdir, "nova", "__init__.py")):
|
|||||||
|
|
||||||
|
|
||||||
from nova import flags
|
from nova import flags
|
||||||
from nova import log as logging
|
|
||||||
from nova.objectstore import s3server
|
from nova.objectstore import s3server
|
||||||
|
from nova.openstack.common import log as logging
|
||||||
from nova import service
|
from nova import service
|
||||||
from nova import utils
|
from nova import utils
|
||||||
from nova.vnc import xvp_proxy
|
from nova.vnc import xvp_proxy
|
||||||
@ -52,7 +52,7 @@ LOG = logging.getLogger('nova.all')
|
|||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
flags.parse_args(sys.argv)
|
flags.parse_args(sys.argv)
|
||||||
logging.setup()
|
logging.setup("nova")
|
||||||
utils.monkey_patch()
|
utils.monkey_patch()
|
||||||
launcher = service.ProcessLauncher()
|
launcher = service.ProcessLauncher()
|
||||||
|
|
||||||
|
@ -37,13 +37,13 @@ if os.path.exists(os.path.join(possible_topdir, "nova", "__init__.py")):
|
|||||||
|
|
||||||
|
|
||||||
from nova import flags
|
from nova import flags
|
||||||
from nova import log as logging
|
from nova.openstack.common import log as logging
|
||||||
from nova import service
|
from nova import service
|
||||||
from nova import utils
|
from nova import utils
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
flags.parse_args(sys.argv)
|
flags.parse_args(sys.argv)
|
||||||
logging.setup()
|
logging.setup("nova")
|
||||||
utils.monkey_patch()
|
utils.monkey_patch()
|
||||||
launcher = service.ProcessLauncher()
|
launcher = service.ProcessLauncher()
|
||||||
for api in flags.FLAGS.enabled_apis:
|
for api in flags.FLAGS.enabled_apis:
|
||||||
|
@ -33,13 +33,13 @@ if os.path.exists(os.path.join(possible_topdir, "nova", "__init__.py")):
|
|||||||
|
|
||||||
|
|
||||||
from nova import flags
|
from nova import flags
|
||||||
from nova import log as logging
|
from nova.openstack.common import log as logging
|
||||||
from nova import service
|
from nova import service
|
||||||
from nova import utils
|
from nova import utils
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
flags.parse_args(sys.argv)
|
flags.parse_args(sys.argv)
|
||||||
logging.setup()
|
logging.setup("nova")
|
||||||
utils.monkey_patch()
|
utils.monkey_patch()
|
||||||
server = service.WSGIService('ec2')
|
server = service.WSGIService('ec2')
|
||||||
service.serve(server, workers=server.workers)
|
service.serve(server, workers=server.workers)
|
||||||
|
@ -33,13 +33,13 @@ if os.path.exists(os.path.join(possible_topdir, "nova", "__init__.py")):
|
|||||||
|
|
||||||
|
|
||||||
from nova import flags
|
from nova import flags
|
||||||
from nova import log as logging
|
from nova.openstack.common import log as logging
|
||||||
from nova import service
|
from nova import service
|
||||||
from nova import utils
|
from nova import utils
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
flags.parse_args(sys.argv)
|
flags.parse_args(sys.argv)
|
||||||
logging.setup()
|
logging.setup("nova")
|
||||||
utils.monkey_patch()
|
utils.monkey_patch()
|
||||||
server = service.WSGIService('metadata')
|
server = service.WSGIService('metadata')
|
||||||
service.serve(server, workers=server.workers)
|
service.serve(server, workers=server.workers)
|
||||||
|
@ -33,13 +33,13 @@ if os.path.exists(os.path.join(possible_topdir, "nova", "__init__.py")):
|
|||||||
|
|
||||||
|
|
||||||
from nova import flags
|
from nova import flags
|
||||||
from nova import log as logging
|
from nova.openstack.common import log as logging
|
||||||
from nova import service
|
from nova import service
|
||||||
from nova import utils
|
from nova import utils
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
flags.parse_args(sys.argv)
|
flags.parse_args(sys.argv)
|
||||||
logging.setup()
|
logging.setup("nova")
|
||||||
utils.monkey_patch()
|
utils.monkey_patch()
|
||||||
server = service.WSGIService('osapi_compute')
|
server = service.WSGIService('osapi_compute')
|
||||||
service.serve(server, workers=server.workers)
|
service.serve(server, workers=server.workers)
|
||||||
|
@ -33,13 +33,13 @@ if os.path.exists(os.path.join(possible_topdir, "nova", "__init__.py")):
|
|||||||
|
|
||||||
|
|
||||||
from nova import flags
|
from nova import flags
|
||||||
from nova import log as logging
|
from nova.openstack.common import log as logging
|
||||||
from nova import service
|
from nova import service
|
||||||
from nova import utils
|
from nova import utils
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
flags.parse_args(sys.argv)
|
flags.parse_args(sys.argv)
|
||||||
logging.setup()
|
logging.setup("nova")
|
||||||
utils.monkey_patch()
|
utils.monkey_patch()
|
||||||
server = service.WSGIService('osapi_volume')
|
server = service.WSGIService('osapi_volume')
|
||||||
service.serve(server, workers=server.workers)
|
service.serve(server, workers=server.workers)
|
||||||
|
@ -33,13 +33,13 @@ if os.path.exists(os.path.join(POSSIBLE_TOPDIR, 'nova', '__init__.py')):
|
|||||||
|
|
||||||
|
|
||||||
from nova import flags
|
from nova import flags
|
||||||
from nova import log as logging
|
from nova.openstack.common import log as logging
|
||||||
from nova import service
|
from nova import service
|
||||||
from nova import utils
|
from nova import utils
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
flags.parse_args(sys.argv)
|
flags.parse_args(sys.argv)
|
||||||
logging.setup()
|
logging.setup("nova")
|
||||||
utils.monkey_patch()
|
utils.monkey_patch()
|
||||||
server = service.Service.create(binary='nova-cert')
|
server = service.Service.create(binary='nova-cert')
|
||||||
service.serve(server)
|
service.serve(server)
|
||||||
|
@ -43,8 +43,8 @@ gettext.install('nova', unicode=1)
|
|||||||
from nova import context
|
from nova import context
|
||||||
from nova import exception
|
from nova import exception
|
||||||
from nova import flags
|
from nova import flags
|
||||||
from nova import log as logging
|
|
||||||
from nova.openstack.common import cfg
|
from nova.openstack.common import cfg
|
||||||
|
from nova.openstack.common import log as logging
|
||||||
from nova.openstack.common import rpc
|
from nova.openstack.common import rpc
|
||||||
|
|
||||||
|
|
||||||
@ -70,7 +70,7 @@ def delete_queues(queues):
|
|||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
args = flags.parse_args(sys.argv)
|
args = flags.parse_args(sys.argv)
|
||||||
logging.setup()
|
logging.setup("nova")
|
||||||
delete_queues(args[1:])
|
delete_queues(args[1:])
|
||||||
if FLAGS.delete_exchange:
|
if FLAGS.delete_exchange:
|
||||||
delete_exchange(FLAGS.control_exchange)
|
delete_exchange(FLAGS.control_exchange)
|
||||||
|
@ -35,13 +35,13 @@ if os.path.exists(os.path.join(POSSIBLE_TOPDIR, 'nova', '__init__.py')):
|
|||||||
|
|
||||||
|
|
||||||
from nova import flags
|
from nova import flags
|
||||||
from nova import log as logging
|
from nova.openstack.common import log as logging
|
||||||
from nova import service
|
from nova import service
|
||||||
from nova import utils
|
from nova import utils
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
flags.parse_args(sys.argv)
|
flags.parse_args(sys.argv)
|
||||||
logging.setup()
|
logging.setup('nova')
|
||||||
utils.monkey_patch()
|
utils.monkey_patch()
|
||||||
server = service.Service.create(binary='nova-compute')
|
server = service.Service.create(binary='nova-compute')
|
||||||
service.serve(server)
|
service.serve(server)
|
||||||
|
@ -34,12 +34,12 @@ if os.path.exists(os.path.join(possible_topdir, 'nova', '__init__.py')):
|
|||||||
|
|
||||||
|
|
||||||
from nova import flags
|
from nova import flags
|
||||||
from nova import log as logging
|
from nova.openstack.common import log as logging
|
||||||
from nova import service
|
from nova import service
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
flags.parse_args(sys.argv)
|
flags.parse_args(sys.argv)
|
||||||
logging.setup()
|
logging.setup("nova")
|
||||||
server = service.Service.create(binary='nova-console')
|
server = service.Service.create(binary='nova-console')
|
||||||
service.serve(server)
|
service.serve(server)
|
||||||
service.wait()
|
service.wait()
|
||||||
|
@ -33,13 +33,13 @@ if os.path.exists(os.path.join(possible_topdir, 'nova', '__init__.py')):
|
|||||||
|
|
||||||
from nova.consoleauth import manager
|
from nova.consoleauth import manager
|
||||||
from nova import flags
|
from nova import flags
|
||||||
from nova import log as logging
|
from nova.openstack.common import log as logging
|
||||||
from nova import service
|
from nova import service
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
flags.parse_args(sys.argv)
|
flags.parse_args(sys.argv)
|
||||||
logging.setup()
|
logging.setup("nova")
|
||||||
|
|
||||||
server = service.Service.create(binary='nova-consoleauth')
|
server = service.Service.create(binary='nova-consoleauth')
|
||||||
service.serve(server)
|
service.serve(server)
|
||||||
|
@ -38,9 +38,9 @@ gettext.install('nova', unicode=1)
|
|||||||
from nova import context
|
from nova import context
|
||||||
from nova import db
|
from nova import db
|
||||||
from nova import flags
|
from nova import flags
|
||||||
from nova import log as logging
|
|
||||||
from nova.network import linux_net
|
from nova.network import linux_net
|
||||||
from nova.openstack.common import importutils
|
from nova.openstack.common import importutils
|
||||||
|
from nova.openstack.common import log as logging
|
||||||
from nova.openstack.common import rpc
|
from nova.openstack.common import rpc
|
||||||
from nova import utils
|
from nova import utils
|
||||||
|
|
||||||
@ -97,7 +97,7 @@ def main():
|
|||||||
"""Parse environment and arguments and call the approproate action."""
|
"""Parse environment and arguments and call the approproate action."""
|
||||||
flagfile = os.environ.get('FLAGFILE', FLAGS.dhcpbridge_flagfile)
|
flagfile = os.environ.get('FLAGFILE', FLAGS.dhcpbridge_flagfile)
|
||||||
argv = flags.parse_args(sys.argv)
|
argv = flags.parse_args(sys.argv)
|
||||||
logging.setup()
|
logging.setup("nova")
|
||||||
|
|
||||||
if int(os.environ.get('TESTING', '0')):
|
if int(os.environ.get('TESTING', '0')):
|
||||||
from nova.tests import fake_flags
|
from nova.tests import fake_flags
|
||||||
|
@ -55,7 +55,7 @@ from nova import context
|
|||||||
from nova import db
|
from nova import db
|
||||||
from nova import exception
|
from nova import exception
|
||||||
from nova import flags
|
from nova import flags
|
||||||
from nova import log as logging
|
from nova.openstack.common import log as logging
|
||||||
from nova.openstack.common import rpc
|
from nova.openstack.common import rpc
|
||||||
from nova import utils
|
from nova import utils
|
||||||
|
|
||||||
@ -65,7 +65,7 @@ FLAGS = flags.FLAGS
|
|||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
admin_context = context.get_admin_context()
|
admin_context = context.get_admin_context()
|
||||||
flags.parse_args(sys.argv)
|
flags.parse_args(sys.argv)
|
||||||
logging.setup()
|
logging.setup("nova")
|
||||||
begin, end = utils.last_completed_audit_period()
|
begin, end = utils.last_completed_audit_period()
|
||||||
print "Starting instance usage audit"
|
print "Starting instance usage audit"
|
||||||
print "Creating usages for %s until %s" % (str(begin), str(end))
|
print "Creating usages for %s until %s" % (str(begin), str(end))
|
||||||
|
@ -86,10 +86,10 @@ from nova import db
|
|||||||
from nova.db import migration
|
from nova.db import migration
|
||||||
from nova import exception
|
from nova import exception
|
||||||
from nova import flags
|
from nova import flags
|
||||||
from nova import log as logging
|
|
||||||
from nova.openstack.common import cfg
|
from nova.openstack.common import cfg
|
||||||
from nova.openstack.common import importutils
|
from nova.openstack.common import importutils
|
||||||
from nova.openstack.common import jsonutils
|
from nova.openstack.common import jsonutils
|
||||||
|
from nova.openstack.common import log as logging
|
||||||
from nova.openstack.common import rpc
|
from nova.openstack.common import rpc
|
||||||
from nova.openstack.common import timeutils
|
from nova.openstack.common import timeutils
|
||||||
from nova import quota
|
from nova import quota
|
||||||
@ -1667,7 +1667,7 @@ def main():
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
argv = flags.parse_args(sys.argv)
|
argv = flags.parse_args(sys.argv)
|
||||||
logging.setup()
|
logging.setup("nova")
|
||||||
except cfg.ConfigFilesNotFoundError:
|
except cfg.ConfigFilesNotFoundError:
|
||||||
cfgfile = FLAGS.config_file[-1] if FLAGS.config_file else None
|
cfgfile = FLAGS.config_file[-1] if FLAGS.config_file else None
|
||||||
if cfgfile and not os.access(cfgfile, os.R_OK):
|
if cfgfile and not os.access(cfgfile, os.R_OK):
|
||||||
|
@ -35,13 +35,13 @@ if os.path.exists(os.path.join(possible_topdir, 'nova', '__init__.py')):
|
|||||||
|
|
||||||
|
|
||||||
from nova import flags
|
from nova import flags
|
||||||
from nova import log as logging
|
from nova.openstack.common import log as logging
|
||||||
from nova import service
|
from nova import service
|
||||||
from nova import utils
|
from nova import utils
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
flags.parse_args(sys.argv)
|
flags.parse_args(sys.argv)
|
||||||
logging.setup()
|
logging.setup("nova")
|
||||||
utils.monkey_patch()
|
utils.monkey_patch()
|
||||||
server = service.Service.create(binary='nova-network')
|
server = service.Service.create(binary='nova-network')
|
||||||
service.serve(server)
|
service.serve(server)
|
||||||
|
@ -35,15 +35,15 @@ if os.path.exists(os.path.join(possible_topdir, 'nova', '__init__.py')):
|
|||||||
|
|
||||||
|
|
||||||
from nova import flags
|
from nova import flags
|
||||||
from nova import log as logging
|
|
||||||
from nova.objectstore import s3server
|
from nova.objectstore import s3server
|
||||||
|
from nova.openstack.common import log as logging
|
||||||
from nova import service
|
from nova import service
|
||||||
from nova import utils
|
from nova import utils
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
flags.parse_args(sys.argv)
|
flags.parse_args(sys.argv)
|
||||||
logging.setup()
|
logging.setup("nova")
|
||||||
utils.monkey_patch()
|
utils.monkey_patch()
|
||||||
server = s3server.get_wsgi_server()
|
server = s3server.get_wsgi_server()
|
||||||
service.serve(server)
|
service.serve(server)
|
||||||
|
@ -45,7 +45,7 @@ CONF = cfg.CONF
|
|||||||
def main():
|
def main():
|
||||||
CONF.register_opts(rpc.rpc_opts)
|
CONF.register_opts(rpc.rpc_opts)
|
||||||
impl_zmq.register_opts(CONF)
|
impl_zmq.register_opts(CONF)
|
||||||
logging.setup()
|
logging.setup("nova")
|
||||||
utils.monkey_patch()
|
utils.monkey_patch()
|
||||||
|
|
||||||
ipc_dir = CONF.rpc_zmq_ipc_dir
|
ipc_dir = CONF.rpc_zmq_ipc_dir
|
||||||
|
@ -37,13 +37,13 @@ if os.path.exists(os.path.join(possible_topdir, 'nova', '__init__.py')):
|
|||||||
gettext.install('nova', unicode=1)
|
gettext.install('nova', unicode=1)
|
||||||
|
|
||||||
from nova import flags
|
from nova import flags
|
||||||
from nova import log as logging
|
from nova.openstack.common import log as logging
|
||||||
from nova import service
|
from nova import service
|
||||||
from nova import utils
|
from nova import utils
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
flags.parse_args(sys.argv)
|
flags.parse_args(sys.argv)
|
||||||
logging.setup()
|
logging.setup("nova")
|
||||||
utils.monkey_patch()
|
utils.monkey_patch()
|
||||||
server = service.Service.create(binary='nova-scheduler')
|
server = service.Service.create(binary='nova-scheduler')
|
||||||
service.serve(server)
|
service.serve(server)
|
||||||
|
@ -35,13 +35,13 @@ if os.path.exists(os.path.join(possible_topdir, 'nova', '__init__.py')):
|
|||||||
|
|
||||||
|
|
||||||
from nova import flags
|
from nova import flags
|
||||||
from nova import log as logging
|
from nova.openstack.common import log as logging
|
||||||
from nova import service
|
from nova import service
|
||||||
from nova import utils
|
from nova import utils
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
flags.parse_args(sys.argv)
|
flags.parse_args(sys.argv)
|
||||||
logging.setup()
|
logging.setup("nova")
|
||||||
utils.monkey_patch()
|
utils.monkey_patch()
|
||||||
server = service.Service.create(binary='nova-volume')
|
server = service.Service.create(binary='nova-volume')
|
||||||
service.serve(server)
|
service.serve(server)
|
||||||
|
@ -54,7 +54,7 @@ from nova import context
|
|||||||
from nova import db
|
from nova import db
|
||||||
from nova import exception
|
from nova import exception
|
||||||
from nova import flags
|
from nova import flags
|
||||||
from nova import log as logging
|
from nova.openstack.common import log as logging
|
||||||
from nova.openstack.common import rpc
|
from nova.openstack.common import rpc
|
||||||
from nova import utils
|
from nova import utils
|
||||||
from nova.volume import utils as volume_utils
|
from nova.volume import utils as volume_utils
|
||||||
@ -65,7 +65,7 @@ if __name__ == '__main__':
|
|||||||
admin_context = context.get_admin_context()
|
admin_context = context.get_admin_context()
|
||||||
utils.default_cfgfile()
|
utils.default_cfgfile()
|
||||||
flags.FLAGS(sys.argv)
|
flags.FLAGS(sys.argv)
|
||||||
logging.setup()
|
logging.setup("nova")
|
||||||
begin, end = utils.last_completed_audit_period()
|
begin, end = utils.last_completed_audit_period()
|
||||||
print "Starting volume usage audit"
|
print "Starting volume usage audit"
|
||||||
print "Creating usages for %s until %s" % (str(begin), str(end))
|
print "Creating usages for %s until %s" % (str(begin), str(end))
|
||||||
|
@ -32,7 +32,7 @@ if os.path.exists(os.path.join(possible_topdir, 'nova', '__init__.py')):
|
|||||||
|
|
||||||
|
|
||||||
from nova import flags
|
from nova import flags
|
||||||
from nova import log as logging
|
from nova.openstack.common import log as logging
|
||||||
from nova.openstack.common import rpc
|
from nova.openstack.common import rpc
|
||||||
from nova import service
|
from nova import service
|
||||||
from nova.vnc import xvp_proxy
|
from nova.vnc import xvp_proxy
|
||||||
@ -41,7 +41,7 @@ FLAGS = flags.FLAGS
|
|||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
flags.parse_args(sys.argv)
|
flags.parse_args(sys.argv)
|
||||||
logging.setup()
|
logging.setup("nova")
|
||||||
|
|
||||||
wsgi_server = xvp_proxy.get_wsgi_server()
|
wsgi_server = xvp_proxy.get_wsgi_server()
|
||||||
service.serve(wsgi_server)
|
service.serve(wsgi_server)
|
||||||
|
@ -29,8 +29,8 @@ import sys
|
|||||||
|
|
||||||
from nova import exception
|
from nova import exception
|
||||||
from nova import flags
|
from nova import flags
|
||||||
from nova import log as logging
|
|
||||||
from nova.openstack.common import cfg
|
from nova.openstack.common import cfg
|
||||||
|
from nova.openstack.common import log as logging
|
||||||
|
|
||||||
|
|
||||||
ldap_opts = [
|
ldap_opts = [
|
||||||
|
@ -34,9 +34,9 @@ from nova import crypto
|
|||||||
from nova import db
|
from nova import db
|
||||||
from nova import exception
|
from nova import exception
|
||||||
from nova import flags
|
from nova import flags
|
||||||
from nova import log as logging
|
|
||||||
from nova.openstack.common import cfg
|
from nova.openstack.common import cfg
|
||||||
from nova.openstack.common import importutils
|
from nova.openstack.common import importutils
|
||||||
|
from nova.openstack.common import log as logging
|
||||||
from nova import utils
|
from nova import utils
|
||||||
|
|
||||||
|
|
||||||
|
@ -59,7 +59,7 @@ except ImportError:
|
|||||||
boto = None
|
boto = None
|
||||||
|
|
||||||
from nova import exception
|
from nova import exception
|
||||||
from nova import log as logging
|
from nova.openstack.common import log as logging
|
||||||
|
|
||||||
|
|
||||||
LOG = logging.getLogger(__name__)
|
LOG = logging.getLogger(__name__)
|
||||||
|
@ -16,8 +16,8 @@
|
|||||||
|
|
||||||
from nova import exception
|
from nova import exception
|
||||||
from nova import flags
|
from nova import flags
|
||||||
from nova import log as logging
|
|
||||||
from nova.openstack.common import cfg
|
from nova.openstack.common import cfg
|
||||||
|
from nova.openstack.common import log as logging
|
||||||
|
|
||||||
LOG = logging.getLogger(__name__)
|
LOG = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
@ -29,8 +29,8 @@ import itertools
|
|||||||
|
|
||||||
import webob.exc
|
import webob.exc
|
||||||
|
|
||||||
from nova import log as logging
|
|
||||||
from nova.openstack.common import excutils
|
from nova.openstack.common import excutils
|
||||||
|
from nova.openstack.common import log as logging
|
||||||
|
|
||||||
LOG = logging.getLogger(__name__)
|
LOG = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
@ -73,18 +73,6 @@ def _get_my_ip():
|
|||||||
return "127.0.0.1"
|
return "127.0.0.1"
|
||||||
|
|
||||||
|
|
||||||
log_opts = [
|
|
||||||
cfg.StrOpt('logdir',
|
|
||||||
default=None,
|
|
||||||
help='Log output to a per-service log file in named directory'),
|
|
||||||
cfg.StrOpt('logfile',
|
|
||||||
default=None,
|
|
||||||
help='Log output to a named file'),
|
|
||||||
cfg.BoolOpt('use_stderr',
|
|
||||||
default=True,
|
|
||||||
help='Log output to standard error'),
|
|
||||||
]
|
|
||||||
|
|
||||||
core_opts = [
|
core_opts = [
|
||||||
cfg.StrOpt('connection_type',
|
cfg.StrOpt('connection_type',
|
||||||
default=None,
|
default=None,
|
||||||
@ -125,7 +113,6 @@ debug_opts = [
|
|||||||
help='Add python stack traces to SQL as comment strings'),
|
help='Add python stack traces to SQL as comment strings'),
|
||||||
]
|
]
|
||||||
|
|
||||||
FLAGS.register_cli_opts(log_opts)
|
|
||||||
FLAGS.register_cli_opts(core_opts)
|
FLAGS.register_cli_opts(core_opts)
|
||||||
FLAGS.register_cli_opts(debug_opts)
|
FLAGS.register_cli_opts(debug_opts)
|
||||||
|
|
||||||
@ -273,9 +260,6 @@ global_opts = [
|
|||||||
cfg.IntOpt('auth_token_ttl',
|
cfg.IntOpt('auth_token_ttl',
|
||||||
default=3600,
|
default=3600,
|
||||||
help='Seconds for auth tokens to linger'),
|
help='Seconds for auth tokens to linger'),
|
||||||
cfg.StrOpt('logfile_mode',
|
|
||||||
default='0644',
|
|
||||||
help='Default file mode used when creating log files'),
|
|
||||||
cfg.StrOpt('sqlite_db',
|
cfg.StrOpt('sqlite_db',
|
||||||
default='nova.sqlite',
|
default='nova.sqlite',
|
||||||
help='the filename to use with sqlite'),
|
help='the filename to use with sqlite'),
|
||||||
|
@ -55,7 +55,7 @@ This module provides Manager, a base class for managers.
|
|||||||
|
|
||||||
from nova.db import base
|
from nova.db import base
|
||||||
from nova import flags
|
from nova import flags
|
||||||
from nova import log as logging
|
from nova.openstack.common import log as logging
|
||||||
from nova.openstack.common.rpc import dispatcher as rpc_dispatcher
|
from nova.openstack.common.rpc import dispatcher as rpc_dispatcher
|
||||||
from nova.scheduler import rpcapi as scheduler_rpcapi
|
from nova.scheduler import rpcapi as scheduler_rpcapi
|
||||||
from nova import version
|
from nova import version
|
||||||
|
@ -23,11 +23,11 @@ import nova.context
|
|||||||
from nova import db
|
from nova import db
|
||||||
from nova import exception
|
from nova import exception
|
||||||
from nova import flags
|
from nova import flags
|
||||||
from nova import log
|
|
||||||
from nova import network
|
from nova import network
|
||||||
from nova.network import model as network_model
|
from nova.network import model as network_model
|
||||||
from nova.notifier import api as notifier_api
|
from nova.notifier import api as notifier_api
|
||||||
from nova.openstack.common import cfg
|
from nova.openstack.common import cfg
|
||||||
|
from nova.openstack.common import log
|
||||||
from nova.openstack.common import timeutils
|
from nova.openstack.common import timeutils
|
||||||
from nova import utils
|
from nova import utils
|
||||||
|
|
||||||
|
@ -17,10 +17,10 @@ import uuid
|
|||||||
|
|
||||||
from nova import exception
|
from nova import exception
|
||||||
from nova import flags
|
from nova import flags
|
||||||
from nova import log as logging
|
|
||||||
from nova.openstack.common import cfg
|
from nova.openstack.common import cfg
|
||||||
from nova.openstack.common import importutils
|
from nova.openstack.common import importutils
|
||||||
from nova.openstack.common import jsonutils
|
from nova.openstack.common import jsonutils
|
||||||
|
from nova.openstack.common import log as logging
|
||||||
from nova.openstack.common import timeutils
|
from nova.openstack.common import timeutils
|
||||||
|
|
||||||
|
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
|
|
||||||
from nova import context
|
from nova import context
|
||||||
from nova import db
|
from nova import db
|
||||||
from nova import log as logging
|
from nova.openstack.common import log as logging
|
||||||
|
|
||||||
|
|
||||||
LOG = logging.getLogger(__name__)
|
LOG = logging.getLogger(__name__)
|
||||||
|
@ -14,9 +14,9 @@
|
|||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
from nova import flags
|
from nova import flags
|
||||||
from nova import log as logging
|
|
||||||
from nova.openstack.common import cfg
|
from nova.openstack.common import cfg
|
||||||
from nova.openstack.common import importutils
|
from nova.openstack.common import importutils
|
||||||
|
from nova.openstack.common import log as logging
|
||||||
|
|
||||||
|
|
||||||
list_notifier_drivers_opt = cfg.MultiStrOpt('list_notifier_drivers',
|
list_notifier_drivers_opt = cfg.MultiStrOpt('list_notifier_drivers',
|
||||||
|
@ -14,8 +14,8 @@
|
|||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
from nova import flags
|
from nova import flags
|
||||||
from nova import log as logging
|
|
||||||
from nova.openstack.common import jsonutils
|
from nova.openstack.common import jsonutils
|
||||||
|
from nova.openstack.common import log as logging
|
||||||
|
|
||||||
|
|
||||||
FLAGS = flags.FLAGS
|
FLAGS = flags.FLAGS
|
||||||
|
@ -17,8 +17,8 @@
|
|||||||
import nova.context
|
import nova.context
|
||||||
|
|
||||||
from nova import flags
|
from nova import flags
|
||||||
from nova import log as logging
|
|
||||||
from nova.openstack.common import cfg
|
from nova.openstack.common import cfg
|
||||||
|
from nova.openstack.common import log as logging
|
||||||
from nova.openstack.common import rpc
|
from nova.openstack.common import rpc
|
||||||
|
|
||||||
LOG = logging.getLogger(__name__)
|
LOG = logging.getLogger(__name__)
|
||||||
|
@ -17,7 +17,7 @@
|
|||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
"""Nova logging handler.
|
"""Openstack logging handler.
|
||||||
|
|
||||||
This module adds to logging functionality by adding the option to specify
|
This module adds to logging functionality by adding the option to specify
|
||||||
a context object when calling the various log methods. If the context object
|
a context object when calling the various log methods. If the context object
|
||||||
@ -25,7 +25,7 @@ is not specified, default formatting is used. Additionally, an instance uuid
|
|||||||
may be passed as part of the log message, which is intended to make it easier
|
may be passed as part of the log message, which is intended to make it easier
|
||||||
for admins to find messages related to a specific instance.
|
for admins to find messages related to a specific instance.
|
||||||
|
|
||||||
It also allows setting of formatting information through flags.
|
It also allows setting of formatting information through conf.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
@ -40,12 +40,10 @@ import stat
|
|||||||
import sys
|
import sys
|
||||||
import traceback
|
import traceback
|
||||||
|
|
||||||
import nova
|
from nova import notifier
|
||||||
from nova import flags
|
|
||||||
from nova.openstack.common import cfg
|
from nova.openstack.common import cfg
|
||||||
from nova.openstack.common import jsonutils
|
from nova.openstack.common import jsonutils
|
||||||
from nova.openstack.common import local
|
from nova.openstack.common import local
|
||||||
from nova import version
|
|
||||||
|
|
||||||
|
|
||||||
log_opts = [
|
log_opts = [
|
||||||
@ -92,8 +90,26 @@ log_opts = [
|
|||||||
'format it like this'),
|
'format it like this'),
|
||||||
]
|
]
|
||||||
|
|
||||||
FLAGS = flags.FLAGS
|
|
||||||
FLAGS.register_opts(log_opts)
|
generic_log_opts = [
|
||||||
|
cfg.StrOpt('logdir',
|
||||||
|
default=None,
|
||||||
|
help='Log output to a per-service log file in named directory'),
|
||||||
|
cfg.StrOpt('logfile',
|
||||||
|
default=None,
|
||||||
|
help='Log output to a named file'),
|
||||||
|
cfg.BoolOpt('use_stderr',
|
||||||
|
default=True,
|
||||||
|
help='Log output to standard error'),
|
||||||
|
cfg.StrOpt('logfile_mode',
|
||||||
|
default='0644',
|
||||||
|
help='Default file mode used when creating log files'),
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
CONF = cfg.CONF
|
||||||
|
CONF.register_opts(generic_log_opts)
|
||||||
|
CONF.register_opts(log_opts)
|
||||||
|
|
||||||
# our new audit level
|
# our new audit level
|
||||||
# NOTE(jkoelker) Since we synthesized an audit level, make the logging
|
# NOTE(jkoelker) Since we synthesized an audit level, make the logging
|
||||||
@ -129,8 +145,8 @@ def _get_binary_name():
|
|||||||
|
|
||||||
|
|
||||||
def _get_log_file_path(binary=None):
|
def _get_log_file_path(binary=None):
|
||||||
logfile = FLAGS.log_file or FLAGS.logfile
|
logfile = CONF.log_file or CONF.logfile
|
||||||
logdir = FLAGS.log_dir or FLAGS.logdir
|
logdir = CONF.log_dir or CONF.logdir
|
||||||
|
|
||||||
if logfile and not logdir:
|
if logfile and not logdir:
|
||||||
return logfile
|
return logfile
|
||||||
@ -143,11 +159,13 @@ def _get_log_file_path(binary=None):
|
|||||||
return '%s.log' % (os.path.join(logdir, binary),)
|
return '%s.log' % (os.path.join(logdir, binary),)
|
||||||
|
|
||||||
|
|
||||||
class NovaContextAdapter(logging.LoggerAdapter):
|
class ContextAdapter(logging.LoggerAdapter):
|
||||||
warn = logging.LoggerAdapter.warning
|
warn = logging.LoggerAdapter.warning
|
||||||
|
|
||||||
def __init__(self, logger):
|
def __init__(self, logger, project_name, version_string):
|
||||||
self.logger = logger
|
self.logger = logger
|
||||||
|
self.project = project_name
|
||||||
|
self.version = version_string
|
||||||
|
|
||||||
def audit(self, msg, *args, **kwargs):
|
def audit(self, msg, *args, **kwargs):
|
||||||
self.log(logging.AUDIT, msg, *args, **kwargs)
|
self.log(logging.AUDIT, msg, *args, **kwargs)
|
||||||
@ -166,15 +184,16 @@ class NovaContextAdapter(logging.LoggerAdapter):
|
|||||||
instance = kwargs.pop('instance', None)
|
instance = kwargs.pop('instance', None)
|
||||||
instance_extra = ''
|
instance_extra = ''
|
||||||
if instance:
|
if instance:
|
||||||
instance_extra = FLAGS.instance_format % instance
|
instance_extra = CONF.instance_format % instance
|
||||||
else:
|
else:
|
||||||
instance_uuid = kwargs.pop('instance_uuid', None)
|
instance_uuid = kwargs.pop('instance_uuid', None)
|
||||||
if instance_uuid:
|
if instance_uuid:
|
||||||
instance_extra = (FLAGS.instance_uuid_format
|
instance_extra = (CONF.instance_uuid_format
|
||||||
% {'uuid': instance_uuid})
|
% {'uuid': instance_uuid})
|
||||||
extra.update({'instance': instance_extra})
|
extra.update({'instance': instance_extra})
|
||||||
|
|
||||||
extra.update({"nova_version": version.version_string_with_vcs()})
|
extra.update({"project": self.project})
|
||||||
|
extra.update({"version": self.version})
|
||||||
extra['extra'] = extra.copy()
|
extra['extra'] = extra.copy()
|
||||||
return msg, kwargs
|
return msg, kwargs
|
||||||
|
|
||||||
@ -225,8 +244,153 @@ class JSONFormatter(logging.Formatter):
|
|||||||
return jsonutils.dumps(message)
|
return jsonutils.dumps(message)
|
||||||
|
|
||||||
|
|
||||||
class LegacyNovaFormatter(logging.Formatter):
|
class PublishErrorsHandler(logging.Handler):
|
||||||
"""A nova.context.RequestContext aware formatter configured through flags.
|
def emit(self, record):
|
||||||
|
if 'list_notifier_drivers' in CONF:
|
||||||
|
if ('nova.openstack.common.notifier.log_notifier' in
|
||||||
|
CONF.list_notifier_drivers):
|
||||||
|
return
|
||||||
|
notifier.api.notify(None, 'error.publisher',
|
||||||
|
'error_notification',
|
||||||
|
notifier.api.ERROR,
|
||||||
|
dict(error=record.msg))
|
||||||
|
|
||||||
|
|
||||||
|
def handle_exception(type, value, tb):
|
||||||
|
extra = {}
|
||||||
|
if CONF.verbose:
|
||||||
|
extra['exc_info'] = (type, value, tb)
|
||||||
|
getLogger().critical(str(value), **extra)
|
||||||
|
|
||||||
|
|
||||||
|
def setup(product_name):
|
||||||
|
"""Setup logging."""
|
||||||
|
sys.excepthook = handle_exception
|
||||||
|
|
||||||
|
if CONF.log_config:
|
||||||
|
try:
|
||||||
|
logging.config.fileConfig(CONF.log_config)
|
||||||
|
except Exception:
|
||||||
|
traceback.print_exc()
|
||||||
|
raise
|
||||||
|
else:
|
||||||
|
_setup_logging_from_conf(product_name)
|
||||||
|
|
||||||
|
|
||||||
|
def _find_facility_from_conf():
|
||||||
|
facility_names = logging.handlers.SysLogHandler.facility_names
|
||||||
|
facility = getattr(logging.handlers.SysLogHandler,
|
||||||
|
CONF.syslog_log_facility,
|
||||||
|
None)
|
||||||
|
|
||||||
|
if facility is None and CONF.syslog_log_facility in facility_names:
|
||||||
|
facility = facility_names.get(CONF.syslog_log_facility)
|
||||||
|
|
||||||
|
if facility is None:
|
||||||
|
valid_facilities = facility_names.keys()
|
||||||
|
consts = ['LOG_AUTH', 'LOG_AUTHPRIV', 'LOG_CRON', 'LOG_DAEMON',
|
||||||
|
'LOG_FTP', 'LOG_KERN', 'LOG_LPR', 'LOG_MAIL', 'LOG_NEWS',
|
||||||
|
'LOG_AUTH', 'LOG_SYSLOG', 'LOG_USER', 'LOG_UUCP',
|
||||||
|
'LOG_LOCAL0', 'LOG_LOCAL1', 'LOG_LOCAL2', 'LOG_LOCAL3',
|
||||||
|
'LOG_LOCAL4', 'LOG_LOCAL5', 'LOG_LOCAL6', 'LOG_LOCAL7']
|
||||||
|
valid_facilities.extend(consts)
|
||||||
|
raise TypeError(_('syslog facility must be one of: %s') %
|
||||||
|
', '.join("'%s'" % fac
|
||||||
|
for fac in valid_facilities))
|
||||||
|
|
||||||
|
return facility
|
||||||
|
|
||||||
|
|
||||||
|
def _setup_logging_from_conf(product_name):
|
||||||
|
log_root = getLogger(product_name).logger
|
||||||
|
for handler in log_root.handlers:
|
||||||
|
log_root.removeHandler(handler)
|
||||||
|
|
||||||
|
if CONF.use_syslog:
|
||||||
|
facility = _find_facility_from_conf()
|
||||||
|
syslog = logging.handlers.SysLogHandler(address='/dev/log',
|
||||||
|
facility=facility)
|
||||||
|
log_root.addHandler(syslog)
|
||||||
|
|
||||||
|
logpath = _get_log_file_path()
|
||||||
|
if logpath:
|
||||||
|
filelog = logging.handlers.WatchedFileHandler(logpath)
|
||||||
|
log_root.addHandler(filelog)
|
||||||
|
|
||||||
|
mode = int(CONF.logfile_mode, 8)
|
||||||
|
st = os.stat(logpath)
|
||||||
|
if st.st_mode != (stat.S_IFREG | mode):
|
||||||
|
os.chmod(logpath, mode)
|
||||||
|
|
||||||
|
if CONF.use_stderr:
|
||||||
|
streamlog = ColorHandler()
|
||||||
|
log_root.addHandler(streamlog)
|
||||||
|
|
||||||
|
elif not CONF.log_file:
|
||||||
|
# pass sys.stdout as a positional argument
|
||||||
|
# python2.6 calls the argument strm, in 2.7 it's stream
|
||||||
|
streamlog = logging.StreamHandler(sys.stdout)
|
||||||
|
log_root.addHandler(streamlog)
|
||||||
|
|
||||||
|
if CONF.publish_errors:
|
||||||
|
log_root.addHandler(PublishErrorsHandler(logging.ERROR))
|
||||||
|
|
||||||
|
for handler in log_root.handlers:
|
||||||
|
datefmt = CONF.log_date_format
|
||||||
|
if CONF.log_format:
|
||||||
|
handler.setFormatter(logging.Formatter(fmt=CONF.log_format,
|
||||||
|
datefmt=datefmt))
|
||||||
|
handler.setFormatter(LegacyFormatter(datefmt=datefmt))
|
||||||
|
|
||||||
|
if CONF.verbose or CONF.debug:
|
||||||
|
log_root.setLevel(logging.DEBUG)
|
||||||
|
else:
|
||||||
|
log_root.setLevel(logging.INFO)
|
||||||
|
|
||||||
|
level = logging.NOTSET
|
||||||
|
for pair in CONF.default_log_levels:
|
||||||
|
mod, _sep, level_name = pair.partition('=')
|
||||||
|
level = logging.getLevelName(level_name)
|
||||||
|
logger = logging.getLogger(mod)
|
||||||
|
logger.setLevel(level)
|
||||||
|
for handler in log_root.handlers:
|
||||||
|
logger.addHandler(handler)
|
||||||
|
|
||||||
|
# NOTE(jkoelker) Clear the handlers for the root logger that was setup
|
||||||
|
# by basicConfig in nova/__init__.py and install the
|
||||||
|
# NullHandler.
|
||||||
|
root = logging.getLogger()
|
||||||
|
for handler in root.handlers:
|
||||||
|
root.removeHandler(handler)
|
||||||
|
handler = NullHandler()
|
||||||
|
handler.setFormatter(logging.Formatter())
|
||||||
|
root.addHandler(handler)
|
||||||
|
|
||||||
|
|
||||||
|
_loggers = {}
|
||||||
|
|
||||||
|
|
||||||
|
def getLogger(name='unknown', version='unknown'):
|
||||||
|
if name not in _loggers:
|
||||||
|
_loggers[name] = ContextAdapter(logging.getLogger(name),
|
||||||
|
name,
|
||||||
|
version)
|
||||||
|
return _loggers[name]
|
||||||
|
|
||||||
|
|
||||||
|
class WritableLogger(object):
|
||||||
|
"""A thin wrapper that responds to `write` and logs."""
|
||||||
|
|
||||||
|
def __init__(self, logger, level=logging.INFO):
|
||||||
|
self.logger = logger
|
||||||
|
self.level = level
|
||||||
|
|
||||||
|
def write(self, msg):
|
||||||
|
self.logger.log(self.level, msg)
|
||||||
|
|
||||||
|
|
||||||
|
class LegacyFormatter(logging.Formatter):
|
||||||
|
"""A context.RequestContext aware formatter configured through flags.
|
||||||
|
|
||||||
The flags used to set format strings are: logging_context_format_string
|
The flags used to set format strings are: logging_context_format_string
|
||||||
and logging_default_format_string. You can also specify
|
and logging_default_format_string. You can also specify
|
||||||
@ -244,13 +408,13 @@ class LegacyNovaFormatter(logging.Formatter):
|
|||||||
record.__dict__['instance'] = ''
|
record.__dict__['instance'] = ''
|
||||||
|
|
||||||
if record.__dict__.get('request_id', None):
|
if record.__dict__.get('request_id', None):
|
||||||
self._fmt = FLAGS.logging_context_format_string
|
self._fmt = CONF.logging_context_format_string
|
||||||
else:
|
else:
|
||||||
self._fmt = FLAGS.logging_default_format_string
|
self._fmt = CONF.logging_default_format_string
|
||||||
|
|
||||||
if (record.levelno == logging.DEBUG and
|
if (record.levelno == logging.DEBUG and
|
||||||
FLAGS.logging_debug_format_suffix):
|
CONF.logging_debug_format_suffix):
|
||||||
self._fmt += " " + FLAGS.logging_debug_format_suffix
|
self._fmt += " " + CONF.logging_debug_format_suffix
|
||||||
|
|
||||||
# Cache this on the record, Logger will respect our formated copy
|
# Cache this on the record, Logger will respect our formated copy
|
||||||
if record.exc_info:
|
if record.exc_info:
|
||||||
@ -258,7 +422,7 @@ class LegacyNovaFormatter(logging.Formatter):
|
|||||||
return logging.Formatter.format(self, record)
|
return logging.Formatter.format(self, record)
|
||||||
|
|
||||||
def formatException(self, exc_info, record=None):
|
def formatException(self, exc_info, record=None):
|
||||||
"""Format exception output with FLAGS.logging_exception_prefix."""
|
"""Format exception output with CONF.logging_exception_prefix."""
|
||||||
if not record:
|
if not record:
|
||||||
return logging.Formatter.formatException(self, exc_info)
|
return logging.Formatter.formatException(self, exc_info)
|
||||||
|
|
||||||
@ -268,18 +432,18 @@ class LegacyNovaFormatter(logging.Formatter):
|
|||||||
lines = stringbuffer.getvalue().split('\n')
|
lines = stringbuffer.getvalue().split('\n')
|
||||||
stringbuffer.close()
|
stringbuffer.close()
|
||||||
|
|
||||||
if FLAGS.logging_exception_prefix.find('%(asctime)') != -1:
|
if CONF.logging_exception_prefix.find('%(asctime)') != -1:
|
||||||
record.asctime = self.formatTime(record, self.datefmt)
|
record.asctime = self.formatTime(record, self.datefmt)
|
||||||
|
|
||||||
formatted_lines = []
|
formatted_lines = []
|
||||||
for line in lines:
|
for line in lines:
|
||||||
pl = FLAGS.logging_exception_prefix % record.__dict__
|
pl = CONF.logging_exception_prefix % record.__dict__
|
||||||
fl = '%s%s' % (pl, line)
|
fl = '%s%s' % (pl, line)
|
||||||
formatted_lines.append(fl)
|
formatted_lines.append(fl)
|
||||||
return '\n'.join(formatted_lines)
|
return '\n'.join(formatted_lines)
|
||||||
|
|
||||||
|
|
||||||
class NovaColorHandler(logging.StreamHandler):
|
class ColorHandler(logging.StreamHandler):
|
||||||
LEVEL_COLORS = {
|
LEVEL_COLORS = {
|
||||||
logging.DEBUG: '\033[00;32m', # GREEN
|
logging.DEBUG: '\033[00;32m', # GREEN
|
||||||
logging.INFO: '\033[00;36m', # CYAN
|
logging.INFO: '\033[00;36m', # CYAN
|
||||||
@ -292,145 +456,3 @@ class NovaColorHandler(logging.StreamHandler):
|
|||||||
def format(self, record):
|
def format(self, record):
|
||||||
record.color = self.LEVEL_COLORS[record.levelno]
|
record.color = self.LEVEL_COLORS[record.levelno]
|
||||||
return logging.StreamHandler.format(self, record)
|
return logging.StreamHandler.format(self, record)
|
||||||
|
|
||||||
|
|
||||||
class PublishErrorsHandler(logging.Handler):
|
|
||||||
def emit(self, record):
|
|
||||||
if 'list_notifier_drivers' in FLAGS:
|
|
||||||
if 'nova.notifier.log_notifier' in FLAGS.list_notifier_drivers:
|
|
||||||
return
|
|
||||||
nova.notifier.api.notify(None, 'nova.error.publisher',
|
|
||||||
'error_notification',
|
|
||||||
nova.notifier.api.ERROR,
|
|
||||||
dict(error=record.msg))
|
|
||||||
|
|
||||||
|
|
||||||
def handle_exception(type, value, tb):
|
|
||||||
extra = {}
|
|
||||||
if FLAGS.verbose:
|
|
||||||
extra['exc_info'] = (type, value, tb)
|
|
||||||
getLogger().critical(str(value), **extra)
|
|
||||||
|
|
||||||
|
|
||||||
def setup():
|
|
||||||
"""Setup nova logging."""
|
|
||||||
sys.excepthook = handle_exception
|
|
||||||
|
|
||||||
if FLAGS.log_config:
|
|
||||||
try:
|
|
||||||
logging.config.fileConfig(FLAGS.log_config)
|
|
||||||
except Exception:
|
|
||||||
traceback.print_exc()
|
|
||||||
raise
|
|
||||||
else:
|
|
||||||
_setup_logging_from_flags()
|
|
||||||
|
|
||||||
|
|
||||||
def _find_facility_from_flags():
|
|
||||||
facility_names = logging.handlers.SysLogHandler.facility_names
|
|
||||||
facility = getattr(logging.handlers.SysLogHandler,
|
|
||||||
FLAGS.syslog_log_facility,
|
|
||||||
None)
|
|
||||||
|
|
||||||
if facility is None and FLAGS.syslog_log_facility in facility_names:
|
|
||||||
facility = facility_names.get(FLAGS.syslog_log_facility)
|
|
||||||
|
|
||||||
if facility is None:
|
|
||||||
valid_facilities = facility_names.keys()
|
|
||||||
consts = ['LOG_AUTH', 'LOG_AUTHPRIV', 'LOG_CRON', 'LOG_DAEMON',
|
|
||||||
'LOG_FTP', 'LOG_KERN', 'LOG_LPR', 'LOG_MAIL', 'LOG_NEWS',
|
|
||||||
'LOG_AUTH', 'LOG_SYSLOG', 'LOG_USER', 'LOG_UUCP',
|
|
||||||
'LOG_LOCAL0', 'LOG_LOCAL1', 'LOG_LOCAL2', 'LOG_LOCAL3',
|
|
||||||
'LOG_LOCAL4', 'LOG_LOCAL5', 'LOG_LOCAL6', 'LOG_LOCAL7']
|
|
||||||
valid_facilities.extend(consts)
|
|
||||||
raise TypeError(_('syslog facility must be one of: %s') %
|
|
||||||
', '.join("'%s'" % fac
|
|
||||||
for fac in valid_facilities))
|
|
||||||
|
|
||||||
return facility
|
|
||||||
|
|
||||||
|
|
||||||
def _setup_logging_from_flags():
|
|
||||||
nova_root = getLogger().logger
|
|
||||||
for handler in nova_root.handlers:
|
|
||||||
nova_root.removeHandler(handler)
|
|
||||||
|
|
||||||
if FLAGS.use_syslog:
|
|
||||||
facility = _find_facility_from_flags()
|
|
||||||
syslog = logging.handlers.SysLogHandler(address='/dev/log',
|
|
||||||
facility=facility)
|
|
||||||
nova_root.addHandler(syslog)
|
|
||||||
|
|
||||||
logpath = _get_log_file_path()
|
|
||||||
if logpath:
|
|
||||||
filelog = logging.handlers.WatchedFileHandler(logpath)
|
|
||||||
nova_root.addHandler(filelog)
|
|
||||||
|
|
||||||
mode = int(FLAGS.logfile_mode, 8)
|
|
||||||
st = os.stat(logpath)
|
|
||||||
if st.st_mode != (stat.S_IFREG | mode):
|
|
||||||
os.chmod(logpath, mode)
|
|
||||||
|
|
||||||
if FLAGS.use_stderr:
|
|
||||||
streamlog = NovaColorHandler()
|
|
||||||
nova_root.addHandler(streamlog)
|
|
||||||
|
|
||||||
elif not FLAGS.log_file:
|
|
||||||
# pass sys.stdout as a positional argument
|
|
||||||
# python2.6 calls the argument strm, in 2.7 it's stream
|
|
||||||
streamlog = logging.StreamHandler(sys.stdout)
|
|
||||||
nova_root.addHandler(streamlog)
|
|
||||||
|
|
||||||
if FLAGS.publish_errors:
|
|
||||||
nova_root.addHandler(PublishErrorsHandler(logging.ERROR))
|
|
||||||
|
|
||||||
for handler in nova_root.handlers:
|
|
||||||
datefmt = FLAGS.log_date_format
|
|
||||||
if FLAGS.log_format:
|
|
||||||
handler.setFormatter(logging.Formatter(fmt=FLAGS.log_format,
|
|
||||||
datefmt=datefmt))
|
|
||||||
handler.setFormatter(LegacyNovaFormatter(datefmt=datefmt))
|
|
||||||
|
|
||||||
if FLAGS.verbose or FLAGS.debug:
|
|
||||||
nova_root.setLevel(logging.DEBUG)
|
|
||||||
else:
|
|
||||||
nova_root.setLevel(logging.INFO)
|
|
||||||
|
|
||||||
level = logging.NOTSET
|
|
||||||
for pair in FLAGS.default_log_levels:
|
|
||||||
mod, _sep, level_name = pair.partition('=')
|
|
||||||
level = logging.getLevelName(level_name)
|
|
||||||
logger = logging.getLogger(mod)
|
|
||||||
logger.setLevel(level)
|
|
||||||
for handler in nova_root.handlers:
|
|
||||||
logger.addHandler(handler)
|
|
||||||
|
|
||||||
# NOTE(jkoelker) Clear the handlers for the root logger that was setup
|
|
||||||
# by basicConfig in nova/__init__.py and install the
|
|
||||||
# NullHandler.
|
|
||||||
root = logging.getLogger()
|
|
||||||
for handler in root.handlers:
|
|
||||||
root.removeHandler(handler)
|
|
||||||
handler = NullHandler()
|
|
||||||
handler.setFormatter(logging.Formatter())
|
|
||||||
root.addHandler(handler)
|
|
||||||
|
|
||||||
|
|
||||||
_loggers = {}
|
|
||||||
|
|
||||||
|
|
||||||
def getLogger(name='nova'):
|
|
||||||
if name not in _loggers:
|
|
||||||
_loggers[name] = NovaContextAdapter(logging.getLogger(name))
|
|
||||||
return _loggers[name]
|
|
||||||
|
|
||||||
|
|
||||||
class WritableLogger(object):
|
|
||||||
"""A thin wrapper that responds to `write` and logs."""
|
|
||||||
|
|
||||||
def __init__(self, logger, level=logging.INFO):
|
|
||||||
self.logger = logger
|
|
||||||
self.level = level
|
|
||||||
|
|
||||||
def write(self, msg):
|
|
||||||
self.logger.log(self.level, msg)
|
|
@ -47,7 +47,7 @@ zmq_opts = [
|
|||||||
|
|
||||||
# The module.Class to use for matchmaking.
|
# The module.Class to use for matchmaking.
|
||||||
cfg.StrOpt('rpc_zmq_matchmaker',
|
cfg.StrOpt('rpc_zmq_matchmaker',
|
||||||
default='openstack.common.rpc.matchmaker.MatchMakerLocalhost',
|
default='nova.openstack.common.rpc.matchmaker.MatchMakerLocalhost',
|
||||||
help='MatchMaker driver'),
|
help='MatchMaker driver'),
|
||||||
|
|
||||||
# The following port is unassigned by IANA as of 2012-05-21
|
# The following port is unassigned by IANA as of 2012-05-21
|
||||||
|
@ -23,9 +23,9 @@ import datetime
|
|||||||
from nova import db
|
from nova import db
|
||||||
from nova import exception
|
from nova import exception
|
||||||
from nova import flags
|
from nova import flags
|
||||||
from nova import log as logging
|
|
||||||
from nova.openstack.common import cfg
|
from nova.openstack.common import cfg
|
||||||
from nova.openstack.common import importutils
|
from nova.openstack.common import importutils
|
||||||
|
from nova.openstack.common import log as logging
|
||||||
from nova.openstack.common import timeutils
|
from nova.openstack.common import timeutils
|
||||||
|
|
||||||
|
|
||||||
|
@ -28,11 +28,11 @@ from nova.compute import task_states
|
|||||||
from nova import db
|
from nova import db
|
||||||
from nova import exception
|
from nova import exception
|
||||||
from nova import flags
|
from nova import flags
|
||||||
from nova import log as logging
|
|
||||||
from nova import notifications
|
from nova import notifications
|
||||||
from nova.openstack.common import cfg
|
from nova.openstack.common import cfg
|
||||||
from nova.openstack.common import importutils
|
from nova.openstack.common import importutils
|
||||||
from nova.openstack.common import jsonutils
|
from nova.openstack.common import jsonutils
|
||||||
|
from nova.openstack.common import log as logging
|
||||||
from nova.openstack.common import rpc
|
from nova.openstack.common import rpc
|
||||||
from nova.openstack.common import timeutils
|
from nova.openstack.common import timeutils
|
||||||
from nova import utils
|
from nova import utils
|
||||||
|
@ -23,9 +23,9 @@ import operator
|
|||||||
|
|
||||||
from nova import exception
|
from nova import exception
|
||||||
from nova import flags
|
from nova import flags
|
||||||
from nova import log as logging
|
|
||||||
from nova.notifier import api as notifier
|
from nova.notifier import api as notifier
|
||||||
from nova.openstack.common import importutils
|
from nova.openstack.common import importutils
|
||||||
|
from nova.openstack.common import log as logging
|
||||||
from nova.scheduler import driver
|
from nova.scheduler import driver
|
||||||
from nova.scheduler import least_cost
|
from nova.scheduler import least_cost
|
||||||
from nova.scheduler import scheduler_options
|
from nova.scheduler import scheduler_options
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
|
|
||||||
from nova import log as logging
|
from nova.openstack.common import log as logging
|
||||||
from nova.scheduler import filters
|
from nova.scheduler import filters
|
||||||
from nova import utils
|
from nova import utils
|
||||||
|
|
||||||
|
@ -13,7 +13,7 @@
|
|||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
from nova import log as logging
|
from nova.openstack.common import log as logging
|
||||||
from nova.scheduler import filters
|
from nova.scheduler import filters
|
||||||
from nova import utils
|
from nova import utils
|
||||||
|
|
||||||
|
@ -16,8 +16,8 @@
|
|||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
from nova import flags
|
from nova import flags
|
||||||
from nova import log as logging
|
|
||||||
from nova.openstack.common import cfg
|
from nova.openstack.common import cfg
|
||||||
|
from nova.openstack.common import log as logging
|
||||||
from nova.scheduler import filters
|
from nova.scheduler import filters
|
||||||
|
|
||||||
|
|
||||||
|
@ -15,8 +15,8 @@
|
|||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
from nova import flags
|
from nova import flags
|
||||||
from nova import log as logging
|
|
||||||
from nova.openstack.common import cfg
|
from nova.openstack.common import cfg
|
||||||
|
from nova.openstack.common import log as logging
|
||||||
from nova.scheduler import filters
|
from nova.scheduler import filters
|
||||||
|
|
||||||
LOG = logging.getLogger(__name__)
|
LOG = logging.getLogger(__name__)
|
||||||
|
@ -49,9 +49,9 @@ import socket
|
|||||||
import ssl
|
import ssl
|
||||||
|
|
||||||
from nova import flags
|
from nova import flags
|
||||||
from nova import log as logging
|
|
||||||
from nova.openstack.common import cfg
|
from nova.openstack.common import cfg
|
||||||
from nova.openstack.common import jsonutils
|
from nova.openstack.common import jsonutils
|
||||||
|
from nova.openstack.common import log as logging
|
||||||
from nova.scheduler import filters
|
from nova.scheduler import filters
|
||||||
|
|
||||||
|
|
||||||
|
@ -23,8 +23,8 @@ import UserDict
|
|||||||
from nova import db
|
from nova import db
|
||||||
from nova import exception
|
from nova import exception
|
||||||
from nova import flags
|
from nova import flags
|
||||||
from nova import log as logging
|
|
||||||
from nova.openstack.common import cfg
|
from nova.openstack.common import cfg
|
||||||
|
from nova.openstack.common import log as logging
|
||||||
from nova.openstack.common import timeutils
|
from nova.openstack.common import timeutils
|
||||||
from nova.scheduler import filters
|
from nova.scheduler import filters
|
||||||
|
|
||||||
|
@ -23,8 +23,8 @@ is then selected for provisioning.
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
from nova import flags
|
from nova import flags
|
||||||
from nova import log as logging
|
|
||||||
from nova.openstack.common import cfg
|
from nova.openstack.common import cfg
|
||||||
|
from nova.openstack.common import log as logging
|
||||||
|
|
||||||
|
|
||||||
LOG = logging.getLogger(__name__)
|
LOG = logging.getLogger(__name__)
|
||||||
|
@ -27,13 +27,13 @@ from nova.compute import vm_states
|
|||||||
from nova import db
|
from nova import db
|
||||||
from nova import exception
|
from nova import exception
|
||||||
from nova import flags
|
from nova import flags
|
||||||
from nova import log as logging
|
|
||||||
from nova import manager
|
from nova import manager
|
||||||
from nova import notifications
|
from nova import notifications
|
||||||
from nova.notifier import api as notifier
|
from nova.notifier import api as notifier
|
||||||
from nova.openstack.common import cfg
|
from nova.openstack.common import cfg
|
||||||
from nova.openstack.common import excutils
|
from nova.openstack.common import excutils
|
||||||
from nova.openstack.common import importutils
|
from nova.openstack.common import importutils
|
||||||
|
from nova.openstack.common import log as logging
|
||||||
from nova import quota
|
from nova import quota
|
||||||
|
|
||||||
|
|
||||||
|
@ -27,8 +27,8 @@ import json
|
|||||||
import os
|
import os
|
||||||
|
|
||||||
from nova import flags
|
from nova import flags
|
||||||
from nova import log as logging
|
|
||||||
from nova.openstack.common import cfg
|
from nova.openstack.common import cfg
|
||||||
|
from nova.openstack.common import log as logging
|
||||||
from nova.openstack.common import timeutils
|
from nova.openstack.common import timeutils
|
||||||
|
|
||||||
|
|
||||||
|
@ -35,9 +35,9 @@ from nova import context
|
|||||||
from nova import db
|
from nova import db
|
||||||
from nova import exception
|
from nova import exception
|
||||||
from nova import flags
|
from nova import flags
|
||||||
from nova import log as logging
|
|
||||||
from nova.openstack.common import cfg
|
from nova.openstack.common import cfg
|
||||||
from nova.openstack.common import importutils
|
from nova.openstack.common import importutils
|
||||||
|
from nova.openstack.common import log as logging
|
||||||
from nova.openstack.common import rpc
|
from nova.openstack.common import rpc
|
||||||
from nova import utils
|
from nova import utils
|
||||||
from nova import version
|
from nova import version
|
||||||
|
@ -32,8 +32,8 @@ import nose.plugins.skip
|
|||||||
import stubout
|
import stubout
|
||||||
|
|
||||||
from nova import flags
|
from nova import flags
|
||||||
from nova import log as logging
|
|
||||||
from nova.openstack.common import cfg
|
from nova.openstack.common import cfg
|
||||||
|
from nova.openstack.common import log as logging
|
||||||
from nova.openstack.common import timeutils
|
from nova.openstack.common import timeutils
|
||||||
from nova import service
|
from nova import service
|
||||||
from nova import tests
|
from nova import tests
|
||||||
|
@ -39,7 +39,7 @@ import shutil
|
|||||||
|
|
||||||
from nova.db.sqlalchemy.session import get_engine
|
from nova.db.sqlalchemy.session import get_engine
|
||||||
from nova import flags
|
from nova import flags
|
||||||
from nova import log as logging
|
from nova.openstack.common import log as logging
|
||||||
|
|
||||||
import eventlet
|
import eventlet
|
||||||
|
|
||||||
@ -49,7 +49,7 @@ eventlet.monkey_patch(os=False)
|
|||||||
FLAGS = flags.FLAGS
|
FLAGS = flags.FLAGS
|
||||||
FLAGS.use_stderr = False
|
FLAGS.use_stderr = False
|
||||||
|
|
||||||
logging.setup()
|
logging.setup('nova')
|
||||||
|
|
||||||
_DB = None
|
_DB = None
|
||||||
|
|
||||||
|
@ -14,11 +14,11 @@
|
|||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
import nova
|
import nova
|
||||||
from nova import log as logging
|
|
||||||
import nova.notifier.api
|
import nova.notifier.api
|
||||||
from nova.notifier import list_notifier
|
from nova.notifier import list_notifier
|
||||||
import nova.notifier.log_notifier
|
import nova.notifier.log_notifier
|
||||||
import nova.notifier.no_op_notifier
|
import nova.notifier.no_op_notifier
|
||||||
|
from nova.openstack.common import log as logging
|
||||||
from nova import test
|
from nova import test
|
||||||
|
|
||||||
|
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
from nova import exception
|
from nova import exception
|
||||||
from nova import log as logging
|
from nova.openstack.common import log as logging
|
||||||
from nova import test
|
from nova import test
|
||||||
from nova.volume import san
|
from nova.volume import san
|
||||||
|
|
||||||
|
@ -22,7 +22,7 @@ from nova.auth import fakeldap
|
|||||||
from nova.auth import manager
|
from nova.auth import manager
|
||||||
from nova import exception
|
from nova import exception
|
||||||
from nova import flags
|
from nova import flags
|
||||||
from nova import log as logging
|
from nova.openstack.common import log as logging
|
||||||
from nova import test
|
from nova import test
|
||||||
|
|
||||||
FLAGS = flags.FLAGS
|
FLAGS = flags.FLAGS
|
||||||
|
@ -22,9 +22,9 @@ from nova.compute import utils as compute_utils
|
|||||||
from nova import context
|
from nova import context
|
||||||
from nova import db
|
from nova import db
|
||||||
from nova import flags
|
from nova import flags
|
||||||
from nova import log as logging
|
|
||||||
from nova.notifier import test_notifier
|
from nova.notifier import test_notifier
|
||||||
from nova.openstack.common import importutils
|
from nova.openstack.common import importutils
|
||||||
|
from nova.openstack.common import log as logging
|
||||||
from nova import test
|
from nova import test
|
||||||
from nova.tests import fake_network
|
from nova.tests import fake_network
|
||||||
import nova.tests.image.fake
|
import nova.tests.image.fake
|
||||||
|
@ -29,7 +29,7 @@ from nova import test
|
|||||||
from nova.compute import vm_states
|
from nova.compute import vm_states
|
||||||
from nova import db
|
from nova import db
|
||||||
from nova import flags
|
from nova import flags
|
||||||
from nova import log
|
from nova.openstack.common import log
|
||||||
from nova import utils
|
from nova import utils
|
||||||
from nova.virt.libvirt import imagecache
|
from nova.virt.libvirt import imagecache
|
||||||
from nova.virt.libvirt import utils as virtutils
|
from nova.virt.libvirt import utils as virtutils
|
||||||
@ -335,10 +335,10 @@ class ImageCacheManagerTestCase(test.TestCase):
|
|||||||
@contextlib.contextmanager
|
@contextlib.contextmanager
|
||||||
def _intercept_log_messages(self):
|
def _intercept_log_messages(self):
|
||||||
try:
|
try:
|
||||||
mylog = log.getLogger()
|
mylog = log.getLogger('nova')
|
||||||
stream = cStringIO.StringIO()
|
stream = cStringIO.StringIO()
|
||||||
handler = logging.StreamHandler(stream)
|
handler = logging.StreamHandler(stream)
|
||||||
handler.setFormatter(log.LegacyNovaFormatter())
|
handler.setFormatter(log.LegacyFormatter())
|
||||||
mylog.logger.addHandler(handler)
|
mylog.logger.addHandler(handler)
|
||||||
yield stream
|
yield stream
|
||||||
finally:
|
finally:
|
||||||
|
@ -24,7 +24,7 @@ from nova.db.sqlalchemy import models
|
|||||||
from nova.db.sqlalchemy import session as sql_session
|
from nova.db.sqlalchemy import session as sql_session
|
||||||
from nova import exception
|
from nova import exception
|
||||||
from nova import flags
|
from nova import flags
|
||||||
from nova import log as logging
|
from nova.openstack.common import log as logging
|
||||||
from nova import test
|
from nova import test
|
||||||
|
|
||||||
FLAGS = flags.FLAGS
|
FLAGS = flags.FLAGS
|
||||||
|
@ -34,9 +34,9 @@ from nova import context
|
|||||||
from nova import db
|
from nova import db
|
||||||
from nova import exception
|
from nova import exception
|
||||||
from nova import flags
|
from nova import flags
|
||||||
from nova import log as logging
|
|
||||||
from nova.openstack.common import importutils
|
from nova.openstack.common import importutils
|
||||||
from nova.openstack.common import jsonutils
|
from nova.openstack.common import jsonutils
|
||||||
|
from nova.openstack.common import log as logging
|
||||||
from nova import test
|
from nova import test
|
||||||
from nova.tests import fake_libvirt_utils
|
from nova.tests import fake_libvirt_utils
|
||||||
from nova.tests import fake_network
|
from nova.tests import fake_network
|
||||||
|
@ -1,217 +0,0 @@
|
|||||||
import cStringIO
|
|
||||||
import logging
|
|
||||||
|
|
||||||
from nova import context
|
|
||||||
from nova import flags
|
|
||||||
from nova import log
|
|
||||||
from nova.notifier import api as notifier
|
|
||||||
from nova.openstack.common import jsonutils
|
|
||||||
from nova import test
|
|
||||||
|
|
||||||
FLAGS = flags.FLAGS
|
|
||||||
flags.DECLARE('list_notifier_drivers',
|
|
||||||
'nova.notifier.list_notifier')
|
|
||||||
|
|
||||||
|
|
||||||
def _fake_context():
|
|
||||||
return context.RequestContext(1, 1)
|
|
||||||
|
|
||||||
|
|
||||||
class LoggerTestCase(test.TestCase):
|
|
||||||
def setUp(self):
|
|
||||||
super(LoggerTestCase, self).setUp()
|
|
||||||
self.log = log.getLogger()
|
|
||||||
|
|
||||||
def test_handlers_have_nova_formatter(self):
|
|
||||||
formatters = []
|
|
||||||
for h in self.log.logger.handlers:
|
|
||||||
f = h.formatter
|
|
||||||
if isinstance(f, log.LegacyNovaFormatter):
|
|
||||||
formatters.append(f)
|
|
||||||
self.assert_(formatters)
|
|
||||||
self.assertEqual(len(formatters), len(self.log.logger.handlers))
|
|
||||||
|
|
||||||
def test_handles_context_kwarg(self):
|
|
||||||
self.log.info("foo", context=_fake_context())
|
|
||||||
self.assert_(True) # didn't raise exception
|
|
||||||
|
|
||||||
def test_audit_handles_context_arg(self):
|
|
||||||
self.log.audit("foo", context=_fake_context())
|
|
||||||
self.assert_(True) # didn't raise exception
|
|
||||||
|
|
||||||
def test_will_be_verbose_if_verbose_flag_set(self):
|
|
||||||
self.flags(verbose=True)
|
|
||||||
log.setup()
|
|
||||||
self.assertEqual(logging.DEBUG, self.log.logger.getEffectiveLevel())
|
|
||||||
|
|
||||||
def test_will_not_be_verbose_if_verbose_flag_not_set(self):
|
|
||||||
self.flags(verbose=False)
|
|
||||||
log.setup()
|
|
||||||
self.assertEqual(logging.INFO, self.log.logger.getEffectiveLevel())
|
|
||||||
|
|
||||||
def test_no_logging_via_module(self):
|
|
||||||
for func in ('critical', 'error', 'exception', 'warning', 'warn',
|
|
||||||
'info', 'debug', 'log', 'audit'):
|
|
||||||
self.assertRaises(AttributeError, getattr, log, func)
|
|
||||||
|
|
||||||
|
|
||||||
class LogHandlerTestCase(test.TestCase):
|
|
||||||
def test_log_path_logdir(self):
|
|
||||||
self.flags(logdir='/some/path', logfile=None)
|
|
||||||
self.assertEquals(log._get_log_file_path(binary='foo-bar'),
|
|
||||||
'/some/path/foo-bar.log')
|
|
||||||
|
|
||||||
def test_log_path_logfile(self):
|
|
||||||
self.flags(logfile='/some/path/foo-bar.log')
|
|
||||||
self.assertEquals(log._get_log_file_path(binary='foo-bar'),
|
|
||||||
'/some/path/foo-bar.log')
|
|
||||||
|
|
||||||
def test_log_path_none(self):
|
|
||||||
self.flags(logdir=None, logfile=None)
|
|
||||||
self.assertTrue(log._get_log_file_path(binary='foo-bar') is None)
|
|
||||||
|
|
||||||
def test_log_path_logfile_overrides_logdir(self):
|
|
||||||
self.flags(logdir='/some/other/path',
|
|
||||||
logfile='/some/path/foo-bar.log')
|
|
||||||
self.assertEquals(log._get_log_file_path(binary='foo-bar'),
|
|
||||||
'/some/path/foo-bar.log')
|
|
||||||
|
|
||||||
|
|
||||||
class PublishErrorsHandlerTestCase(test.TestCase):
|
|
||||||
"""Tests for nova.log.PublishErrorsHandler"""
|
|
||||||
def setUp(self):
|
|
||||||
super(PublishErrorsHandlerTestCase, self).setUp()
|
|
||||||
self.publiserrorshandler = log.PublishErrorsHandler(logging.ERROR)
|
|
||||||
|
|
||||||
def test_emit_cfg_list_notifier_drivers_in_flags(self):
|
|
||||||
self.stub_flg = False
|
|
||||||
|
|
||||||
def fake_notifier(*args, **kwargs):
|
|
||||||
self.stub_flg = True
|
|
||||||
|
|
||||||
self.stubs.Set(notifier, 'notify', fake_notifier)
|
|
||||||
logrecord = logging.LogRecord('name', 'WARN', '/tmp', 1,
|
|
||||||
'Message', None, None)
|
|
||||||
self.publiserrorshandler.emit(logrecord)
|
|
||||||
self.assertTrue(self.stub_flg)
|
|
||||||
|
|
||||||
def test_emit_cfg_log_notifier_in_list_notifier_drivers(self):
|
|
||||||
self.flags(list_notifier_drivers=['nova.notifier.rabbit_notifier',
|
|
||||||
'nova.notifier.log_notifier'])
|
|
||||||
self.stub_flg = True
|
|
||||||
|
|
||||||
def fake_notifier(*args, **kwargs):
|
|
||||||
self.stub_flg = False
|
|
||||||
|
|
||||||
self.stubs.Set(notifier, 'notify', fake_notifier)
|
|
||||||
logrecord = logging.LogRecord('name', 'WARN', '/tmp', 1,
|
|
||||||
'Message', None, None)
|
|
||||||
self.publiserrorshandler.emit(logrecord)
|
|
||||||
self.assertTrue(self.stub_flg)
|
|
||||||
|
|
||||||
|
|
||||||
class NovaFormatterTestCase(test.TestCase):
|
|
||||||
def setUp(self):
|
|
||||||
super(NovaFormatterTestCase, self).setUp()
|
|
||||||
self.flags(logging_context_format_string="HAS CONTEXT "
|
|
||||||
"[%(request_id)s]: "
|
|
||||||
"%(message)s",
|
|
||||||
logging_default_format_string="NOCTXT: %(message)s",
|
|
||||||
logging_debug_format_suffix="--DBG")
|
|
||||||
self.log = log.getLogger()
|
|
||||||
self.stream = cStringIO.StringIO()
|
|
||||||
self.handler = logging.StreamHandler(self.stream)
|
|
||||||
self.handler.setFormatter(log.LegacyNovaFormatter())
|
|
||||||
self.log.logger.addHandler(self.handler)
|
|
||||||
self.level = self.log.logger.getEffectiveLevel()
|
|
||||||
self.log.logger.setLevel(logging.DEBUG)
|
|
||||||
|
|
||||||
def tearDown(self):
|
|
||||||
self.log.logger.setLevel(self.level)
|
|
||||||
self.log.logger.removeHandler(self.handler)
|
|
||||||
super(NovaFormatterTestCase, self).tearDown()
|
|
||||||
|
|
||||||
def test_uncontextualized_log(self):
|
|
||||||
self.log.info("foo")
|
|
||||||
self.assertEqual("NOCTXT: foo\n", self.stream.getvalue())
|
|
||||||
|
|
||||||
def test_contextualized_log(self):
|
|
||||||
ctxt = _fake_context()
|
|
||||||
self.log.info("bar", context=ctxt)
|
|
||||||
expected = "HAS CONTEXT [%s]: bar\n" % ctxt.request_id
|
|
||||||
self.assertEqual(expected, self.stream.getvalue())
|
|
||||||
|
|
||||||
def test_debugging_log(self):
|
|
||||||
self.log.debug("baz")
|
|
||||||
self.assertEqual("NOCTXT: baz --DBG\n", self.stream.getvalue())
|
|
||||||
|
|
||||||
|
|
||||||
class NovaLoggerTestCase(test.TestCase):
|
|
||||||
def setUp(self):
|
|
||||||
super(NovaLoggerTestCase, self).setUp()
|
|
||||||
levels = FLAGS.default_log_levels
|
|
||||||
levels.append("nova-test=AUDIT")
|
|
||||||
self.flags(default_log_levels=levels,
|
|
||||||
verbose=True)
|
|
||||||
log.setup()
|
|
||||||
self.log = log.getLogger('nova-test')
|
|
||||||
|
|
||||||
def test_has_level_from_flags(self):
|
|
||||||
self.assertEqual(logging.AUDIT, self.log.logger.getEffectiveLevel())
|
|
||||||
|
|
||||||
def test_child_log_has_level_of_parent_flag(self):
|
|
||||||
l = log.getLogger('nova-test.foo')
|
|
||||||
self.assertEqual(logging.AUDIT, l.logger.getEffectiveLevel())
|
|
||||||
|
|
||||||
|
|
||||||
class JSONFormatterTestCase(test.TestCase):
|
|
||||||
def setUp(self):
|
|
||||||
super(JSONFormatterTestCase, self).setUp()
|
|
||||||
self.log = log.getLogger('test-json')
|
|
||||||
self.stream = cStringIO.StringIO()
|
|
||||||
handler = logging.StreamHandler(self.stream)
|
|
||||||
handler.setFormatter(log.JSONFormatter())
|
|
||||||
self.log.logger.addHandler(handler)
|
|
||||||
self.log.logger.setLevel(logging.DEBUG)
|
|
||||||
|
|
||||||
def test_json(self):
|
|
||||||
test_msg = 'This is a %(test)s line'
|
|
||||||
test_data = {'test': 'log'}
|
|
||||||
self.log.debug(test_msg, test_data)
|
|
||||||
|
|
||||||
data = jsonutils.loads(self.stream.getvalue())
|
|
||||||
self.assertTrue(data)
|
|
||||||
self.assertTrue('extra' in data)
|
|
||||||
self.assertEqual('test-json', data['name'])
|
|
||||||
|
|
||||||
self.assertEqual(test_msg % test_data, data['message'])
|
|
||||||
self.assertEqual(test_msg, data['msg'])
|
|
||||||
self.assertEqual(test_data, data['args'])
|
|
||||||
|
|
||||||
self.assertEqual('test_log.py', data['filename'])
|
|
||||||
self.assertEqual('test_json', data['funcname'])
|
|
||||||
|
|
||||||
self.assertEqual('DEBUG', data['levelname'])
|
|
||||||
self.assertEqual(logging.DEBUG, data['levelno'])
|
|
||||||
self.assertFalse(data['traceback'])
|
|
||||||
|
|
||||||
def test_json_exception(self):
|
|
||||||
test_msg = 'This is %s'
|
|
||||||
test_data = 'exceptional'
|
|
||||||
try:
|
|
||||||
raise Exception('This is exceptional')
|
|
||||||
except Exception:
|
|
||||||
self.log.exception(test_msg, test_data)
|
|
||||||
|
|
||||||
data = jsonutils.loads(self.stream.getvalue())
|
|
||||||
self.assertTrue(data)
|
|
||||||
self.assertTrue('extra' in data)
|
|
||||||
self.assertEqual('test-json', data['name'])
|
|
||||||
|
|
||||||
self.assertEqual(test_msg % test_data, data['message'])
|
|
||||||
self.assertEqual(test_msg, data['msg'])
|
|
||||||
self.assertEqual([test_data], data['args'])
|
|
||||||
|
|
||||||
self.assertEqual('ERROR', data['levelname'])
|
|
||||||
self.assertEqual(logging.ERROR, data['levelno'])
|
|
||||||
self.assertTrue(data['traceback'])
|
|
@ -35,7 +35,7 @@ import sqlalchemy
|
|||||||
import nova.db.migration as migration
|
import nova.db.migration as migration
|
||||||
import nova.db.sqlalchemy.migrate_repo
|
import nova.db.sqlalchemy.migrate_repo
|
||||||
from nova.db.sqlalchemy.migration import versioning_api as migration_api
|
from nova.db.sqlalchemy.migration import versioning_api as migration_api
|
||||||
from nova import log as logging
|
from nova.openstack.common import log as logging
|
||||||
from nova import test
|
from nova import test
|
||||||
|
|
||||||
|
|
||||||
|
@ -25,7 +25,7 @@ import StringIO
|
|||||||
|
|
||||||
from lxml import etree
|
from lxml import etree
|
||||||
|
|
||||||
from nova import log as logging
|
from nova.openstack.common import log as logging
|
||||||
from nova import test
|
from nova import test
|
||||||
from nova.volume import netapp
|
from nova.volume import netapp
|
||||||
|
|
||||||
|
@ -16,9 +16,9 @@
|
|||||||
import nova
|
import nova
|
||||||
from nova import context
|
from nova import context
|
||||||
from nova import flags
|
from nova import flags
|
||||||
from nova import log
|
|
||||||
from nova.notifier import api as notifier_api
|
from nova.notifier import api as notifier_api
|
||||||
import nova.notifier.no_op_notifier
|
import nova.notifier.no_op_notifier
|
||||||
|
from nova.openstack.common import log
|
||||||
from nova import test
|
from nova import test
|
||||||
|
|
||||||
|
|
||||||
@ -106,7 +106,7 @@ class NotifierTestCase(test.TestCase):
|
|||||||
'nova.notifier.rabbit_notifier')
|
'nova.notifier.rabbit_notifier')
|
||||||
self.stubs.Set(nova.flags.FLAGS, 'publish_errors', True)
|
self.stubs.Set(nova.flags.FLAGS, 'publish_errors', True)
|
||||||
LOG = log.getLogger('nova')
|
LOG = log.getLogger('nova')
|
||||||
log.setup()
|
log.setup('nova')
|
||||||
msgs = []
|
msgs = []
|
||||||
|
|
||||||
def mock_notify(context, topic, data):
|
def mock_notify(context, topic, data):
|
||||||
|
@ -21,8 +21,8 @@ import traceback
|
|||||||
|
|
||||||
from nova.compute.manager import ComputeManager
|
from nova.compute.manager import ComputeManager
|
||||||
from nova import exception
|
from nova import exception
|
||||||
from nova import log as logging
|
|
||||||
from nova.openstack.common import importutils
|
from nova.openstack.common import importutils
|
||||||
|
from nova.openstack.common import log as logging
|
||||||
from nova import test
|
from nova import test
|
||||||
from nova.tests.image import fake as fake_image
|
from nova.tests.image import fake as fake_image
|
||||||
from nova.tests import utils as test_utils
|
from nova.tests import utils as test_utils
|
||||||
|
@ -28,9 +28,9 @@ from nova import context
|
|||||||
from nova import db
|
from nova import db
|
||||||
from nova import exception
|
from nova import exception
|
||||||
from nova import flags
|
from nova import flags
|
||||||
from nova import log as logging
|
|
||||||
from nova.notifier import test_notifier
|
from nova.notifier import test_notifier
|
||||||
from nova.openstack.common import importutils
|
from nova.openstack.common import importutils
|
||||||
|
from nova.openstack.common import log as logging
|
||||||
from nova.openstack.common import rpc
|
from nova.openstack.common import rpc
|
||||||
import nova.policy
|
import nova.policy
|
||||||
from nova import quota
|
from nova import quota
|
||||||
@ -430,7 +430,7 @@ class DriverTestCase(test.TestCase):
|
|||||||
return self.output, None
|
return self.output, None
|
||||||
self.volume.driver.set_execute(_fake_execute)
|
self.volume.driver.set_execute(_fake_execute)
|
||||||
|
|
||||||
log = logging.getLogger()
|
log = logging.getLogger('nova')
|
||||||
self.stream = cStringIO.StringIO()
|
self.stream = cStringIO.StringIO()
|
||||||
log.logger.addHandler(logging.logging.StreamHandler(self.stream))
|
log.logger.addHandler(logging.logging.StreamHandler(self.stream))
|
||||||
|
|
||||||
|
@ -23,7 +23,7 @@ from nova.db.sqlalchemy import models
|
|||||||
from nova.db.sqlalchemy import session as sql_session
|
from nova.db.sqlalchemy import session as sql_session
|
||||||
from nova import exception
|
from nova import exception
|
||||||
from nova import flags
|
from nova import flags
|
||||||
from nova import log as logging
|
from nova.openstack.common import log as logging
|
||||||
from nova import test
|
from nova import test
|
||||||
from nova.volume import volume_types
|
from nova.volume import volume_types
|
||||||
|
|
||||||
|
@ -20,9 +20,9 @@
|
|||||||
from nova import context
|
from nova import context
|
||||||
from nova import db
|
from nova import db
|
||||||
from nova import flags
|
from nova import flags
|
||||||
from nova import log as logging
|
|
||||||
from nova.notifier import test_notifier
|
from nova.notifier import test_notifier
|
||||||
from nova.openstack.common import importutils
|
from nova.openstack.common import importutils
|
||||||
|
from nova.openstack.common import log as logging
|
||||||
from nova import test
|
from nova import test
|
||||||
from nova.volume import utils as volume_utils
|
from nova.volume import utils as volume_utils
|
||||||
|
|
||||||
|
@ -29,8 +29,8 @@ from nova import context
|
|||||||
from nova import db
|
from nova import db
|
||||||
from nova import exception
|
from nova import exception
|
||||||
from nova import flags
|
from nova import flags
|
||||||
from nova import log as logging
|
|
||||||
from nova.openstack.common import importutils
|
from nova.openstack.common import importutils
|
||||||
|
from nova.openstack.common import log as logging
|
||||||
from nova.openstack.common import timeutils
|
from nova.openstack.common import timeutils
|
||||||
from nova import test
|
from nova import test
|
||||||
from nova.tests.db import fakes as db_fakes
|
from nova.tests.db import fakes as db_fakes
|
||||||
|
@ -22,7 +22,7 @@ from nova import context
|
|||||||
from nova import db
|
from nova import db
|
||||||
from nova import exception
|
from nova import exception
|
||||||
from nova import flags
|
from nova import flags
|
||||||
from nova import log as logging
|
from nova.openstack.common import log as logging
|
||||||
from nova import test
|
from nova import test
|
||||||
from nova.tests.xenapi import stubs
|
from nova.tests.xenapi import stubs
|
||||||
from nova.virt.xenapi import connection as xenapi_conn
|
from nova.virt.xenapi import connection as xenapi_conn
|
||||||
|
@ -51,10 +51,10 @@ import netaddr
|
|||||||
|
|
||||||
from nova import exception
|
from nova import exception
|
||||||
from nova import flags
|
from nova import flags
|
||||||
from nova import log as logging
|
|
||||||
from nova.openstack.common import cfg
|
from nova.openstack.common import cfg
|
||||||
from nova.openstack.common import excutils
|
from nova.openstack.common import excutils
|
||||||
from nova.openstack.common import importutils
|
from nova.openstack.common import importutils
|
||||||
|
from nova.openstack.common import log as logging
|
||||||
from nova.openstack.common import timeutils
|
from nova.openstack.common import timeutils
|
||||||
|
|
||||||
|
|
||||||
|
@ -32,7 +32,7 @@ import webob.exc
|
|||||||
|
|
||||||
from nova import exception
|
from nova import exception
|
||||||
from nova import flags
|
from nova import flags
|
||||||
from nova import log as logging
|
from nova.openstack.common import log as logging
|
||||||
|
|
||||||
|
|
||||||
FLAGS = flags.FLAGS
|
FLAGS = flags.FLAGS
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
[DEFAULT]
|
[DEFAULT]
|
||||||
|
|
||||||
# The list of modules to copy from openstack-common
|
# The list of modules to copy from openstack-common
|
||||||
modules=cfg,excutils,importutils,iniparser,jsonutils,local,policy,setup,timeutils,rpc,gettextutils
|
modules=cfg,excutils,gettextutils,importutils,iniparser,jsonutils,local,log,policy,setup,timeutils,rpc
|
||||||
|
|
||||||
# The base module to hold the copy of openstack.common
|
# The base module to hold the copy of openstack.common
|
||||||
base=nova
|
base=nova
|
||||||
|
Loading…
Reference in New Issue
Block a user