From 36ef23591de9571bc241a4ff0d81536c5f688996 Mon Sep 17 00:00:00 2001 From: TerryHowe Date: Thu, 13 Aug 2015 09:42:46 -0600 Subject: [PATCH] Keep a consistent logger name for keystoneauth As keystoneauth comes out with new releases, it would be convenient if the logger name did not change. Change-Id: Ica4102db27fa6cd2a3eaa1dac647abe02b4543a2 --- keystoneauth1/_utils.py | 7 ++++++- keystoneauth1/discover.py | 3 +-- keystoneauth1/identity/base.py | 3 +-- keystoneauth1/identity/generic/base.py | 4 ++-- keystoneauth1/identity/generic/password.py | 4 +--- keystoneauth1/identity/generic/token.py | 5 ++--- keystoneauth1/identity/v2.py | 3 +-- keystoneauth1/identity/v3/base.py | 3 +-- keystoneauth1/session.py | 2 +- keystoneauth1/tests/unit/test_utils.py | 22 ++++++++++++++++++++++ 10 files changed, 38 insertions(+), 18 deletions(-) create mode 100644 keystoneauth1/tests/unit/test_utils.py diff --git a/keystoneauth1/_utils.py b/keystoneauth1/_utils.py index 3cd73a90..a6466b9b 100644 --- a/keystoneauth1/_utils.py +++ b/keystoneauth1/_utils.py @@ -19,7 +19,12 @@ import iso8601 import six -logger = logging.getLogger(__name__) +def get_logger(name): + name = name.replace(__name__.split('.')[0], 'keystoneauth') + return logging.getLogger(name) + + +logger = get_logger(__name__) class positional(object): diff --git a/keystoneauth1/discover.py b/keystoneauth1/discover.py index ef31e801..4b05a70e 100644 --- a/keystoneauth1/discover.py +++ b/keystoneauth1/discover.py @@ -21,14 +21,13 @@ This includes functions like url_for which allow you to retrieve URLs and the raw data specified in version discovery responses. """ -import logging import re from keystoneauth1 import _utils as utils from keystoneauth1 import exceptions -_LOGGER = logging.getLogger(__name__) +_LOGGER = utils.get_logger(__name__) @utils.positional() diff --git a/keystoneauth1/identity/base.py b/keystoneauth1/identity/base.py index ca073386..78a02837 100644 --- a/keystoneauth1/identity/base.py +++ b/keystoneauth1/identity/base.py @@ -11,7 +11,6 @@ # under the License. import abc -import logging import six @@ -20,7 +19,7 @@ from keystoneauth1 import discover from keystoneauth1 import exceptions from keystoneauth1 import plugin -LOG = logging.getLogger(__name__) +LOG = utils.get_logger(__name__) @six.add_metaclass(abc.ABCMeta) diff --git a/keystoneauth1/identity/generic/base.py b/keystoneauth1/identity/generic/base.py index a71491af..4cbfbe36 100644 --- a/keystoneauth1/identity/generic/base.py +++ b/keystoneauth1/identity/generic/base.py @@ -11,17 +11,17 @@ # under the License. import abc -import logging import six import six.moves.urllib.parse as urlparse +from keystoneauth1 import _utils as utils from keystoneauth1 import discover from keystoneauth1 import exceptions from keystoneauth1.identity import base -LOG = logging.getLogger(__name__) +LOG = utils.get_logger(__name__) @six.add_metaclass(abc.ABCMeta) diff --git a/keystoneauth1/identity/generic/password.py b/keystoneauth1/identity/generic/password.py index daf2e63c..439553a0 100644 --- a/keystoneauth1/identity/generic/password.py +++ b/keystoneauth1/identity/generic/password.py @@ -10,15 +10,13 @@ # License for the specific language governing permissions and limitations # under the License. -import logging - from keystoneauth1 import _utils as utils from keystoneauth1 import discover from keystoneauth1.identity.generic import base from keystoneauth1.identity import v2 from keystoneauth1.identity import v3 -LOG = logging.getLogger(__name__) +LOG = utils.get_logger(__name__) class Password(base.BaseGenericPlugin): diff --git a/keystoneauth1/identity/generic/token.py b/keystoneauth1/identity/generic/token.py index 7bca2e66..2ed1cd9f 100644 --- a/keystoneauth1/identity/generic/token.py +++ b/keystoneauth1/identity/generic/token.py @@ -10,14 +10,13 @@ # License for the specific language governing permissions and limitations # under the License. -import logging - +from keystoneauth1 import _utils as utils from keystoneauth1 import discover from keystoneauth1.identity.generic import base from keystoneauth1.identity import v2 from keystoneauth1.identity import v3 -LOG = logging.getLogger(__name__) +LOG = utils.get_logger(__name__) class Token(base.BaseGenericPlugin): diff --git a/keystoneauth1/identity/v2.py b/keystoneauth1/identity/v2.py index e3d77ccb..d1331481 100644 --- a/keystoneauth1/identity/v2.py +++ b/keystoneauth1/identity/v2.py @@ -11,7 +11,6 @@ # under the License. import abc -import logging import six @@ -20,7 +19,7 @@ from keystoneauth1 import access from keystoneauth1 import exceptions from keystoneauth1.identity import base -_logger = logging.getLogger(__name__) +_logger = utils.get_logger(__name__) @six.add_metaclass(abc.ABCMeta) diff --git a/keystoneauth1/identity/v3/base.py b/keystoneauth1/identity/v3/base.py index 94967f02..60dbeced 100644 --- a/keystoneauth1/identity/v3/base.py +++ b/keystoneauth1/identity/v3/base.py @@ -11,7 +11,6 @@ # under the License. import abc -import logging import six @@ -20,7 +19,7 @@ from keystoneauth1 import access from keystoneauth1 import exceptions from keystoneauth1.identity import base -_logger = logging.getLogger(__name__) +_logger = utils.get_logger(__name__) __all__ = ['Auth', 'AuthMethod', 'AuthConstructor', 'BaseAuth'] diff --git a/keystoneauth1/session.py b/keystoneauth1/session.py index c92adbd6..93ef5aad 100644 --- a/keystoneauth1/session.py +++ b/keystoneauth1/session.py @@ -38,7 +38,7 @@ except ImportError: USER_AGENT = 'keystoneauth1' -_logger = logging.getLogger(__name__) +_logger = utils.get_logger(__name__) class _JSONEncoder(json.JSONEncoder): diff --git a/keystoneauth1/tests/unit/test_utils.py b/keystoneauth1/tests/unit/test_utils.py new file mode 100644 index 00000000..8ec9edc5 --- /dev/null +++ b/keystoneauth1/tests/unit/test_utils.py @@ -0,0 +1,22 @@ +# 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. + +import testtools + +from keystoneauth1 import _utils + + +class UtilsTests(testtools.TestCase): + + def test_get_logger(self): + self.assertEqual('keystoneauth.tests.unit.test_utils', + _utils.get_logger(__name__).name)