Skip to content

Commit

Permalink
Allow to set different log level
Browse files Browse the repository at this point in the history
  • Loading branch information
guerremdq committed Dec 19, 2023
1 parent f99ef24 commit 6651b43
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions trino/logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,22 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import os
import logging
from typing import Optional

LEVEL = logging.INFO
_level = os.environ.get('TRINO_LOGLEVEL', 'INFO')
if _level.upper() == _level and hasattr(logging, _level) and isinstance(getattr(logging, _level), int):
LEVEL = getattr(logging, _level)
elif _level == 'NONE':
LEVEL = None
else:
LEVEL = logging.INFO


# TODO: provide interface to use ``logging.dictConfig``
def get_logger(name: str, log_level: int = LEVEL) -> logging.Logger:
def get_logger(name: str, log_level: Optional[int] = LEVEL) -> logging.Logger:
logger = logging.getLogger(name)
logger.setLevel(log_level)
if log_level is not None:
logger.setLevel(log_level)
return logger

0 comments on commit 6651b43

Please sign in to comment.