Skip to content

Commit fde7559

Browse files
committed
docs: add docstrings to LogManager
1 parent 8fd896b commit fde7559

1 file changed

Lines changed: 23 additions & 1 deletion

File tree

manager/ram_logging/log_manager.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
"""
2+
LogManager singleton for managing application logging.
3+
4+
Has support for colored and length-limited log formatting.
5+
"""
6+
17
import logging
28
import os
39

@@ -6,6 +12,8 @@
612

713
# Clase para un Formatter personalizado que añade colores
814
class ColorFormatter(logging.Formatter):
15+
"""Custom formatter that adds colors to log messages based on their log level."""
16+
917
# Diccionario de colores para diferentes niveles de log
1018
COLORS = {
1119
logging.ERROR: "\033[91m", # Rojo para errores
@@ -16,6 +24,7 @@ class ColorFormatter(logging.Formatter):
1624
RESET = "\033[0m" # Resetear a color por defecto
1725

1826
def format(self, record):
27+
"""Format the log record with color based on its log level."""
1928
color = self.COLORS.get(record.levelno)
2029
message = super().format(record)
2130
if color:
@@ -24,6 +33,8 @@ def format(self, record):
2433

2534

2635
class MaxLengthColorFormatter(logging.Formatter):
36+
"""Custom formatter that adds colors and limits log message length."""
37+
2738
# Diccionario de colores para diferentes niveles de log
2839
COLORS = {
2940
logging.ERROR: "\033[91m", # Rojo para errores
@@ -35,6 +46,7 @@ class MaxLengthColorFormatter(logging.Formatter):
3546
MAX_LENGTH = 1000
3647

3748
def format(self, record):
49+
"""Format the log record with color and limit its length."""
3850
color = self.COLORS.get(record.levelno)
3951
msg = super().format(record)
4052
if color:
@@ -50,13 +62,23 @@ def format(self, record):
5062

5163
@singleton
5264
class LogManager:
65+
"""Singleton class for managing application logging."""
66+
5367
def __init__(self):
68+
"""
69+
Initialize the LogManager.
70+
71+
Sets up file and console logging handlers with appropriate formatters.
72+
"""
5473
log_path = os.getcwd()
5574
log_level = logging.INFO
5675
log_to_console = True
5776

5877
self.log_file = os.path.join(log_path, "ram.log")
59-
log_format = "%(asctime)s [%(threadName)-12.12s] [%(levelname)-5.5s] (%(name)s) %(message)s"
78+
log_format = (
79+
"%(asctime)s [%(threadName)-12.12s] [%(levelname)-5.5s] "
80+
"(%(name)s) %(message)s"
81+
)
6082
date_format = "%H:%M:%S"
6183
self.log_formatter = logging.Formatter(log_format, date_format)
6284
self.color_formatter = ColorFormatter(

0 commit comments

Comments
 (0)