From 063b2bd958d84b32ff0e9513174a072b085c8685 Mon Sep 17 00:00:00 2001 From: Greg Leclercq Date: Thu, 31 Aug 2017 14:11:22 -0700 Subject: [PATCH] Add logging module --- integration_tests/fixtures.py | 4 ++-- prestodb/__init__.py | 1 + prestodb/client.py | 5 ++--- prestodb/dbapi.py | 4 ++-- prestodb/exceptions.py | 4 ++-- prestodb/logging.py | 25 +++++++++++++++++++++++++ 6 files changed, 34 insertions(+), 9 deletions(-) create mode 100644 prestodb/logging.py diff --git a/integration_tests/fixtures.py b/integration_tests/fixtures.py index f6276f4..a9708c7 100644 --- a/integration_tests/fixtures.py +++ b/integration_tests/fixtures.py @@ -14,7 +14,6 @@ from __future__ import print_function from contextlib import closing -import logging import os import requests import socket @@ -28,9 +27,10 @@ from prestodb.client import PrestoQuery, PrestoRequest from prestodb.constants import DEFAULT_PORT +import prestodb.logging -logger = logging.getLogger(__name__) +logger = prestodb.logging.get_logger(__name__) def get_latest_release(): diff --git a/prestodb/__init__.py b/prestodb/__init__.py index cbee9db..d9415ab 100644 --- a/prestodb/__init__.py +++ b/prestodb/__init__.py @@ -16,5 +16,6 @@ from . import dbapi from . import client from . import constants +from . import logging __version__ = '0.3.0' diff --git a/prestodb/client.py b/prestodb/client.py index f79b033..3183c30 100644 --- a/prestodb/client.py +++ b/prestodb/client.py @@ -36,7 +36,6 @@ from __future__ import division from __future__ import print_function -import logging import os from requests_kerberos.exceptions import KerberosExchangeError from typing import Any, Dict, List, Optional, Text, Tuple, Union # NOQA for mypy types @@ -45,14 +44,14 @@ from prestodb import constants from prestodb import exceptions +import prestodb.logging import prestodb.redirect __all__ = ['PrestoQuery', 'PrestoRequest'] -logger = logging.getLogger(__name__) -logger.setLevel(logging.INFO) +logger = prestodb.logging.get_logger(__name__) MAX_ATTEMPTS = constants.DEFAULT_MAX_ATTEMPTS diff --git a/prestodb/dbapi.py b/prestodb/dbapi.py index 5dcf86f..b9e9b75 100644 --- a/prestodb/dbapi.py +++ b/prestodb/dbapi.py @@ -23,13 +23,13 @@ from future.standard_library import install_aliases install_aliases() -import logging from typing import Any, List, Optional # NOQA for mypy types from prestodb import constants import prestodb.exceptions import prestodb.client +import prestodb.logging import prestodb.redirect @@ -39,7 +39,7 @@ apilevel = '2.0' threadsafety = 2 -logger = logging.getLogger(__name__) +logger = prestodb.logging.get_logger(__name__) class Error(Exception): diff --git a/prestodb/exceptions.py b/prestodb/exceptions.py index 417b176..32c5387 100644 --- a/prestodb/exceptions.py +++ b/prestodb/exceptions.py @@ -20,12 +20,12 @@ from __future__ import print_function import functools -import logging import random import time +import prestodb.logging -logger = logging.getLogger(__name__) +logger = prestodb.logging.get_logger(__name__) class HttpError(Exception): diff --git a/prestodb/logging.py b/prestodb/logging.py new file mode 100644 index 0000000..c440369 --- /dev/null +++ b/prestodb/logging.py @@ -0,0 +1,25 @@ +# 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. +from __future__ import absolute_import +from __future__ import division +from __future__ import print_function + +import logging + +LEVEL = logging.INFO + + +# TODO: provide interface to use ``logging.dictConfig`` +def get_logger(name, log_level=LEVEL): + logger = logging.getLogger(name) + logger.setLevel(log_level) + return logger