Skip to content

Commit

Permalink
fix the logger to name 'pe' instead of using the root logger
Browse files Browse the repository at this point in the history
  • Loading branch information
fjxmlzn committed Jan 11, 2025
1 parent 5b1bc74 commit 8aba343
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions pe/logging/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,38 @@
import os

#: The logger that will be used to log the execution information
execution_logger = logging.getLogger()
execution_logger = logging.getLogger("pe")


def setup_logging(
log_file=None,
log_screen=True,
datefmt="%m/%d/%Y %H:%M:%S %p",
fmt="%(asctime)s [%(name)s] [%(levelname)-5.5s] %(message)s",
level=logging.INFO,
name="logger",
):
"""Setup the logging configuration.
:param log_file: The log file path, defaults to None
:type log_file: str, optional
:param log_screen: Whether to log to the screen, defaults to True
:type log_screen: bool, optional
:param datefmt: The date format, defaults to "%m/%d/%Y %H:%M:%S %p"
:type datefmt: str, optional
:param fmt: The log format, defaults to "%(asctime)s [%(name)s] [%(levelname)-5.5s] %(message)s"
:type fmt: str, optional
:param level: The log level, defaults to logging.INFO
:type level: int, optional
:param name: The logger name, defaults to "logger"
:type name: str, optional
"""
execution_logger.name = name

execution_logger.handlers.clear()
execution_logger.setLevel(level)

log_formatter = logging.Formatter(fmt=fmt, datefmt=datefmt)

console_handler = logging.StreamHandler()
console_handler.setFormatter(log_formatter)
execution_logger.addHandler(console_handler)
if log_screen:
console_handler = logging.StreamHandler()
console_handler.setFormatter(log_formatter)
execution_logger.addHandler(console_handler)

if log_file is not None:
os.makedirs(os.path.dirname(log_file), exist_ok=True)
Expand Down

0 comments on commit 8aba343

Please sign in to comment.