mirror of
https://github.com/joaovitoriasilva/endurain.git
synced 2026-01-09 15:57:59 -05:00
Add print_to_console utility for console logging
Introduces the print_to_console function to print messages to the console at various log levels without writing to log files. This provides a simple way to output log messages directly to the console, complementing existing logging utilities.
This commit is contained in:
@@ -2,6 +2,7 @@ import logging
|
||||
|
||||
import core.config as core_config
|
||||
|
||||
|
||||
def setup_main_logger():
|
||||
"""
|
||||
Sets up the main application logger and attaches a file handler to it, as well as to the Alembic and APScheduler loggers.
|
||||
@@ -53,7 +54,9 @@ def get_main_logger():
|
||||
return logging.getLogger("main_logger")
|
||||
|
||||
|
||||
def print_to_log(message: str, log_level: str = "info", exc: Exception = None, context = None):
|
||||
def print_to_log(
|
||||
message: str, log_level: str = "info", exc: Exception = None, context=None
|
||||
):
|
||||
"""
|
||||
Logs a message at the specified log level using the main logger.
|
||||
|
||||
@@ -76,6 +79,24 @@ def print_to_log(message: str, log_level: str = "info", exc: Exception = None, c
|
||||
main_logger.debug(message)
|
||||
|
||||
|
||||
def print_to_console(message: str, log_level: str = "info"):
|
||||
"""
|
||||
Prints a message to the console only (without logging to file).
|
||||
|
||||
Args:
|
||||
message (str): The message to print.
|
||||
log_level (str, optional): The log level to display ('info', 'error', 'warning', 'debug'). Defaults to "info".
|
||||
"""
|
||||
if log_level == "info":
|
||||
print(f"INFO: {message}")
|
||||
elif log_level == "error":
|
||||
print(f"ERROR: {message}")
|
||||
elif log_level == "warning":
|
||||
print(f"WARNING: {message}")
|
||||
elif log_level == "debug":
|
||||
print(f"DEBUG: {message}")
|
||||
|
||||
|
||||
def print_to_log_and_console(
|
||||
message: str, log_level: str = "info", exc: Exception = None
|
||||
):
|
||||
|
||||
Reference in New Issue
Block a user