Align logging on oslo_log

This patch aligns all of Octavia to use oslo_log instead of the built
in python logging. This should provide consistent log formats.

It adds a hacking check to make sure "logging" doesn't come back into
the code.

Change-Id: I9b76c2bb5a5c396faf85df4606f2ca00f23de913
This commit is contained in:
Michael Johnson 2018-06-16 14:02:40 -07:00
parent 13eab152fb
commit 5af7133a02
33 changed files with 50 additions and 55 deletions

@ -12,10 +12,11 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
import logging
import re import re
import subprocess import subprocess
from oslo_log import log as logging
LOG = logging.getLogger(__name__) LOG = logging.getLogger(__name__)

@ -12,13 +12,13 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
import logging
import os import os
import stat import stat
import subprocess import subprocess
import flask import flask
import jinja2 import jinja2
from oslo_log import log as logging
import webob import webob
from octavia.amphorae.backends.agent.api_server import listener from octavia.amphorae.backends.agent.api_server import listener

@ -14,7 +14,6 @@
import hashlib import hashlib
import io import io
import logging
import os import os
import re import re
import shutil import shutil
@ -24,6 +23,7 @@ import subprocess
import flask import flask
import jinja2 import jinja2
from oslo_config import cfg from oslo_config import cfg
from oslo_log import log as logging
import six import six
import webob import webob
from werkzeug import exceptions from werkzeug import exceptions

@ -13,7 +13,6 @@
# under the License. # under the License.
import ipaddress import ipaddress
import logging
import os import os
import platform import platform
import shutil import shutil
@ -22,6 +21,7 @@ import subprocess
import jinja2 import jinja2
from oslo_config import cfg from oslo_config import cfg
from oslo_log import log as logging
import six import six
import webob import webob
from werkzeug import exceptions from werkzeug import exceptions

@ -14,7 +14,6 @@
# under the License. # under the License.
import ipaddress import ipaddress
import logging
import os import os
import socket import socket
import stat import stat
@ -23,6 +22,7 @@ import subprocess
import jinja2 import jinja2
import netifaces import netifaces
from oslo_config import cfg from oslo_config import cfg
from oslo_log import log as logging
import pyroute2 import pyroute2
import six import six
import webob import webob

@ -12,9 +12,8 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
import logging
from oslo_config import cfg from oslo_config import cfg
from oslo_log import log as logging
from pecan import rest from pecan import rest
from wsme import types as wtypes from wsme import types as wtypes
from wsmeext import pecan as wsme_pecan from wsmeext import pecan as wsme_pecan

@ -12,9 +12,8 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
import logging
from oslo_config import cfg from oslo_config import cfg
from oslo_log import log as logging
from pecan import rest from pecan import rest
from stevedore import driver as stevedore_driver from stevedore import driver as stevedore_driver

@ -13,9 +13,8 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
import logging
from oslo_db import exception as odb_exceptions from oslo_db import exception as odb_exceptions
from oslo_log import log as logging
from oslo_utils import excutils from oslo_utils import excutils
import pecan import pecan
from wsmeext import pecan as wsme_pecan from wsmeext import pecan as wsme_pecan

@ -12,9 +12,8 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
import logging
import oslo_db.exception as oslo_exc import oslo_db.exception as oslo_exc
from oslo_log import log as logging
from oslo_utils import excutils from oslo_utils import excutils
import pecan import pecan
from wsme import types as wtypes from wsme import types as wtypes

@ -12,9 +12,8 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
import logging
import oslo_db.exception as oslo_exc import oslo_db.exception as oslo_exc
from oslo_log import log as logging
from oslo_utils import excutils from oslo_utils import excutils
import pecan import pecan
from wsme import types as wtypes from wsme import types as wtypes

@ -13,9 +13,8 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
import logging
from oslo_db import exception as odb_exceptions from oslo_db import exception as odb_exceptions
from oslo_log import log as logging
from oslo_utils import excutils from oslo_utils import excutils
import pecan import pecan
from wsme import types as wtypes from wsme import types as wtypes

@ -13,9 +13,8 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
import logging
import oslo_db.exception as oslo_exc import oslo_db.exception as oslo_exc
from oslo_log import log as logging
from oslo_utils import excutils from oslo_utils import excutils
import pecan import pecan
from wsme import types as wtypes from wsme import types as wtypes

@ -13,9 +13,8 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
import logging
from oslo_db import exception as odb_exceptions from oslo_db import exception as odb_exceptions
from oslo_log import log as logging
from oslo_utils import excutils from oslo_utils import excutils
import pecan import pecan
from wsme import types as wtypes from wsme import types as wtypes

@ -13,9 +13,8 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
import logging
from oslo_config import cfg from oslo_config import cfg
from oslo_log import log as logging
import oslo_messaging as messaging import oslo_messaging as messaging
from oslo_utils import excutils from oslo_utils import excutils
import pecan import pecan

@ -12,9 +12,8 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
import logging
from oslo_config import cfg from oslo_config import cfg
from oslo_log import log as logging
from pecan import rest from pecan import rest
from wsme import types as wtypes from wsme import types as wtypes

@ -13,10 +13,9 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
import logging
from oslo_config import cfg from oslo_config import cfg
from oslo_db import exception as odb_exceptions from oslo_db import exception as odb_exceptions
from oslo_log import log as logging
from oslo_utils import excutils from oslo_utils import excutils
import pecan import pecan
from wsme import types as wtypes from wsme import types as wtypes

@ -12,10 +12,9 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
import logging
from oslo_config import cfg from oslo_config import cfg
from oslo_db import exception as odb_exceptions from oslo_db import exception as odb_exceptions
from oslo_log import log as logging
from oslo_utils import excutils from oslo_utils import excutils
import pecan import pecan
from wsme import types as wtypes from wsme import types as wtypes

@ -12,9 +12,8 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
import logging
from oslo_db import exception as odb_exceptions from oslo_db import exception as odb_exceptions
from oslo_log import log as logging
from oslo_utils import excutils from oslo_utils import excutils
import pecan import pecan
from wsme import types as wtypes from wsme import types as wtypes

@ -13,10 +13,9 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
import logging
from oslo_config import cfg from oslo_config import cfg
from oslo_db import exception as odb_exceptions from oslo_db import exception as odb_exceptions
from oslo_log import log as logging
from oslo_utils import excutils from oslo_utils import excutils
import pecan import pecan
from stevedore import driver as stevedore_driver from stevedore import driver as stevedore_driver

@ -13,9 +13,8 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
import logging
from oslo_db import exception as odb_exceptions from oslo_db import exception as odb_exceptions
from oslo_log import log as logging
from oslo_utils import excutils from oslo_utils import excutils
import pecan import pecan
from wsme import types as wtypes from wsme import types as wtypes

@ -13,10 +13,9 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
import logging
from oslo_config import cfg from oslo_config import cfg
from oslo_db import exception as odb_exceptions from oslo_db import exception as odb_exceptions
from oslo_log import log as logging
from oslo_utils import excutils from oslo_utils import excutils
import pecan import pecan
from wsme import types as wtypes from wsme import types as wtypes

@ -12,9 +12,8 @@
"""Policy Engine For Octavia.""" """Policy Engine For Octavia."""
import logging
from oslo_config import cfg from oslo_config import cfg
from oslo_log import log as logging
from oslo_policy import policy as oslo_policy from oslo_policy import policy as oslo_policy
from oslo_utils import excutils from oslo_utils import excutils

@ -12,7 +12,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.
import logging from oslo_log import log as logging
from octavia.common import constants from octavia.common import constants
from octavia.common import data_models from octavia.common import data_models

@ -13,9 +13,9 @@
# under the License. # under the License.
# #
import logging
from oslo_config import cfg from oslo_config import cfg
from oslo_log import log as logging
from oslo_utils import excutils from oslo_utils import excutils
from sqlalchemy.orm import exc as db_exceptions from sqlalchemy.orm import exc as db_exceptions
from taskflow.listeners import logging as tf_logging from taskflow.listeners import logging as tf_logging

@ -14,7 +14,7 @@
""" Methods common to the controller work tasks.""" """ Methods common to the controller work tasks."""
import logging from oslo_log import log as logging
from octavia.common import constants from octavia.common import constants
from octavia.db import api as db_apis from octavia.db import api as db_apis

@ -13,9 +13,8 @@
# under the License. # under the License.
# #
import logging
from oslo_config import cfg from oslo_config import cfg
from oslo_log import log as logging
import six import six
from stevedore import driver as stevedore_driver from stevedore import driver as stevedore_driver
from taskflow import task from taskflow import task

@ -13,10 +13,10 @@
# under the License. # under the License.
# #
import logging
import time import time
from oslo_config import cfg from oslo_config import cfg
from oslo_log import log as logging
import six import six
from stevedore import driver as stevedore_driver from stevedore import driver as stevedore_driver
from taskflow import task from taskflow import task

@ -13,10 +13,9 @@
# under the License. # under the License.
# #
import logging
from oslo_config import cfg from oslo_config import cfg
from oslo_db import exception as odb_exceptions from oslo_db import exception as odb_exceptions
from oslo_log import log as logging
from oslo_utils import excutils from oslo_utils import excutils
from oslo_utils import uuidutils from oslo_utils import uuidutils
import six import six

@ -13,9 +13,8 @@
# under the License. # under the License.
# #
import logging
from oslo_config import cfg from oslo_config import cfg
from oslo_log import log as logging
import six import six
from taskflow import task from taskflow import task
from taskflow.types import failure from taskflow.types import failure

@ -14,7 +14,6 @@
from __future__ import with_statement from __future__ import with_statement
from logging import config as logging_config
import sys import sys
from alembic import context from alembic import context
@ -30,10 +29,6 @@ except AttributeError:
" alembic actions.") " alembic actions.")
sys.exit(1) sys.exit(1)
# Interpret the config file for Python logging.
# This line sets up loggers basically.
logging_config.fileConfig(config.config_file_name)
# add your model's MetaData object here # add your model's MetaData object here
# for 'autogenerate' support # for 'autogenerate' support
# from myapp import mymodel # from myapp import mymodel

@ -20,11 +20,15 @@ from alembic import config as alembic_cfg
from alembic import util as alembic_u from alembic import util as alembic_u
from oslo_config import cfg from oslo_config import cfg
from oslo_db import options from oslo_db import options
from oslo_log import log
from octavia.i18n import _ from octavia.i18n import _
CONF = cfg.CONF CONF = cfg.CONF
options.set_defaults(CONF) options.set_defaults(CONF)
log.set_defaults()
log.register_options(CONF)
log.setup(CONF, 'octavia-db-manage')
def do_alembic_command(config, cmd, *args, **kwargs): def do_alembic_command(config, cmd, *args, **kwargs):

@ -69,6 +69,7 @@ no_basestring_re = re.compile(r"\bbasestring\b")
no_iteritems_re = re.compile(r".*\.iteritems\(\)") no_iteritems_re = re.compile(r".*\.iteritems\(\)")
no_eventlet_re = re.compile(r'(import|from)\s+[(]?eventlet') no_eventlet_re = re.compile(r'(import|from)\s+[(]?eventlet')
no_line_continuation_backslash_re = re.compile(r'.*(\\)\n') no_line_continuation_backslash_re = re.compile(r'.*(\\)\n')
no_logging_re = re.compile(r'(import|from)\s+[(]?logging')
def _translation_checks_not_enforced(filename): def _translation_checks_not_enforced(filename):
@ -288,6 +289,19 @@ def revert_must_have_kwargs(logical_line):
yield 0, msg yield 0, msg
def check_no_logging_imports(logical_line):
"""O348 - Usage of Python logging module not allowed.
:param logical_line: The logical line to check.
:returns: None if the logical line passes the check, otherwise a tuple
is yielded that contains the offending index in logical line
and a message describe the check validation failure.
"""
if no_logging_re.match(logical_line):
msg = 'O348 Usage of Python logging module not allowed, use oslo_log'
yield logical_line.index('logging'), msg
def factory(register): def factory(register):
register(assert_true_instance) register(assert_true_instance)
register(assert_equal_or_not_none) register(assert_equal_or_not_none)
@ -304,3 +318,4 @@ def factory(register):
register(check_no_eventlet_imports) register(check_no_eventlet_imports)
register(check_line_continuation_no_backslash) register(check_line_continuation_no_backslash)
register(revert_must_have_kwargs) register(revert_must_have_kwargs)
register(check_no_logging_imports)

@ -12,10 +12,10 @@
"""Test of Policy Engine For Octavia.""" """Test of Policy Engine For Octavia."""
import logging
import tempfile import tempfile
from oslo_config import fixture as oslo_fixture from oslo_config import fixture as oslo_fixture
from oslo_log import log as logging
from oslo_policy import policy as oslo_policy from oslo_policy import policy as oslo_policy
import requests_mock import requests_mock