Clean log format

This commit is contained in:
Xoconoch
2025-06-07 14:01:38 -06:00
parent a400538ed1
commit e97efb6b19
3 changed files with 13 additions and 5 deletions

2
app.py
View File

@@ -46,7 +46,7 @@ def setup_logging():
# Log formatting
log_format = logging.Formatter(
"%(asctime)s [%(processName)s:%(threadName)s] [%(name)s] [%(levelname)s] - %(message)s",
"%(asctime)s [%(levelname)s] %(message)s",
datefmt="%Y-%m-%d %H:%M:%S",
)

View File

@@ -4,7 +4,7 @@ import atexit
# Configure basic logging for the application if not already configured
# This is a good place for it if routes are a central part of your app structure.
logging.basicConfig(
level=logging.INFO, format="%(asctime)s - %(name)s - %(levelname)s - %(message)s"
level=logging.INFO, format="%(message)s"
)
logger = logging.getLogger(__name__)

View File

@@ -69,8 +69,16 @@ class CeleryManager:
try:
for line in iter(stream.readline, ""):
if line:
log_method = logger.error if error else logger.info
log_method(f"{log_prefix}: {line.strip()}")
line_stripped = line.strip()
log_method = logger.info # Default log method
if error: # This is a stderr stream
if " - ERROR - " in line_stripped or " - CRITICAL - " in line_stripped:
log_method = logger.error
elif " - WARNING - " in line_stripped:
log_method = logger.warning
log_method(f"{log_prefix}: {line_stripped}")
elif (
self.stop_event.is_set()
): # If empty line and stop is set, likely EOF
@@ -359,7 +367,7 @@ celery_manager = CeleryManager()
if __name__ == "__main__":
logging.basicConfig(
level=logging.INFO,
format="%(asctime)s [%(levelname)s] [%(threadName)s] [%(name)s] - %(message)s",
format="%(message)s",
)
logger.info("Starting Celery Manager example...")
celery_manager.start()