mirror of
https://github.com/AkitaEngineering/Akita-Meshtastic-Meshcore-Bridge.git
synced 2026-03-28 17:42:42 +01:00
35 lines
1.2 KiB
Python
35 lines
1.2 KiB
Python
# ammb/utils.py
|
|
"""
|
|
Shared utilities for the AMMB application, primarily logging setup.
|
|
"""
|
|
|
|
import logging
|
|
|
|
LOG_FORMAT = '%(asctime)s - %(threadName)s - %(levelname)s - %(name)s - %(message)s'
|
|
DATE_FORMAT = '%Y-%m-%d %H:%M:%S'
|
|
|
|
def setup_logging(log_level_str: str):
|
|
"""
|
|
Configures application-wide logging.
|
|
"""
|
|
numeric_level = getattr(logging, log_level_str.upper(), None)
|
|
if not isinstance(numeric_level, int):
|
|
logging.warning(
|
|
f"Invalid log level specified: '{log_level_str}'. Defaulting to INFO."
|
|
)
|
|
numeric_level = logging.INFO
|
|
|
|
# Reconfigure the root logger
|
|
logging.basicConfig(level=numeric_level,
|
|
format=LOG_FORMAT,
|
|
datefmt=DATE_FORMAT,
|
|
force=True)
|
|
|
|
# Adjust logging levels for noisy libraries
|
|
logging.getLogger("pypubsub").setLevel(logging.WARNING)
|
|
logging.getLogger("pubsub").setLevel(logging.WARNING)
|
|
logging.getLogger("meshtastic").setLevel(logging.INFO)
|
|
logging.getLogger("paho").setLevel(logging.WARNING)
|
|
|
|
logging.info(f"Logging configured to level {logging.getLevelName(numeric_level)} ({numeric_level})")
|