Merge "Switch to oslo_log"

This commit is contained in:
Jenkins 2015-07-20 18:02:15 +00:00 committed by Gerrit Code Review
commit 24a715df17
52 changed files with 67 additions and 856 deletions

View File

@ -17,10 +17,10 @@ import json
import cfg
import glanceclient
from oslo_log import log as logging
from murano.common import config
import murano.dsl.helpers as helpers
from murano.openstack.common import log as logging
CONF = config.CONF

View File

@ -44,11 +44,6 @@ level = WARNING
handlers = stderr
qualname = oslo.messaginga
[handler_null]
class = murano.openstack.common.log.NullHandler
formatter = default
args = ()
[handler_stderr]
class = StreamHandler
args = (sys.stderr,)
@ -64,11 +59,5 @@ class: handlers.WatchedFileHandler
args: ('murano.log',)
formatter: context
[formatter_context]
class: murano.openstack.common.log.ContextFormatter
args: (datefmt=datefmt)
format: %(asctime)s.%(msecs)03d %(process)d %(levelname)s %(name)s [%(request_id)s %(user)s %(tenant)s] %(instance)s%(message)s
datefmt: %Y-%m-%d %H:%M:%S
[formatter_default]
format = %(message)s

View File

@ -3,6 +3,7 @@ output_file = etc/murano/murano.conf.sample
namespace = keystonemiddleware.auth_token
namespace = murano
namespace = oslo.db
namespace = oslo.log
namespace = oslo.messaging
namespace = oslo.policy
namespace = oslo.service.service

View File

@ -13,11 +13,11 @@
# under the License.
from oslo_config import cfg
from oslo_log import log as logging
from murano.common.i18n import _
from murano.common import wsgi
import murano.context
import murano.openstack.common.log as logging
context_opts = [
cfg.StrOpt('admin_role', default='admin',

View File

@ -23,8 +23,6 @@ import webob
from murano.common import wsgi
from murano.packages import exceptions as pkg_exc
cfg.CONF.import_opt('debug', 'murano.openstack.common.log')
class HTTPExceptionDisguise(Exception):
"""Disguises HTTP exceptions so they can be handled by the webob fault

View File

@ -19,10 +19,10 @@ return
"""
from oslo_config import cfg
from oslo_log import log as logging
from murano.api import versions
from murano.common import wsgi
import murano.openstack.common.log as logging
CONF = cfg.CONF
LOG = logging.getLogger(__name__)

View File

@ -12,6 +12,7 @@
# License for the specific language governing permissions and limitations
# under the License.
from oslo_log import log as logging
from webob import exc
from murano.common import policy
@ -21,7 +22,6 @@ from murano.db.services import environments as envs
from murano.db.services import sessions
from murano.db import session as db_session
from murano.common.i18n import _LI, _LE, _
from murano.openstack.common import log as logging
from murano.services import actions
from murano.services import states

View File

@ -20,6 +20,7 @@ import tempfile
import jsonschema
from oslo_config import cfg
from oslo_db import exception as db_exc
from oslo_log import log as logging
from webob import exc
import murano.api.v1
@ -29,7 +30,6 @@ from murano.common import policy
from murano.common import wsgi
from murano.db.catalog import api as db_api
from murano.common.i18n import _, _LW
from murano.openstack.common import log as logging
from murano.packages import exceptions as pkg_exc
from murano.packages import load_utils

View File

@ -11,6 +11,8 @@
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from oslo_log import log as logging
from sqlalchemy import desc
from webob import exc
@ -22,7 +24,6 @@ from murano.common import utils
from murano.common import wsgi
from murano.db import models
from murano.db import session as db_session
from murano.openstack.common import log as logging
LOG = logging.getLogger(__name__)

View File

@ -15,6 +15,7 @@
import re
from oslo_db import exception as db_exc
from oslo_log import log as logging
from sqlalchemy import desc
from webob import exc
@ -28,7 +29,6 @@ from murano.db.services import core_services
from murano.db.services import environments as envs
from murano.db import session as db_session
from murano.common.i18n import _, _LI
from murano.openstack.common import log as logging
LOG = logging.getLogger(__name__)

View File

@ -12,11 +12,12 @@
# License for the specific language governing permissions and limitations
# under the License.
from oslo_log import log as logging
from murano.api.v1 import request_statistics
from murano.common import policy
from murano.common import wsgi
from murano.db.services import instances
from murano.openstack.common import log as logging
LOG = logging.getLogger(__name__)

View File

@ -14,11 +14,12 @@
import time
from oslo_log import log as logging
from murano.api import v1
from murano.common.i18n import _LE
from murano.common import wsgi
from murano.db.services import stats
from murano.openstack.common import log as logging
LOG = logging.getLogger(__name__)

View File

@ -14,14 +14,13 @@
import functools as func
from oslo_log import log as logging
from webob import exc
from murano.api.v1 import request_statistics
from murano.common.helpers import token_sanitizer
from murano.common import wsgi
from murano.db.services import core_services
from murano.openstack.common import log as logging
from murano import utils

View File

@ -12,6 +12,7 @@
# License for the specific language governing permissions and limitations
# under the License.
from oslo_log import log as logging
from webob import exc
from murano.api.v1 import request_statistics
@ -21,7 +22,6 @@ from murano.db import models
from murano.db.services import environments as envs
from murano.db.services import sessions
from murano.db import session as db_session
from murano.openstack.common import log as logging
from murano.services import states
LOG = logging.getLogger(__name__)

View File

@ -15,14 +15,13 @@
import functools as func
from oslo_log import log as logging
from webob import exc
from murano.api.v1 import request_statistics
from murano.common.helpers import token_sanitizer
from murano.common import wsgi
from murano.db.services import core_services
from murano.openstack.common import log as logging
from murano import utils

View File

@ -13,6 +13,7 @@
# under the License.
from oslo_db import exception as db_exc
from oslo_log import log as logging
from webob import exc
from murano.api.v1 import environments as envs_api
@ -25,7 +26,6 @@ from murano.db.services import core_services
from murano.db.services import environment_templates as env_temps
from murano.db.services import environments as envs
from murano.db.services import sessions
from murano.openstack.common import log as logging
LOG = logging.getLogger(__name__)

View File

@ -15,7 +15,6 @@
# under the License.
import logging
import os
import sys
@ -35,6 +34,7 @@ if os.path.exists(os.path.join(root, 'murano', '__init__.py')):
sys.path.insert(0, root)
from oslo_config import cfg
from oslo_log import log as logging
from oslo_service import service
from paste import deploy
@ -45,7 +45,6 @@ from murano.common import policy
from murano.common import server
from murano.common import statservice as stats
from murano.common import wsgi
from murano.openstack.common import log
CONF = cfg.CONF
@ -110,10 +109,6 @@ def load_paste_app(app_name=None):
app = deploy.loadapp("config:%s" % conf_file, name=app_name)
# Log the options used when starting if we're in debug mode...
if CONF.debug:
CONF.log_opt_values(logger, logging.DEBUG)
return app
except (LookupError, ImportError) as e:
msg = _("Unable to load %(app_name)s from configuration file"
@ -127,7 +122,6 @@ def load_paste_app(app_name=None):
def main():
try:
config.parse_args()
log.setup('murano')
request_statistics.init_stats()
policy.init()

View File

@ -14,7 +14,6 @@ from oslo_config import cfg
from oslo_db import options
from murano.db.migration import migration
from murano.openstack.common import log
CONF = cfg.CONF
options.set_defaults(CONF)
@ -78,5 +77,4 @@ def main():
config.murano_config = CONF
CONF(project='murano')
log.setup('murano')
CONF.command.func(config)

View File

@ -37,7 +37,6 @@ from oslo_service import service
from murano.common import config
from murano.common import engine
from murano.openstack.common import log
CONF = config.CONF
@ -45,7 +44,6 @@ CONF = config.CONF
def main():
try:
config.parse_args()
log.setup('murano')
launcher = service.ServiceLauncher(CONF)
launcher.launch_service(engine.get_rpc_service())

View File

@ -23,11 +23,11 @@ import traceback
from oslo_config import cfg
from oslo_db import exception as db_exception
from oslo_log import log as logging
from murano.common import consts
from murano.db.catalog import api as db_catalog_api
from murano.common.i18n import _LI, _LE
from murano.openstack.common import log as logging
from murano.packages import load_utils
from murano import version
@ -154,7 +154,6 @@ def main():
CONF(sys.argv[1:], project='murano', prog='murano-manage',
version=version.version_string,
default_config_files=default_config_files)
logging.setup("murano")
except RuntimeError as e:
LOG.error(_LE("failed to initialize murano-manage: %s") % e)
sys.exit("ERROR: %s" % e)

View File

@ -13,13 +13,8 @@
# License for the specific language governing permissions and limitations
# under the License.
import logging
import logging.config
import logging.handlers
import os
import sys
from oslo_config import cfg
from oslo_log import log as logging
from murano.common.i18n import _
from murano import version
@ -246,51 +241,10 @@ CONF.register_opts(networking_opts, group='networking')
def parse_args(args=None, usage=None, default_config_files=None):
logging.register_options(CONF)
logging.setup(CONF, 'murano')
CONF(args=args,
project='murano',
version=version.version_string,
usage=usage,
default_config_files=default_config_files)
def setup_logging():
"""Sets up the logging options for a log with supplied name."""
if CONF.log_config:
# Use a logging configuration file for all settings...
if os.path.exists(CONF.log_config):
logging.config.fileConfig(CONF.log_config)
return
else:
raise RuntimeError(_("Unable to locate specified logging "
"config file: %s") % CONF.log_config)
root_logger = logging.root
if CONF.debug:
root_logger.setLevel(logging.DEBUG)
elif CONF.verbose:
root_logger.setLevel(logging.INFO)
else:
root_logger.setLevel(logging.WARNING)
formatter = logging.Formatter(CONF.log_format, CONF.log_date_format)
if CONF.use_syslog:
try:
facility = getattr(logging.handlers.SysLogHandler,
CONF.syslog_log_facility)
except AttributeError:
raise ValueError(_("Invalid syslog facility"))
handler = logging.handlers.SysLogHandler(address='/dev/log',
facility=facility)
elif CONF.log_file:
logfile = CONF.log_file
if CONF.log_dir:
logfile = os.path.join(CONF.log_dir, logfile)
handler = logging.handlers.WatchedFileHandler(logfile)
else:
handler = logging.StreamHandler(sys.stdout)
handler.setFormatter(formatter)
root_logger.addHandler(handler)

View File

@ -18,6 +18,7 @@ import uuid
import eventlet.debug
from oslo_config import cfg
from oslo_log import log as logging
import oslo_messaging as messaging
from oslo_messaging import target
from oslo_serialization import jsonutils
@ -36,7 +37,6 @@ from murano.engine import package_loader
from murano.engine.system import status_reporter
import murano.engine.system.system_objects as system_objects
from murano.common.i18n import _LI, _LE
from murano.openstack.common import log as logging
from murano.policy import model_policy_enforcer as enforcer
CONF = cfg.CONF

View File

@ -16,11 +16,11 @@ import inspect
import re
from oslo_config import cfg
from oslo_log import log as logging
import six
from stevedore import dispatch
from murano.common.i18n import _LE, _LI, _LW
from murano.openstack.common import log as logging
CONF = cfg.CONF

View File

@ -15,11 +15,11 @@
# Based on designate/policy.py
from oslo_config import cfg
from oslo_log import log as logging
from oslo_policy import policy
from webob import exc as exceptions
from murano.common.i18n import _
import murano.openstack.common.log as logging
LOG = logging.getLogger(__name__)
@ -77,13 +77,13 @@ def check(rule, ctxt, target={}, do_raise=True, exc=exceptions.HTTPForbidden):
extra = {'policy': {'rule': rule, 'target': target}}
if result:
LOG.audit(_("Policy check succeeded for rule "
"'%(rule)s' on target %(target)s"),
{'rule': rule, 'target': repr(target)}, extra=extra)
LOG.info(_("Policy check succeeded for rule "
"'%(rule)s' on target %(target)s"),
{'rule': rule, 'target': repr(target)}, extra=extra)
else:
LOG.audit(_("Policy check failed for rule "
"'%(rule)s' on target: %(target)s"),
{'rule': rule, 'target': repr(target)}, extra=extra)
LOG.info(_("Policy check failed for rule "
"'%(rule)s' on target: %(target)s"),
{'rule': rule, 'target': repr(target)}, extra=extra)
def check_is_admin(context):

View File

@ -15,6 +15,7 @@
import uuid
from oslo_config import cfg
from oslo_log import log as logging
import oslo_messaging as messaging
from oslo_messaging.notify import dispatcher as oslo_dispatcher
from oslo_messaging import target
@ -27,7 +28,6 @@ from murano.db.services import environments
from murano.db.services import instances
from murano.db import session
from murano.common.i18n import _, _LI, _LW
from murano.openstack.common import log as logging
from murano.services import states
CONF = cfg.CONF

View File

@ -19,6 +19,7 @@ import time
import eventlet
from oslo_config import cfg
from oslo_log import log as logging
from oslo_service import service
import psutil
@ -26,7 +27,6 @@ from murano.api import v1
from murano.api.v1 import request_statistics
from murano.common.i18n import _LE
from murano.db.services import stats as db_stats
from murano.openstack.common import log as logging
CONF = cfg.CONF

View File

@ -18,9 +18,9 @@ import types
import eventlet
import jsonschema
from oslo_log import log as logging
from murano.common.i18n import _, _LI
from murano.openstack.common import log as logging
LOG = logging.getLogger(__name__)

View File

@ -29,6 +29,8 @@ eventlet.patcher.monkey_patch(all=False, socket=True)
import eventlet.wsgi
import jsonschema
from oslo_config import cfg
from oslo_log import log as logging
from oslo_log import loggers
from oslo_serialization import jsonutils
from oslo_service import service
from oslo_service import sslutils
@ -41,7 +43,6 @@ from murano.api.v1 import schemas
from murano.common import exceptions
from murano.common.i18n import _
from murano.common import xmlutils
from murano.openstack.common import log as logging
socket_opts = [
cfg.IntOpt('backlog',
@ -161,7 +162,7 @@ class Service(service.Service):
eventlet.wsgi.server(socket,
application,
custom_pool=self.tg.pool,
log=logging.WritableLogger(logger))
log=loggers.WritableLogger(logger))
class Middleware(object):

View File

@ -14,6 +14,7 @@
from oslo_config import cfg
from oslo_db.sqlalchemy import utils
from oslo_log import log as logging
import sqlalchemy as sa
from sqlalchemy import or_
from sqlalchemy.orm import attributes
@ -23,7 +24,7 @@ from webob import exc
from murano.db import models
from murano.db import session as db_session
from murano.common.i18n import _, _LW
from murano.openstack.common import log as logging
CONF = cfg.CONF

View File

@ -14,6 +14,7 @@
import types
from oslo_log import log as logging
from oslo_utils import timeutils
from webob import exc
@ -21,7 +22,6 @@ from murano.common.i18n import _
from murano.common import utils
from murano.db.services import environment_templates as env_temp
from murano.db.services import environments as envs
from murano.openstack.common import log as logging
LOG = logging.getLogger(__name__)

View File

@ -15,9 +15,9 @@
from murano.common import uuidutils
from murano.db import models
from murano.db import session as db_session
from murano.openstack.common import log as logging
from oslo_db import exception as db_exc
from oslo_log import log as logging
LOG = logging.getLogger(__name__)

View File

@ -14,6 +14,7 @@
from keystoneclient import exceptions as ks_exceptions
from oslo_config import cfg
from oslo_log import log as logging
import yaml
from murano.common import auth_utils
@ -21,7 +22,6 @@ from murano.common import uuidutils
from murano.db import models
from murano.db.services import sessions
from murano.db import session as db_session
from murano.openstack.common import log as logging
from murano.services import states
CONF = cfg.CONF

View File

@ -19,10 +19,10 @@ from oslo_config import cfg
from oslo_db import exception
from oslo_db import options
from oslo_db.sqlalchemy import session as db_session
from oslo_log import log as logging
from oslo_utils import timeutils
from murano.db.models import Lock
from murano.openstack.common import log as logging
LOG = logging.getLogger(__name__)
CONF = cfg.CONF

View File

@ -20,6 +20,7 @@ import uuid
import eventlet
import eventlet.event
from oslo_log import log as logging
import yaql.context
from murano.common.i18n import _
@ -32,7 +33,6 @@ import murano.dsl.murano_object as murano_object
import murano.dsl.object_store as object_store
import murano.dsl.principal_objects.stack_trace as trace
import murano.dsl.yaql_functions as yaql_functions
from murano.openstack.common import log as logging
LOG = logging.getLogger(__name__)

View File

@ -13,8 +13,9 @@
# See the License for the specific language governing permissions and
# limitations under the License.
from oslo_log import log as logging
from murano.common.i18n import _LE
import murano.openstack.common.log as logging
LOG = logging.getLogger(__name__)

View File

@ -18,13 +18,13 @@ import os.path
import sys
from oslo_config import cfg
from oslo_log import log as logging
import yaml
from murano.dsl import class_loader
from murano.dsl import exceptions
from murano.dsl import murano_package
from murano.engine.system import yaql_functions
from murano.openstack.common import log as logging
from murano.packages import exceptions as pkg_exceptions
CONF = cfg.CONF

View File

@ -22,12 +22,12 @@ import uuid
from muranoclient.common import exceptions as muranoclient_exc
from oslo_config import cfg
from oslo_log import log as logging
import six
from murano.common.i18n import _LE
from murano.dsl import exceptions
from murano.engine import yaql_yaml_loader
from murano.openstack.common import log as logging
from murano.packages import exceptions as pkg_exc
from murano.packages import load_utils

View File

@ -15,15 +15,15 @@
import eventlet
import greenlet
from oslo_config import cfg
from oslo_config import cfg
from oslo_log import log as logging
import murano.common.exceptions as exceptions
from murano.dsl import helpers
import murano.dsl.murano_class as murano_class
import murano.dsl.murano_object as murano_object
import murano.engine.system.common as common
from murano.openstack.common import log as logging
LOG = logging.getLogger(__name__)
CONF = cfg.CONF

View File

@ -17,13 +17,13 @@ import copy
import eventlet
import heatclient.exc as heat_exc
from oslo_log import log as logging
import murano.common.utils as utils
import murano.dsl.helpers as helpers
import murano.dsl.murano_class as murano_class
import murano.dsl.murano_object as murano_object
from murano.common.i18n import _LI, _LW
import murano.openstack.common.log as logging
LOG = logging.getLogger(__name__)

View File

@ -14,11 +14,11 @@
# limitations under the License.
from oslo_config import cfg
from oslo_log import log as logging
import oslo_messaging as messaging
from murano.common import uuidutils
from murano.dsl import murano_class
from murano.openstack.common import log as logging
CONF = cfg.CONF
LOG = logging.getLogger(__name__)

View File

@ -17,11 +17,11 @@
import json
import eventlet
from oslo_log import log as logging
import murano.dsl.helpers as helpers
import murano.dsl.murano_class as murano_class
import murano.dsl.murano_object as murano_object
import murano.openstack.common.log as logging
LOG = logging.getLogger(__name__)

View File

@ -17,12 +17,12 @@ import math
import netaddr
from netaddr.strategy import ipv4
from oslo_config import cfg
from oslo_log import log as logging
from oslo_utils import uuidutils
import murano.dsl.helpers as helpers
import murano.dsl.murano_class as murano_class
import murano.dsl.murano_object as murano_object
from murano.openstack.common import log as logging
CONF = cfg.CONF
LOG = logging.getLogger(__name__)

View File

@ -14,11 +14,11 @@
# limitations under the License.
from oslo_config import cfg
from oslo_log import log as logging
import oslo_messaging as messaging
from murano.common import uuidutils
from murano.dsl import murano_class
from murano.openstack.common import log as logging
CONF = cfg.CONF
LOG = logging.getLogger(__name__)

View File

@ -1,719 +0,0 @@
# Copyright 2011 OpenStack Foundation.
# Copyright 2010 United States Government as represented by the
# Administrator of the National Aeronautics and Space Administration.
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
"""OpenStack logging handler.
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
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
for admins to find messages related to a specific instance.
It also allows setting of formatting information through conf.
"""
import copy
import inspect
import itertools
import logging
import logging.config
import logging.handlers
import os
import socket
import sys
import traceback
from oslo_config import cfg
from oslo_serialization import jsonutils
from oslo_utils import importutils
import six
from six import moves
_PY26 = sys.version_info[0:2] == (2, 6)
from murano.openstack.common._i18n import _, _LI
from murano.openstack.common import local
_DEFAULT_LOG_DATE_FORMAT = "%Y-%m-%d %H:%M:%S"
common_cli_opts = [
cfg.BoolOpt('debug',
short='d',
default=False,
help='Print debugging output (set logging level to '
'DEBUG instead of default WARNING level).'),
cfg.BoolOpt('verbose',
short='v',
default=False,
help='Print more verbose output (set logging level to '
'INFO instead of default WARNING level).'),
]
logging_cli_opts = [
cfg.StrOpt('log-config-append',
metavar='PATH',
deprecated_name='log-config',
help='The name of a logging configuration file. This file '
'is appended to any existing logging configuration '
'files. For details about logging configuration files, '
'see the Python logging module documentation.'),
cfg.StrOpt('log-format',
metavar='FORMAT',
help='DEPRECATED. '
'A logging.Formatter log message format string which may '
'use any of the available logging.LogRecord attributes. '
'This option is deprecated. Please use '
'logging_context_format_string and '
'logging_default_format_string instead.'),
cfg.StrOpt('log-date-format',
default=_DEFAULT_LOG_DATE_FORMAT,
metavar='DATE_FORMAT',
help='Format string for %%(asctime)s in log records. '
'Default: %(default)s .'),
cfg.StrOpt('log-file',
metavar='PATH',
deprecated_name='logfile',
help='(Optional) Name of log file to output to. '
'If no default is set, logging will go to stdout.'),
cfg.StrOpt('log-dir',
deprecated_name='logdir',
help='(Optional) The base directory used for relative '
'--log-file paths.'),
cfg.BoolOpt('use-syslog',
default=False,
help='Use syslog for logging. '
'Existing syslog format is DEPRECATED during I, '
'and will change in J to honor RFC5424.'),
cfg.BoolOpt('use-syslog-rfc-format',
# TODO(bogdando) remove or use True after existing
# syslog format deprecation in J
default=False,
help='(Optional) Enables or disables syslog rfc5424 format '
'for logging. If enabled, prefixes the MSG part of the '
'syslog message with APP-NAME (RFC5424). The '
'format without the APP-NAME is deprecated in I, '
'and will be removed in J.'),
cfg.StrOpt('syslog-log-facility',
default='LOG_USER',
help='Syslog facility to receive log lines.')
]
generic_log_opts = [
cfg.BoolOpt('use_stderr',
default=True,
help='Log output to standard error.')
]
DEFAULT_LOG_LEVELS = ['amqp=WARN', 'amqplib=WARN', 'boto=WARN',
'qpid=WARN', 'sqlalchemy=WARN', 'suds=INFO',
'oslo.messaging=INFO', 'iso8601=WARN',
'requests.packages.urllib3.connectionpool=WARN',
'urllib3.connectionpool=WARN', 'websocket=WARN',
"keystonemiddleware=WARN", "routes.middleware=WARN",
"stevedore=WARN"]
log_opts = [
cfg.StrOpt('logging_context_format_string',
default='%(asctime)s.%(msecs)03d %(process)d %(levelname)s '
'%(name)s [%(request_id)s %(user_identity)s] '
'%(instance)s%(message)s',
help='Format string to use for log messages with context.'),
cfg.StrOpt('logging_default_format_string',
default='%(asctime)s.%(msecs)03d %(process)d %(levelname)s '
'%(name)s [-] %(instance)s%(message)s',
help='Format string to use for log messages without context.'),
cfg.StrOpt('logging_debug_format_suffix',
default='%(funcName)s %(pathname)s:%(lineno)d',
help='Data to append to log format when level is DEBUG.'),
cfg.StrOpt('logging_exception_prefix',
default='%(asctime)s.%(msecs)03d %(process)d TRACE %(name)s '
'%(instance)s',
help='Prefix each line of exception output with this format.'),
cfg.ListOpt('default_log_levels',
default=DEFAULT_LOG_LEVELS,
help='List of logger=LEVEL pairs.'),
cfg.BoolOpt('publish_errors',
default=False,
help='Enables or disables publication of error events.'),
cfg.BoolOpt('fatal_deprecations',
default=False,
help='Enables or disables fatal status of deprecations.'),
# NOTE(mikal): there are two options here because sometimes we are handed
# a full instance (and could include more information), and other times we
# are just handed a UUID for the instance.
cfg.StrOpt('instance_format',
default='[instance: %(uuid)s] ',
help='The format for an instance that is passed with the log '
'message.'),
cfg.StrOpt('instance_uuid_format',
default='[instance: %(uuid)s] ',
help='The format for an instance UUID that is passed with the '
'log message.'),
]
CONF = cfg.CONF
CONF.register_cli_opts(common_cli_opts)
CONF.register_cli_opts(logging_cli_opts)
CONF.register_opts(generic_log_opts)
CONF.register_opts(log_opts)
def list_opts():
"""Entry point for oslo.config-generator."""
return [(None, copy.deepcopy(common_cli_opts)),
(None, copy.deepcopy(logging_cli_opts)),
(None, copy.deepcopy(generic_log_opts)),
(None, copy.deepcopy(log_opts)),
]
# our new audit level
# NOTE(jkoelker) Since we synthesized an audit level, make the logging
# module aware of it so it acts like other levels.
logging.AUDIT = logging.INFO + 1
logging.addLevelName(logging.AUDIT, 'AUDIT')
try:
NullHandler = logging.NullHandler
except AttributeError: # NOTE(jkoelker) NullHandler added in Python 2.7
class NullHandler(logging.Handler):
def handle(self, record):
pass
def emit(self, record):
pass
def createLock(self):
self.lock = None
def _dictify_context(context):
if context is None:
return None
if not isinstance(context, dict) and getattr(context, 'to_dict', None):
context = context.to_dict()
return context
def _get_binary_name():
return os.path.basename(inspect.stack()[-1][1])
def _get_log_file_path(binary=None):
logfile = CONF.log_file
logdir = CONF.log_dir
if logfile and not logdir:
return logfile
if logfile and logdir:
return os.path.join(logdir, logfile)
if logdir:
binary = binary or _get_binary_name()
return '%s.log' % (os.path.join(logdir, binary),)
return None
class BaseLoggerAdapter(logging.LoggerAdapter):
def audit(self, msg, *args, **kwargs):
self.log(logging.AUDIT, msg, *args, **kwargs)
def isEnabledFor(self, level):
if _PY26:
# This method was added in python 2.7 (and it does the exact
# same logic, so we need to do the exact same logic so that
# python 2.6 has this capability as well).
return self.logger.isEnabledFor(level)
else:
return super(BaseLoggerAdapter, self).isEnabledFor(level)
class LazyAdapter(BaseLoggerAdapter):
def __init__(self, name='unknown', version='unknown'):
self._logger = None
self.extra = {}
self.name = name
self.version = version
@property
def logger(self):
if not self._logger:
self._logger = getLogger(self.name, self.version)
if six.PY3:
# In Python 3, the code fails because the 'manager' attribute
# cannot be found when using a LoggerAdapter as the
# underlying logger. Work around this issue.
self._logger.manager = self._logger.logger.manager
return self._logger
class ContextAdapter(BaseLoggerAdapter):
warn = logging.LoggerAdapter.warning
def __init__(self, logger, project_name, version_string):
self.logger = logger
self.project = project_name
self.version = version_string
self._deprecated_messages_sent = dict()
@property
def handlers(self):
return self.logger.handlers
def deprecated(self, msg, *args, **kwargs):
"""Call this method when a deprecated feature is used.
If the system is configured for fatal deprecations then the message
is logged at the 'critical' level and :class:`DeprecatedConfig` will
be raised.
Otherwise, the message will be logged (once) at the 'warn' level.
:raises: :class:`DeprecatedConfig` if the system is configured for
fatal deprecations.
"""
stdmsg = _("Deprecated: %s") % msg
if CONF.fatal_deprecations:
self.critical(stdmsg, *args, **kwargs)
raise DeprecatedConfig(msg=stdmsg)
# Using a list because a tuple with dict can't be stored in a set.
sent_args = self._deprecated_messages_sent.setdefault(msg, list())
if args in sent_args:
# Already logged this message, so don't log it again.
return
sent_args.append(args)
self.warn(stdmsg, *args, **kwargs)
def process(self, msg, kwargs):
# NOTE(jecarey): If msg is not unicode, coerce it into unicode
# before it can get to the python logging and
# possibly cause string encoding trouble
if not isinstance(msg, six.text_type):
msg = six.text_type(msg)
if 'extra' not in kwargs:
kwargs['extra'] = {}
extra = kwargs['extra']
context = kwargs.pop('context', None)
if not context:
context = getattr(local.store, 'context', None)
if context:
extra.update(_dictify_context(context))
instance = kwargs.pop('instance', None)
instance_uuid = (extra.get('instance_uuid') or
kwargs.pop('instance_uuid', None))
instance_extra = ''
if instance:
instance_extra = CONF.instance_format % instance
elif instance_uuid:
instance_extra = (CONF.instance_uuid_format
% {'uuid': instance_uuid})
extra['instance'] = instance_extra
extra.setdefault('user_identity', kwargs.pop('user_identity', None))
extra['project'] = self.project
extra['version'] = self.version
extra['extra'] = extra.copy()
return msg, kwargs
class JSONFormatter(logging.Formatter):
def __init__(self, fmt=None, datefmt=None):
# NOTE(jkoelker) we ignore the fmt argument, but its still there
# since logging.config.fileConfig passes it.
self.datefmt = datefmt
def formatException(self, ei, strip_newlines=True):
lines = traceback.format_exception(*ei)
if strip_newlines:
lines = [moves.filter(
lambda x: x,
line.rstrip().splitlines()) for line in lines]
lines = list(itertools.chain(*lines))
return lines
def format(self, record):
message = {'message': record.getMessage(),
'asctime': self.formatTime(record, self.datefmt),
'name': record.name,
'msg': record.msg,
'args': record.args,
'levelname': record.levelname,
'levelno': record.levelno,
'pathname': record.pathname,
'filename': record.filename,
'module': record.module,
'lineno': record.lineno,
'funcname': record.funcName,
'created': record.created,
'msecs': record.msecs,
'relative_created': record.relativeCreated,
'thread': record.thread,
'thread_name': record.threadName,
'process_name': record.processName,
'process': record.process,
'traceback': None}
if hasattr(record, 'extra'):
message['extra'] = record.extra
if record.exc_info:
message['traceback'] = self.formatException(record.exc_info)
return jsonutils.dumps(message)
def _create_logging_excepthook(product_name):
def logging_excepthook(exc_type, value, tb):
extra = {'exc_info': (exc_type, value, tb)}
getLogger(product_name).critical(
"".join(traceback.format_exception_only(exc_type, value)),
**extra)
return logging_excepthook
class LogConfigError(Exception):
message = _('Error loading logging config %(log_config)s: %(err_msg)s')
def __init__(self, log_config, err_msg):
self.log_config = log_config
self.err_msg = err_msg
def __str__(self):
return self.message % dict(log_config=self.log_config,
err_msg=self.err_msg)
def _load_log_config(log_config_append):
try:
logging.config.fileConfig(log_config_append,
disable_existing_loggers=False)
except (moves.configparser.Error, KeyError) as exc:
raise LogConfigError(log_config_append, six.text_type(exc))
def setup(product_name, version='unknown'):
"""Setup logging."""
if CONF.log_config_append:
_load_log_config(CONF.log_config_append)
else:
_setup_logging_from_conf(product_name, version)
sys.excepthook = _create_logging_excepthook(product_name)
def set_defaults(logging_context_format_string=None,
default_log_levels=None):
# Just in case the caller is not setting the
# default_log_level. This is insurance because
# we introduced the default_log_level parameter
# later in a backwards in-compatible change
if default_log_levels is not None:
cfg.set_defaults(
log_opts,
default_log_levels=default_log_levels)
if logging_context_format_string is not None:
cfg.set_defaults(
log_opts,
logging_context_format_string=logging_context_format_string)
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
class RFCSysLogHandler(logging.handlers.SysLogHandler):
def __init__(self, *args, **kwargs):
self.binary_name = _get_binary_name()
# Do not use super() unless type(logging.handlers.SysLogHandler)
# is 'type' (Python 2.7).
# Use old style calls, if the type is 'classobj' (Python 2.6)
logging.handlers.SysLogHandler.__init__(self, *args, **kwargs)
def format(self, record):
# Do not use super() unless type(logging.handlers.SysLogHandler)
# is 'type' (Python 2.7).
# Use old style calls, if the type is 'classobj' (Python 2.6)
msg = logging.handlers.SysLogHandler.format(self, record)
msg = self.binary_name + ' ' + msg
return msg
def _setup_logging_from_conf(project, version):
log_root = getLogger(None).logger
for handler in log_root.handlers:
log_root.removeHandler(handler)
logpath = _get_log_file_path()
if logpath:
filelog = logging.handlers.WatchedFileHandler(logpath)
log_root.addHandler(filelog)
if CONF.use_stderr:
streamlog = ColorHandler()
log_root.addHandler(streamlog)
elif not logpath:
# 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:
handler = importutils.import_object(
"oslo.messaging.notify.log_handler.PublishErrorsHandler",
logging.ERROR)
log_root.addHandler(handler)
datefmt = CONF.log_date_format
for handler in log_root.handlers:
# NOTE(alaski): CONF.log_format overrides everything currently. This
# should be deprecated in favor of context aware formatting.
if CONF.log_format:
handler.setFormatter(logging.Formatter(fmt=CONF.log_format,
datefmt=datefmt))
log_root.info(_LI(
'Deprecated: log_format is now deprecated and will '
'be removed in the next release'))
else:
handler.setFormatter(ContextFormatter(project=project,
version=version,
datefmt=datefmt))
if CONF.debug:
log_root.setLevel(logging.DEBUG)
elif CONF.verbose:
log_root.setLevel(logging.INFO)
else:
log_root.setLevel(logging.WARNING)
for pair in CONF.default_log_levels:
mod, _sep, level_name = pair.partition('=')
logger = logging.getLogger(mod)
# NOTE(AAzza) in python2.6 Logger.setLevel doesn't convert string name
# to integer code.
if sys.version_info < (2, 7):
level = logging.getLevelName(level_name)
logger.setLevel(level)
else:
logger.setLevel(level_name)
if CONF.use_syslog:
try:
facility = _find_facility_from_conf()
# TODO(bogdando) use the format provided by RFCSysLogHandler
# after existing syslog format deprecation in J
if CONF.use_syslog_rfc_format:
syslog = RFCSysLogHandler(address='/dev/log',
facility=facility)
else:
syslog = logging.handlers.SysLogHandler(address='/dev/log',
facility=facility)
log_root.addHandler(syslog)
except socket.error:
log_root.error('Unable to add syslog handler. Verify that syslog '
'is running.')
_loggers = {}
def getLogger(name='unknown', version='unknown'):
if name not in _loggers:
_loggers[name] = ContextAdapter(logging.getLogger(name),
name,
version)
return _loggers[name]
def getLazyLogger(name='unknown', version='unknown'):
"""Returns lazy logger.
Creates a pass-through logger that does not create the real logger
until it is really needed and delegates all calls to the real logger
once it is created.
"""
return LazyAdapter(name, version)
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.rstrip())
class ContextFormatter(logging.Formatter):
"""A context.RequestContext aware formatter configured through flags.
The flags used to set format strings are: logging_context_format_string
and logging_default_format_string. You can also specify
logging_debug_format_suffix to append extra formatting if the log level is
debug.
For information about what variables are available for the formatter see:
http://docs.python.org/library/logging.html#formatter
If available, uses the context value stored in TLS - local.store.context
"""
def __init__(self, *args, **kwargs):
"""Initialize ContextFormatter instance
Takes additional keyword arguments which can be used in the message
format string.
:keyword project: project name
:type project: string
:keyword version: project version
:type version: string
"""
self.project = kwargs.pop('project', 'unknown')
self.version = kwargs.pop('version', 'unknown')
logging.Formatter.__init__(self, *args, **kwargs)
def format(self, record):
"""Uses contextstring if request_id is set, otherwise default."""
# NOTE(jecarey): If msg is not unicode, coerce it into unicode
# before it can get to the python logging and
# possibly cause string encoding trouble
if not isinstance(record.msg, six.text_type):
record.msg = six.text_type(record.msg)
# store project info
record.project = self.project
record.version = self.version
# store request info
context = getattr(local.store, 'context', None)
if context:
d = _dictify_context(context)
for k, v in d.items():
setattr(record, k, v)
# NOTE(sdague): default the fancier formatting params
# to an empty string so we don't throw an exception if
# they get used
for key in ('instance', 'color', 'user_identity'):
if key not in record.__dict__:
record.__dict__[key] = ''
if record.__dict__.get('request_id'):
fmt = CONF.logging_context_format_string
else:
fmt = CONF.logging_default_format_string
if (record.levelno == logging.DEBUG and
CONF.logging_debug_format_suffix):
fmt += " " + CONF.logging_debug_format_suffix
if sys.version_info < (3, 2):
self._fmt = fmt
else:
self._style = logging.PercentStyle(fmt)
self._fmt = self._style._fmt
# Cache this on the record, Logger will respect our formatted copy
if record.exc_info:
record.exc_text = self.formatException(record.exc_info, record)
return logging.Formatter.format(self, record)
def formatException(self, exc_info, record=None):
"""Format exception output with CONF.logging_exception_prefix."""
if not record:
return logging.Formatter.formatException(self, exc_info)
stringbuffer = moves.StringIO()
traceback.print_exception(exc_info[0], exc_info[1], exc_info[2],
None, stringbuffer)
lines = stringbuffer.getvalue().split('\n')
stringbuffer.close()
if CONF.logging_exception_prefix.find('%(asctime)') != -1:
record.asctime = self.formatTime(record, self.datefmt)
formatted_lines = []
for line in lines:
pl = CONF.logging_exception_prefix % record.__dict__
fl = '%s%s' % (pl, line)
formatted_lines.append(fl)
return '\n'.join(formatted_lines)
class ColorHandler(logging.StreamHandler):
LEVEL_COLORS = {
logging.DEBUG: '\033[00;32m', # GREEN
logging.INFO: '\033[00;36m', # CYAN
logging.AUDIT: '\033[01;36m', # BOLD CYAN
logging.WARN: '\033[01;33m', # BOLD YELLOW
logging.ERROR: '\033[01;31m', # BOLD RED
logging.CRITICAL: '\033[01;31m', # BOLD RED
}
def format(self, record):
record.color = self.LEVEL_COLORS[record.levelno]
return logging.StreamHandler.format(self, record)
class DeprecatedConfig(Exception):
message = _("Fatal call to deprecated config: %(msg)s")
def __init__(self, msg):
super(Exception, self).__init__(self.message % dict(msg=msg))

View File

@ -20,7 +20,6 @@ import oslo_service.sslutils
import murano.common.config
import murano.common.wsgi
import murano.openstack.common.log
def build_list(opt_list):
@ -44,10 +43,6 @@ _opt_lists = [
murano.common.config.bind_opts,
murano.common.config.file_server,
murano.common.wsgi.socket_opts,
murano.openstack.common.log.common_cli_opts,
murano.openstack.common.log.generic_log_opts,
murano.openstack.common.log.log_opts,
murano.openstack.common.log.logging_cli_opts,
])),
]

View File

@ -15,8 +15,9 @@
import re
from oslo_log import log as logging
from murano.common.i18n import _, _LI
from murano.openstack.common import log as logging
from murano.policy import congress_rules

View File

@ -12,14 +12,15 @@
# limitations under the License.
import fixtures
from oslo_log import log
import testtools
from murano.common import config
from murano.db import api as db_api
from murano.openstack.common import log
CONF = config.CONF
log.setup('murano')
log.register_options(CONF)
log.setup(CONF, 'murano')
class MuranoTestCase(testtools.TestCase):

View File

@ -30,10 +30,10 @@ from alembic import config as alembic_config
from alembic import migration
from alembic import script as alembic_script
from oslo_config import cfg
from oslo_log import log as logging
from murano.common.i18n import _LE
import murano.db.migration
from murano.openstack.common import log as logging
LOG = logging.getLogger(__name__)
CONF = cfg.CONF

View File

@ -16,7 +16,8 @@
import logging
import sys
from murano.openstack.common import log
from oslo_log import handlers
from murano.tests.unit import base
@ -30,8 +31,8 @@ class SysLogHandlersTestCase(base.MuranoTestCase):
self.skip("SKIP: This test work on Linux platform only.")
self.facility = logging.handlers.SysLogHandler.LOG_USER
self.rfclogger = log.RFCSysLogHandler(address='/dev/log',
facility=self.facility)
self.rfclogger = handlers.RFCSysLogHandler(address='/dev/log',
facility=self.facility)
self.rfclogger.binary_name = 'Foo_application'
self.logger = logging.handlers.SysLogHandler(address='/dev/log',
facility=self.facility)

View File

@ -14,13 +14,13 @@
import functools
from oslo_log import log as logging
from webob import exc
from murano.common.i18n import _LI
from murano.db import models
from murano.db.services import sessions
from murano.db import session as db_session
from murano.openstack.common import log as logging
from murano.services import states
LOG = logging.getLogger(__name__)

View File

@ -1,7 +1,3 @@
[DEFAULT]
# The list of modules to copy from openstack-common
module=log
# The base module to hold the copy of openstack.common
base=murano

View File

@ -37,6 +37,7 @@ oslo.serialization>=1.4.0 # Apache-2.0
oslo.service>=0.1.0 # Apache-2.0
oslo.utils>=1.6.0 # Apache-2.0
oslo.i18n>=1.5.0 # Apache-2.0
oslo.log>=1.2.0 # Apache-2.0
# not listed in global requirements
python-mistralclient!=1.0.0.0b1,>=1.0.0