Skip to content

Commit

Permalink
Improve existing_handlers
Browse files Browse the repository at this point in the history
  • Loading branch information
JINWOO-J committed Nov 25, 2024
1 parent 5da89c5 commit 50cff9d
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 11 deletions.
6 changes: 3 additions & 3 deletions BUILD_ARGS
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@

--build-arg BASE_IMAGE=python:3.9.13-slim-buster
--build-arg BUILD_DATE=2024-11-25T00:37:29UTC
--build-arg BUILD_DATE=2024-11-25T05:01:50UTC
--build-arg DOCKER_BUILD_OPTION=--no-cache --rm=true
--build-arg ECHO_OPTION=
--build-arg GIT_USER=JINWOO-J
--build-arg IS_MULTI_ARCH=false
--build-arg LOCAL_SERVER=asweenter-oracle
--build-arg LOCAL_SERVER=20.20.5.172
--build-arg NAME=pawnlib
--build-arg PRIMARY_BRANCH=master
--build-arg REPO_HUB=jinwoo
--build-arg SED_OPTION=''
--build-arg UNAME_S=Darwin
--build-arg VERSION=2.0.74
--build-arg VERSION=2.0.76
1 change: 1 addition & 0 deletions last_blockheight.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0x55c29e5
2 changes: 1 addition & 1 deletion pawnlib/__version__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
__title__ = 'pawnlib'
__description__ = 'pawnlib is a collection of libraries for IaC.'
__url__ = 'https://github.com/jinwoo-j/pawnlib'
__version__ = '2.0.76'
__version__ = '2.0.77'
__author__ = 'Jinwoo Jeong'
__author_email__ = 'jinwoo@parametacorp.com'
__license__ = 'MIT'
Expand Down
15 changes: 8 additions & 7 deletions pawnlib/config/logging_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -850,7 +850,8 @@ def setup_app_logger(
exc_info: bool = False,
rotate_time: str = 'midnight', # Log rotation time (e.g., 'midnight', 'H', etc.)
rotate_interval: int = 1, # Rotation interval (e.g., 1 day, 1 hour)
backup_count: int = 7 # Number of backup files to keep
backup_count: int = 7, # Number of backup files to keep
clear_existing_handlers: bool = False,
):
"""
Configures the application logger with specified settings.
Expand Down Expand Up @@ -885,13 +886,13 @@ def setup_app_logger(
:type rotate_interval: int
:param backup_count: Number of backup files to retain.
:type backup_count: int
:param clear_existing_handlers: Whether to clear existing handlers before adding new ones.
:type clear_existing_handlers: bool
Example:
.. code-block:: python
from pawnlib.config import setup_app_logger
# Set up a console logger with DEBUG level
setup_app_logger(
log_type='console',
Expand Down Expand Up @@ -947,9 +948,10 @@ def setup_app_logger(
if not log_format:
log_format = '[%(asctime)s] %(levelname)s::%(filename)s/%(funcName)s(%(lineno)d) %(message)s'

existing_handler_types = {type(h) for h in root_logger.handlers}
if clear_existing_handlers:
root_logger.handlers.clear()

if log_type in ('console', 'both') and ConsoleLoggerHandler not in existing_handler_types:
if log_type in ('console', 'both') and not any(isinstance(h, ConsoleLoggerHandler) for h in root_logger.handlers):
console_handler = ConsoleLoggerHandler(
verbose=verbose,
stdout=True,
Expand All @@ -958,7 +960,6 @@ def setup_app_logger(
exc_info=exc_info
)
console_formatter = CleanAndDetailTimeFormatter(
# fmt=log_format,
datefmt=date_format,
log_level_short=log_level_short,
simple_format=simple_format,
Expand All @@ -967,7 +968,7 @@ def setup_app_logger(
console_handler.setFormatter(console_formatter)
root_logger.addHandler(console_handler)

if log_type in ('file', 'both') and TimedRotatingFileHandler not in existing_handler_types:
if log_type in ('file', 'both') and not any(isinstance(h, TimedRotatingFileHandler) for h in root_logger.handlers):
file_formatter = CleanAndDetailTimeFormatter(
fmt=log_format,
datefmt=date_format,
Expand Down

0 comments on commit 50cff9d

Please sign in to comment.