Skip to content

Commit

Permalink
Logger handled
Browse files Browse the repository at this point in the history
  • Loading branch information
DeepBlockDeepak committed Nov 27, 2023
1 parent 2842e93 commit 5b47218
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions app/log_manager.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,26 @@
import logging
from logging.handlers import RotatingFileHandler

LOGGING_LEVEL = (
logging.INFO
) # (DEBUG, INFO, WARNING, ERROR, CRITICAL) Shows all levels at or above selected

# Set the logging level here (DEBUG, INFO, WARNING, ERROR, CRITICAL)
LOGGING_LEVEL = logging.INFO

# Configure global logger
global_logger = logging.getLogger(__name__)
global_logger.setLevel(LOGGING_LEVEL)
log_format = logging.Formatter("[%(asctime)s] [%(module)s/%(levelname)s]: %(message)s")

file_handler = logging.FileHandler("runtime.log")
# Log format to include timestamp, logger name, log level, and message
log_format = logging.Formatter(
"[%(asctime)s] [%(name)s/%(levelname)s]: %(message)s", "%Y-%m-%d %H:%M:%S"
)

# File handler with log rotation
file_handler = RotatingFileHandler("runtime.log", maxBytes=1048576, backupCount=5)
file_handler.setFormatter(log_format)

# Console handler to output logs to the console
console_handler = logging.StreamHandler()
console_handler.setFormatter(log_format)

# Add handlers to the global logger
global_logger.addHandler(file_handler)
global_logger.addHandler(console_handler)

0 comments on commit 5b47218

Please sign in to comment.