Skip to content

Commit

Permalink
Use openstack common log to do logging.
Browse files Browse the repository at this point in the history
Bug #1073194

We use openstack common log to do logging. At the same time, we will use
quantum logger as our top logger, so that all sub loggers will be set
according to quantum.conf

Change-Id: I5adf72e6031ad437e05c3521864a83757b3e7887
  • Loading branch information
gongysh committed Nov 1, 2012
1 parent cf54850 commit fa2a5c0
Show file tree
Hide file tree
Showing 37 changed files with 61 additions and 116 deletions.
20 changes: 13 additions & 7 deletions etc/quantum.conf
@@ -1,23 +1,29 @@
[DEFAULT]
# Default log level is WARNING
# Show debugging output in logs (sets DEBUG log level output)
# Default log level is INFO
# verbose and debug has the same result.
# One of them will set DEBUG log level output
# debug = False

# Show more verbose log output (sets INFO log level output) if debug is False
# verbose = False

# log_format = %(asctime)s %(levelname)8s [%(name)s] %(message)s
# log_date_format = %Y-%m-%d %H:%M:%S

# use_syslog -> syslog
# log_file and log_dir -> log_dir/log_file
# (not log_file) and log_dir -> log_dir/{binary_name}.log
# use_stderr -> stderr
# (not user_stderr) and (not log_file) -> stdout
# publish_errors -> notification system

# use_syslog = False
# syslog_log_facility = LOG_USER

# if use_syslog is False, we can set log_file and log_dir.
# if use_syslog is False and we do not set log_file,
# the log will be printed to stdout.
# use_stderr = True
# log_file =
# log_dir =

# publish_errors = False

# Address to bind the API server
bind_host = 0.0.0.0

Expand Down
2 changes: 1 addition & 1 deletion quantum/agent/dhcp_agent.py
Expand Up @@ -15,7 +15,6 @@
# License for the specific language governing permissions and limitations
# under the License.

import logging
import os
import re
import socket
Expand All @@ -37,6 +36,7 @@
from quantum.openstack.common import context
from quantum.openstack.common import importutils
from quantum.openstack.common import jsonutils
from quantum.openstack.common import log as logging
from quantum.openstack.common.rpc import proxy

LOG = logging.getLogger(__name__)
Expand Down
2 changes: 1 addition & 1 deletion quantum/agent/l3_agent.py
Expand Up @@ -19,7 +19,6 @@
#
"""

import logging
import sys
import time

Expand All @@ -33,6 +32,7 @@
from quantum.db import l3_db
from quantum.openstack.common import cfg
from quantum.openstack.common import importutils
from quantum.openstack.common import log as logging
from quantumclient.v2_0 import client

LOG = logging.getLogger(__name__)
Expand Down
2 changes: 1 addition & 1 deletion quantum/agent/linux/dhcp.py
Expand Up @@ -16,7 +16,6 @@
# under the License.

import abc
import logging
import os
import re
import socket
Expand All @@ -30,6 +29,7 @@
from quantum.agent.linux import utils
from quantum.openstack.common import cfg
from quantum.openstack.common import jsonutils
from quantum.openstack.common import log as logging

LOG = logging.getLogger(__name__)

Expand Down
2 changes: 1 addition & 1 deletion quantum/agent/linux/interface.py
Expand Up @@ -16,7 +16,6 @@
# under the License.

import abc
import logging

import netaddr

Expand All @@ -27,6 +26,7 @@
from quantum.extensions.flavor import (FLAVOR_NETWORK)
from quantum.openstack.common import cfg
from quantum.openstack.common import importutils
from quantum.openstack.common import log as logging

LOG = logging.getLogger(__name__)

Expand Down
2 changes: 1 addition & 1 deletion quantum/agent/linux/iptables_manager.py
Expand Up @@ -22,10 +22,10 @@
"""Implements iptables rules using linux utilities."""

import inspect
import logging
import os

from quantum.agent.linux import utils
from quantum.openstack.common import log as logging

LOG = logging.getLogger(__name__)
# NOTE(vish): Iptables supports chain names of up to 28 characters, and we
Expand Down
2 changes: 1 addition & 1 deletion quantum/agent/linux/ovs_lib.py
Expand Up @@ -18,10 +18,10 @@
# @author: Dan Wendlandt, Nicira Networks, Inc.
# @author: Dave Lapsley, Nicira Networks, Inc.

import logging
import re

from quantum.agent.linux import utils
from quantum.openstack.common import log as logging

LOG = logging.getLogger(__name__)

Expand Down
3 changes: 1 addition & 2 deletions quantum/agent/linux/utils.py
Expand Up @@ -18,7 +18,6 @@
# @author: Juliano Martinez, Locaweb.

import fcntl
import logging
import os
import shlex
import signal
Expand All @@ -28,7 +27,7 @@
from eventlet.green import subprocess

from quantum.common import utils

from quantum.openstack.common import log as logging

LOG = logging.getLogger(__name__)

Expand Down
2 changes: 1 addition & 1 deletion quantum/agent/netns_cleanup_util.py
@@ -1,4 +1,3 @@
import logging
import re
import sys

Expand All @@ -13,6 +12,7 @@
from quantum.common import config
from quantum.openstack.common import cfg
from quantum.openstack.common import importutils
from quantum.openstack.common import log as logging

LOG = logging.getLogger(__name__)
NS_MANGLING_PATTERN = ('(%s|%s)' % (dhcp_agent.NS_PREFIX, l3_agent.NS_PREFIX) +
Expand Down
3 changes: 1 addition & 2 deletions quantum/agent/rpc.py
Expand Up @@ -13,12 +13,11 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import logging

import eventlet

from quantum.common import topics

from quantum.openstack.common import log as logging
from quantum.openstack.common import rpc
from quantum.openstack.common.rpc import proxy
from quantum.openstack.common.notifier import api
Expand Down
2 changes: 1 addition & 1 deletion quantum/api/api_common.py
Expand Up @@ -15,10 +15,10 @@
# License for the specific language governing permissions and limitations
# under the License.

import logging

from webob import exc

from quantum.openstack.common import log as logging

LOG = logging.getLogger(__name__)

Expand Down
3 changes: 1 addition & 2 deletions quantum/api/v2/attributes.py
Expand Up @@ -17,12 +17,11 @@
# Defining a constant to avoid repeating string literal in several modules
SHARED = 'shared'

import logging
import netaddr
import re

from quantum.common import exceptions as q_exc

from quantum.openstack.common import log as logging

LOG = logging.getLogger(__name__)

Expand Down
2 changes: 1 addition & 1 deletion quantum/api/v2/base.py
Expand Up @@ -13,7 +13,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import logging
import socket

import webob.exc
Expand All @@ -22,6 +21,7 @@
from quantum.api.v2 import resource as wsgi_resource
from quantum.common import exceptions
from quantum.openstack.common import cfg
from quantum.openstack.common import log as logging
from quantum.openstack.common.notifier import api as notifier_api
from quantum import policy
from quantum import quota
Expand Down
2 changes: 1 addition & 1 deletion quantum/api/v2/resource.py
Expand Up @@ -16,7 +16,6 @@
"""
Utility methods for working with WSGI servers redux
"""
import logging

import webob
import webob.dec
Expand All @@ -25,6 +24,7 @@
from quantum.common import exceptions
from quantum import context
from quantum.openstack.common import jsonutils as json
from quantum.openstack.common import log as logging
from quantum import wsgi


Expand Down
2 changes: 1 addition & 1 deletion quantum/api/v2/router.py
Expand Up @@ -13,7 +13,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import logging
import urlparse

import routes as routes_mapper
Expand All @@ -26,6 +25,7 @@
from quantum.extensions import extensions
from quantum import manager
from quantum.openstack.common import cfg
from quantum.openstack.common import log as logging
from quantum import wsgi


Expand Down
2 changes: 1 addition & 1 deletion quantum/api/versions.py
Expand Up @@ -15,10 +15,10 @@
# License for the specific language governing permissions and limitations
# under the License.

import logging
import webob.dec

from quantum.api.views import versions as versions_view
from quantum.openstack.common import log as logging
from quantum import wsgi


Expand Down
4 changes: 1 addition & 3 deletions quantum/auth.py
Expand Up @@ -14,15 +14,13 @@
# License for the specific language governing permissions and limitations
# under the License.

import logging

import webob.dec
import webob.exc

from quantum import context
from quantum import wsgi
from quantum.openstack.common import cfg

from quantum.openstack.common import log as logging

LOG = logging.getLogger(__name__)

Expand Down
48 changes: 5 additions & 43 deletions quantum/common/config.py
Expand Up @@ -19,19 +19,16 @@
Routines for configuring Quantum
"""

import logging
import logging.config
import logging.handlers
import os
import sys

from paste import deploy

from quantum.api.v2 import attributes
from quantum.openstack.common import cfg
from quantum.openstack.common import log as logging
from quantum.version import version_string


LOG = logging.getLogger(__name__)

core_opts = [
Expand Down Expand Up @@ -79,45 +76,10 @@ def setup_logging(conf):
:param conf: a cfg.ConfOpts object
"""

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)
product_name = "quantum"
logging.setup(product_name)
log_root = logging.getLogger(product_name).logger
log_root.propagate = 0
LOG.info("Logging enabled!")


Expand Down
5 changes: 3 additions & 2 deletions quantum/common/utils.py
Expand Up @@ -21,16 +21,17 @@
"""Utilities and helper functions."""


import logging
import os
import signal
import uuid

from eventlet.green import subprocess

from quantum.openstack.common import cfg
from quantum.openstack.common import log as logging

TIME_FORMAT = "%Y-%m-%dT%H:%M:%SZ"
LOG = logging.getLogger(__name__)


def boolize(subject):
Expand Down Expand Up @@ -60,7 +61,7 @@ def read_cached_file(filename, cache_info, reload_func=None):
"""
mtime = os.path.getmtime(filename)
if not cache_info or mtime != cache_info.get('mtime'):
logging.debug(_("Reloading cached file %s") % filename)
LOG.debug(_("Reloading cached file %s") % filename)
with open(filename) as fap:
cache_info['data'] = fap.read()
cache_info['mtime'] = mtime
Expand Down
4 changes: 3 additions & 1 deletion quantum/context.py
Expand Up @@ -18,12 +18,14 @@
"""Context: context for security/db session."""

import copy
import logging

from datetime import datetime

from quantum.db import api as db_api
from quantum.openstack.common import context as common_context
from quantum.openstack.common import log as logging


LOG = logging.getLogger(__name__)


Expand Down

0 comments on commit fa2a5c0

Please sign in to comment.