🔧 chore(logger.py): refactor configure function to improve readability and add support for configurable log level

🔒 chore(logger.py): add VALID_LOG_LEVELS constant to define valid log levels for better maintainability
This commit is contained in:
Gabriel Luiz Freitas Almeida 2023-09-27 08:51:17 -03:00
commit 0b2b074e07

View file

@ -7,6 +7,9 @@ import orjson
import appdirs
VALID_LOG_LEVELS = ["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"]
def serialize(record):
subset = {
"timestamp": record["time"].timestamp(),
@ -21,9 +24,11 @@ def patching(record):
record["extra"]["serialized"] = serialize(record)
def configure(log_level: str = "INFO", log_file: Optional[Path] = None):
if os.getenv("LANGFLOW_LOG_LEVEL"):
def configure(log_level: Optional[str] = None, log_file: Optional[Path] = None):
if os.getenv("LANGFLOW_LOG_LEVEL") in VALID_LOG_LEVELS and not log_level:
log_level = os.getenv("LANGFLOW_LOG_LEVEL")
elif not log_level:
log_level = "INFO"
# Human-readable
log_format = "<green>{time:YYYY-MM-DD HH:mm:ss}</green> - <level>{level: <8}</level> - {module} - <level>{message}</level>"