replace logging with oslo.log

If we use logging lib to initialize a logger, the logger won't be
applied the oslo.log config options.

Also the library oslo.log provides compatibility for log levels.

Change-Id: Ib36fb60b3eaa56413865ee46a20f11c520af7d8c
This commit is contained in:
ZhiQiang Fan 2016-04-25 23:01:06 +08:00
parent b155387cdd
commit 7539942f03
7 changed files with 16 additions and 20 deletions

View File

@ -10,8 +10,7 @@
# License for the specific language governing permissions and limitations
# under the License.
import logging
from oslo_log import log
import oslo_messaging
import osprofiler.notifier
import osprofiler.web
@ -21,7 +20,7 @@ from keystone.i18n import _LI
CONF = config.CONF
LOG = logging.getLogger(__name__)
LOG = log.getLogger(__name__)
def setup(name, host='0.0.0.0'): # nosec

View File

@ -17,7 +17,6 @@
import collections
import functools
import inspect
import logging
import socket
from oslo_config import cfg
@ -246,7 +245,7 @@ def register_event_callback(event, resource_type, callbacks):
_SUBSCRIBERS.setdefault(event, {}).setdefault(resource_type, set())
_SUBSCRIBERS[event][resource_type].add(callback)
if LOG.logger.getEffectiveLevel() <= logging.DEBUG:
if LOG.logger.getEffectiveLevel() <= log.DEBUG:
# Do this only if its going to appear in the logs.
msg = 'Callback: `%(callback)s` subscribed to event `%(event)s`.'
callback_info = _get_callback_info(callback)

View File

@ -12,11 +12,11 @@
# License for the specific language governing permissions and limitations
# under the License.
import logging
import os
from oslo_config import cfg
import oslo_i18n
from oslo_log import log
from keystone.common import profiler
@ -46,7 +46,7 @@ def initialize_application(name,
# Log the options used when starting if we're in debug mode...
if CONF.debug:
CONF.log_opt_values(logging.getLogger(CONF.prog), logging.DEBUG)
CONF.log_opt_values(log.getLogger(CONF.prog), log.DEBUG)
post_log_configured_function()

View File

@ -12,13 +12,13 @@
# License for the specific language governing permissions and limitations
# under the License.
import logging
import uuid
import fixtures
import mock
from oslo_config import cfg
from oslo_config import fixture as config_fixture
from oslo_log import log
from pycadf import cadftaxonomy
from pycadf import cadftype
from pycadf import eventfactory
@ -1158,7 +1158,7 @@ class TestCallbackRegistration(unit.BaseTestCase):
super(TestCallbackRegistration, self).setUp()
self.mock_log = mock.Mock()
# Force the callback logging to occur
self.mock_log.logger.getEffectiveLevel.return_value = logging.DEBUG
self.mock_log.logger.getEffectiveLevel.return_value = log.DEBUG
def verify_log_message(self, data):
"""Verify log message.

View File

@ -20,7 +20,6 @@ import functools
import hashlib
import json
import ldap
import logging
import os
import re
import shutil
@ -655,7 +654,7 @@ class TestCase(BaseTestCase):
# NOTE(morganfainberg): ensure config_overrides has been called.
self.addCleanup(self._assert_config_overrides_called)
self.useFixture(fixtures.FakeLogger(level=logging.DEBUG))
self.useFixture(fixtures.FakeLogger(level=log.DEBUG))
# NOTE(morganfainberg): This code is a copy from the oslo-incubator
# log module. This is not in a function or otherwise available to use
@ -664,8 +663,8 @@ class TestCase(BaseTestCase):
# would run under mod_wsgi).
for pair in CONF.default_log_levels:
mod, _sep, level_name = pair.partition('=')
logger = logging.getLogger(mod)
logger.setLevel(level_name)
logger = log.getLogger(mod)
logger.logger.setLevel(level_name)
self.useFixture(ksfixtures.Cache())

View File

@ -12,7 +12,6 @@
# License for the specific language governing permissions and limitations
# under the License.
import logging
import os
import uuid
@ -20,6 +19,7 @@ import fixtures
import mock
from oslo_config import cfg
from oslo_config import fixture as config_fixture
from oslo_log import log
from oslotest import mockpatch
from six.moves import range
from testtools import matchers
@ -64,8 +64,7 @@ class CliNoConfigTestCase(unit.BaseTestCase):
self.useFixture(mockpatch.PatchObject(
CONF, 'command', FakeConfCommand()))
self.logging = self.useFixture(
fixtures.FakeLogger(level=logging.WARN))
self.logging = self.useFixture(fixtures.FakeLogger(level=log.WARN))
def test_cli(self):
expected_msg = 'Config file not found, using default configs.'

View File

@ -12,12 +12,12 @@
# License for the specific language governing permissions and limitations
# under the License.
import logging
import uuid
import fixtures
import mock
from oslo_config import cfg
from oslo_log import log
from six.moves import http_client
from testtools import matchers
@ -596,7 +596,7 @@ class IdentityTestCase(test_v3.RestfulTestCase):
def test_create_user_password_not_logged(self):
# When a user is created, the password isn't logged at any level.
log_fix = self.useFixture(fixtures.FakeLogger(level=logging.DEBUG))
log_fix = self.useFixture(fixtures.FakeLogger(level=log.DEBUG))
ref = unit.new_user_ref(domain_id=self.domain_id)
self.post(
@ -609,7 +609,7 @@ class IdentityTestCase(test_v3.RestfulTestCase):
# When admin modifies user password, the password isn't logged at any
# level.
log_fix = self.useFixture(fixtures.FakeLogger(level=logging.DEBUG))
log_fix = self.useFixture(fixtures.FakeLogger(level=log.DEBUG))
# bootstrap a user as admin
user_ref = unit.create_user(self.identity_api,
@ -794,7 +794,7 @@ class UserSelfServiceChangingPasswordsTestCase(test_v3.RestfulTestCase):
# When a user changes their password, the password isn't logged at any
# level.
log_fix = self.useFixture(fixtures.FakeLogger(level=logging.DEBUG))
log_fix = self.useFixture(fixtures.FakeLogger(level=log.DEBUG))
# change password
new_password = uuid.uuid4().hex