diff options
author | Ib Lundgren <ib.lundgren@gmail.com> | 2014-09-24 14:52:53 +0100 |
---|---|---|
committer | Ib Lundgren <ib.lundgren@gmail.com> | 2014-09-24 14:52:53 +0100 |
commit | edab385f951e38d65a25003f193793b63037bdec (patch) | |
tree | 0c5658eacb8aeca13556314cd0cffdf1db88f5c9 /oauthlib | |
parent | 3bb2bfbb593386169e997e3332b236c077a546db (diff) | |
download | oauthlib-edab385f951e38d65a25003f193793b63037bdec.tar.gz |
Change logging namespace to a tiered one.
Rather than have all logging under oauthlib we now have it
per file using __name__. Users who wish to enable or disable
all logging can still do so by enabling or disabling the
oauthlib logging namespace.
Diffstat (limited to 'oauthlib')
20 files changed, 83 insertions, 36 deletions
diff --git a/oauthlib/__init__.py b/oauthlib/__init__.py index b043a5a..c70b46a 100644 --- a/oauthlib/__init__.py +++ b/oauthlib/__init__.py @@ -11,3 +11,14 @@ __author__ = 'Idan Gazit <idan@gazit.me>' __version__ = '0.6.3' + + +import logging +try: # Python 2.7+ + from logging import NullHandler +except ImportError: + class NullHandler(logging.Handler): + def emit(self, record): + pass + +logging.getLogger('oauthlib').addHandler(NullHandler()) diff --git a/oauthlib/common.py b/oauthlib/common.py index 2ffdea9..9e8c175 100644 --- a/oauthlib/common.py +++ b/oauthlib/common.py @@ -10,7 +10,6 @@ from __future__ import absolute_import, unicode_literals import collections import datetime -import logging import random import re import sys @@ -43,20 +42,6 @@ always_safe = ('ABCDEFGHIJKLMNOPQRSTUVWXYZ' PY3 = sys.version_info[0] == 3 -# Logger used throughout oauthlib -log = logging.getLogger('oauthlib') -# Add a NullHandler to prevent warnings for users who don't wish -# to configure logging. -try: - log.addHandler(logging.NullHandler()) -# NullHandler gracefully backported to 2.6 -except AttributeError: - class NullHandler(logging.Handler): - - def emit(self, record): - pass - log.addHandler(NullHandler()) - if PY3: unicode_type = str bytes_type = bytes diff --git a/oauthlib/oauth1/rfc5849/__init__.py b/oauthlib/oauth1/rfc5849/__init__.py index 405bf1f..fbf6429 100644 --- a/oauthlib/oauth1/rfc5849/__init__.py +++ b/oauthlib/oauth1/rfc5849/__init__.py @@ -9,7 +9,7 @@ for signing and checking OAuth 1.0 RFC 5849 requests. from __future__ import absolute_import, unicode_literals import logging -log = logging.getLogger("oauthlib") +log = logging.getLogger(__name__) import sys try: diff --git a/oauthlib/oauth1/rfc5849/endpoints/access_token.py b/oauthlib/oauth1/rfc5849/endpoints/access_token.py index 3ea010d..f3139fb 100644 --- a/oauthlib/oauth1/rfc5849/endpoints/access_token.py +++ b/oauthlib/oauth1/rfc5849/endpoints/access_token.py @@ -10,11 +10,15 @@ returned to the client. """ from __future__ import absolute_import, unicode_literals -from oauthlib.common import log, urlencode +import logging + +from oauthlib.common import urlencode from .base import BaseEndpoint from .. import errors +log = logging.getLogger(__name__) + class AccessTokenEndpoint(BaseEndpoint): """An endpoint responsible for providing OAuth 1 access tokens. diff --git a/oauthlib/oauth1/rfc5849/endpoints/request_token.py b/oauthlib/oauth1/rfc5849/endpoints/request_token.py index 8aabc25..9424b9d 100644 --- a/oauthlib/oauth1/rfc5849/endpoints/request_token.py +++ b/oauthlib/oauth1/rfc5849/endpoints/request_token.py @@ -10,11 +10,15 @@ returned to the client. """ from __future__ import absolute_import, unicode_literals -from oauthlib.common import log, urlencode +import logging + +from oauthlib.common import urlencode from .base import BaseEndpoint from .. import errors +log = logging.getLogger(__name__) + class RequestTokenEndpoint(BaseEndpoint): """An endpoint responsible for providing OAuth 1 request tokens. diff --git a/oauthlib/oauth1/rfc5849/endpoints/resource.py b/oauthlib/oauth1/rfc5849/endpoints/resource.py index 7cbfb56..00b5c5f 100644 --- a/oauthlib/oauth1/rfc5849/endpoints/resource.py +++ b/oauthlib/oauth1/rfc5849/endpoints/resource.py @@ -8,11 +8,13 @@ OAuth 1.0 RFC 5849. """ from __future__ import absolute_import, unicode_literals -from oauthlib.common import log +import logging from .base import BaseEndpoint from .. import errors +log = logging.getLogger(__name__) + class ResourceEndpoint(BaseEndpoint): """An endpoint responsible for protecting resources. diff --git a/oauthlib/oauth1/rfc5849/endpoints/signature_only.py b/oauthlib/oauth1/rfc5849/endpoints/signature_only.py index 33dc83d..0cdcdd3 100644 --- a/oauthlib/oauth1/rfc5849/endpoints/signature_only.py +++ b/oauthlib/oauth1/rfc5849/endpoints/signature_only.py @@ -8,11 +8,13 @@ This module is an implementation of the signing logic of OAuth 1.0 RFC 5849. from __future__ import absolute_import, unicode_literals -from oauthlib.common import log +import logging from .base import BaseEndpoint from .. import errors +log = logging.getLogger(__name__) + class SignatureOnlyEndpoint(BaseEndpoint): """An endpoint only responsible for verifying an oauth signature.""" diff --git a/oauthlib/oauth2/rfc6749/__init__.py b/oauthlib/oauth2/rfc6749/__init__.py index a871ced..05a7601 100644 --- a/oauthlib/oauth2/rfc6749/__init__.py +++ b/oauthlib/oauth2/rfc6749/__init__.py @@ -9,12 +9,15 @@ for consuming and providing OAuth 2.0 RFC6749. from __future__ import absolute_import, unicode_literals import functools +import logging -from oauthlib.common import log from .errors import TemporarilyUnavailableError, ServerError from .errors import FatalClientError, OAuth2Error +log = logging.getLogger(__name__) + + class BaseEndpoint(object): def __init__(self): self._available = True diff --git a/oauthlib/oauth2/rfc6749/endpoints/authorization.py b/oauthlib/oauth2/rfc6749/endpoints/authorization.py index 3b59bee..4244a88 100644 --- a/oauthlib/oauth2/rfc6749/endpoints/authorization.py +++ b/oauthlib/oauth2/rfc6749/endpoints/authorization.py @@ -8,10 +8,14 @@ for consuming and providing OAuth 2.0 RFC6749. """ from __future__ import absolute_import, unicode_literals -from oauthlib.common import Request, log +import logging + +from oauthlib.common import Request from .base import BaseEndpoint, catch_errors_and_unavailability +log = logging.getLogger(__name__) + class AuthorizationEndpoint(BaseEndpoint): """Authorization endpoint - used by the client to obtain authorization diff --git a/oauthlib/oauth2/rfc6749/endpoints/base.py b/oauthlib/oauth2/rfc6749/endpoints/base.py index e66ab75..24f00d9 100644 --- a/oauthlib/oauth2/rfc6749/endpoints/base.py +++ b/oauthlib/oauth2/rfc6749/endpoints/base.py @@ -9,12 +9,13 @@ for consuming and providing OAuth 2.0 RFC6749. from __future__ import absolute_import, unicode_literals import functools - -from oauthlib.common import log +import logging from ..errors import TemporarilyUnavailableError, ServerError from ..errors import FatalClientError, OAuth2Error +log = logging.getLogger(__name__) + class BaseEndpoint(object): def __init__(self): diff --git a/oauthlib/oauth2/rfc6749/endpoints/resource.py b/oauthlib/oauth2/rfc6749/endpoints/resource.py index afe5f74..ee23d35 100644 --- a/oauthlib/oauth2/rfc6749/endpoints/resource.py +++ b/oauthlib/oauth2/rfc6749/endpoints/resource.py @@ -8,10 +8,14 @@ for consuming and providing OAuth 2.0 RFC6749. """ from __future__ import absolute_import, unicode_literals -from oauthlib.common import Request, log +import logging + +from oauthlib.common import Request from .base import BaseEndpoint, catch_errors_and_unavailability +log = logging.getLogger(__name__) + class ResourceEndpoint(BaseEndpoint): """Authorizes access to protected resources. diff --git a/oauthlib/oauth2/rfc6749/endpoints/revocation.py b/oauthlib/oauth2/rfc6749/endpoints/revocation.py index fcdeb98..45e8080 100644 --- a/oauthlib/oauth2/rfc6749/endpoints/revocation.py +++ b/oauthlib/oauth2/rfc6749/endpoints/revocation.py @@ -9,12 +9,16 @@ An implementation of the OAuth 2 `Token Revocation`_ spec (draft 11). """ from __future__ import absolute_import, unicode_literals -from oauthlib.common import Request, log +import logging + +from oauthlib.common import Request from .base import BaseEndpoint, catch_errors_and_unavailability from ..errors import InvalidClientError, UnsupportedTokenTypeError from ..errors import InvalidRequestError, OAuth2Error +log = logging.getLogger(__name__) + class RevocationEndpoint(BaseEndpoint): """Token revocation endpoint. diff --git a/oauthlib/oauth2/rfc6749/endpoints/token.py b/oauthlib/oauth2/rfc6749/endpoints/token.py index 68d36ca..267490f 100644 --- a/oauthlib/oauth2/rfc6749/endpoints/token.py +++ b/oauthlib/oauth2/rfc6749/endpoints/token.py @@ -8,11 +8,16 @@ for consuming and providing OAuth 2.0 RFC6749. """ from __future__ import absolute_import, unicode_literals -from oauthlib.common import Request, log +import logging + +from oauthlib.common import Request from .base import BaseEndpoint, catch_errors_and_unavailability +log = logging.getLogger(__name__) + + class TokenEndpoint(BaseEndpoint): """Token issuing endpoint. diff --git a/oauthlib/oauth2/rfc6749/grant_types/authorization_code.py b/oauthlib/oauth2/rfc6749/grant_types/authorization_code.py index 1d84337..65e9c65 100644 --- a/oauthlib/oauth2/rfc6749/grant_types/authorization_code.py +++ b/oauthlib/oauth2/rfc6749/grant_types/authorization_code.py @@ -4,16 +4,19 @@ oauthlib.oauth2.rfc6749.grant_types ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ """ from __future__ import unicode_literals, absolute_import + import json +import logging from oauthlib import common -from oauthlib.common import log from oauthlib.uri_validate import is_absolute_uri from .base import GrantTypeBase from .. import errors from ..request_validator import RequestValidator +log = logging.getLogger(__name__) + class AuthorizationCodeGrant(GrantTypeBase): """`Authorization Code Grant`_ diff --git a/oauthlib/oauth2/rfc6749/grant_types/base.py b/oauthlib/oauth2/rfc6749/grant_types/base.py index a3dd87c..9121580 100644 --- a/oauthlib/oauth2/rfc6749/grant_types/base.py +++ b/oauthlib/oauth2/rfc6749/grant_types/base.py @@ -5,9 +5,12 @@ oauthlib.oauth2.rfc6749.grant_types """ from __future__ import unicode_literals, absolute_import -from oauthlib.common import log +import logging + from oauthlib.oauth2.rfc6749 import errors, utils +log = logging.getLogger(__name__) + class GrantTypeBase(object): error_uri = None diff --git a/oauthlib/oauth2/rfc6749/grant_types/client_credentials.py b/oauthlib/oauth2/rfc6749/grant_types/client_credentials.py index 9bc2c8f..9437b11 100644 --- a/oauthlib/oauth2/rfc6749/grant_types/client_credentials.py +++ b/oauthlib/oauth2/rfc6749/grant_types/client_credentials.py @@ -4,13 +4,16 @@ oauthlib.oauth2.rfc6749.grant_types ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ """ from __future__ import unicode_literals, absolute_import + import json -from oauthlib.common import log +import logging from .base import GrantTypeBase from .. import errors from ..request_validator import RequestValidator +log = logging.getLogger(__name__) + class ClientCredentialsGrant(GrantTypeBase): """`Client Credentials Grant`_ diff --git a/oauthlib/oauth2/rfc6749/grant_types/implicit.py b/oauthlib/oauth2/rfc6749/grant_types/implicit.py index fcdb606..c3335af 100644 --- a/oauthlib/oauth2/rfc6749/grant_types/implicit.py +++ b/oauthlib/oauth2/rfc6749/grant_types/implicit.py @@ -4,14 +4,18 @@ oauthlib.oauth2.rfc6749.grant_types ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ """ from __future__ import unicode_literals, absolute_import + +import logging + from oauthlib import common -from oauthlib.common import log from oauthlib.uri_validate import is_absolute_uri from .base import GrantTypeBase from .. import errors from ..request_validator import RequestValidator +log = logging.getLogger(__name__) + class ImplicitGrant(GrantTypeBase): """`Implicit Grant`_ diff --git a/oauthlib/oauth2/rfc6749/grant_types/refresh_token.py b/oauthlib/oauth2/rfc6749/grant_types/refresh_token.py index 51b6487..f6c27ea 100644 --- a/oauthlib/oauth2/rfc6749/grant_types/refresh_token.py +++ b/oauthlib/oauth2/rfc6749/grant_types/refresh_token.py @@ -4,14 +4,16 @@ oauthlib.oauth2.rfc6749.grant_types ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ """ from __future__ import unicode_literals, absolute_import -import json -from oauthlib.common import log +import json +import logging from .base import GrantTypeBase from .. import errors, utils from ..request_validator import RequestValidator +log = logging.getLogger(__name__) + class RefreshTokenGrant(GrantTypeBase): """`Refresh token grant`_ diff --git a/oauthlib/oauth2/rfc6749/grant_types/resource_owner_password_credentials.py b/oauthlib/oauth2/rfc6749/grant_types/resource_owner_password_credentials.py index ae73d31..07aa9c1 100644 --- a/oauthlib/oauth2/rfc6749/grant_types/resource_owner_password_credentials.py +++ b/oauthlib/oauth2/rfc6749/grant_types/resource_owner_password_credentials.py @@ -4,13 +4,16 @@ oauthlib.oauth2.rfc6749.grant_types ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ """ from __future__ import unicode_literals, absolute_import + import json -from oauthlib.common import log +import logging from .base import GrantTypeBase from .. import errors from ..request_validator import RequestValidator +log = logging.getLogger(__name__) + class ResourceOwnerPasswordCredentialsGrant(GrantTypeBase): """`Resource Owner Password Credentials Grant`_ diff --git a/oauthlib/oauth2/rfc6749/request_validator.py b/oauthlib/oauth2/rfc6749/request_validator.py index a66ddc2..01e025d 100644 --- a/oauthlib/oauth2/rfc6749/request_validator.py +++ b/oauthlib/oauth2/rfc6749/request_validator.py @@ -4,10 +4,10 @@ oauthlib.oauth2.rfc6749.grant_types ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ """ from __future__ import unicode_literals, absolute_import -import logging +import logging -log = logging.getLogger('oauthlib') +log = logging.getLogger(__name__) class RequestValidator(object): |