Move CustomLoggerFormatter to utils.py and update imports

This commit is contained in:
Rafael Moraes
2025-10-23 14:03:14 -03:00
parent 243b3ea45c
commit ef2f0a56ae
3 changed files with 31 additions and 32 deletions
+1 -2
View File
@@ -29,8 +29,7 @@ from ..interface import (
UploadedVideoQuality,
)
from .constants import X_NOT_IN_PATH
from .custom_logger_formatter import CustomLoggerFormatter
from .utils import Csv, PathPrompt, load_config_file, make_sync
from .utils import Csv, CustomLoggerFormatter, PathPrompt, load_config_file, make_sync
logger = logging.getLogger(__name__)
-30
View File
@@ -1,30 +0,0 @@
import logging
import click
class CustomLoggerFormatter(logging.Formatter):
base_format = "[%(levelname)-8s %(asctime)s]"
format_colors = {
logging.DEBUG: dict(dim=True),
logging.INFO: dict(fg="green"),
logging.WARNING: dict(fg="yellow"),
logging.ERROR: dict(fg="red"),
logging.CRITICAL: dict(fg="red", bold=True),
}
date_format = "%H:%M:%S"
def __init__(self, use_colors: bool = True) -> None:
super().__init__()
self.use_colors = use_colors
def format(self, record: logging.LogRecord) -> str:
return logging.Formatter(
(
click.style(self.base_format, **self.format_colors.get(record.levelno))
if self.use_colors
else self.base_format
)
+ " %(message)s",
datefmt=self.date_format,
).format(record)
+30
View File
@@ -1,8 +1,11 @@
import asyncio
import logging
import typing
from functools import wraps
from pathlib import Path
import click
from .config_file import ConfigFile
@@ -79,6 +82,33 @@ class PathPrompt(click.ParamType):
return result
class CustomLoggerFormatter(logging.Formatter):
base_format = "[%(levelname)-8s %(asctime)s]"
format_colors = {
logging.DEBUG: dict(dim=True),
logging.INFO: dict(fg="green"),
logging.WARNING: dict(fg="yellow"),
logging.ERROR: dict(fg="red"),
logging.CRITICAL: dict(fg="red", bold=True),
}
date_format = "%H:%M:%S"
def __init__(self, use_colors: bool = True) -> None:
super().__init__()
self.use_colors = use_colors
def format(self, record: logging.LogRecord) -> str:
return logging.Formatter(
(
click.style(self.base_format, **self.format_colors.get(record.levelno))
if self.use_colors
else self.base_format
)
+ " %(message)s",
datefmt=self.date_format,
).format(record)
def load_config_file(
ctx: click.Context,
param: click.Parameter,