fix: make bot.py FileHandler resilient to missing log directory
This commit is contained in:
parent
0045f5d324
commit
98af8e2df3
1 changed files with 7 additions and 4 deletions
|
|
@ -46,13 +46,16 @@ except Exception:
|
||||||
_bot_domain_suffix = ""
|
_bot_domain_suffix = ""
|
||||||
|
|
||||||
# Configure logging
|
# Configure logging
|
||||||
|
_log_handlers: list[logging.Handler] = [logging.StreamHandler(sys.stdout)]
|
||||||
|
try:
|
||||||
|
os.makedirs(os.path.dirname(config.BOT_LOG_FILE), exist_ok=True)
|
||||||
|
_log_handlers.append(logging.FileHandler(config.BOT_LOG_FILE, mode="a"))
|
||||||
|
except OSError:
|
||||||
|
pass # File logging unavailable (e.g., read-only filesystem in CI)
|
||||||
logging.basicConfig(
|
logging.basicConfig(
|
||||||
level=logging.INFO,
|
level=logging.INFO,
|
||||||
format="%(asctime)s [%(name)s] %(levelname)s: %(message)s",
|
format="%(asctime)s [%(name)s] %(levelname)s: %(message)s",
|
||||||
handlers=[
|
handlers=_log_handlers,
|
||||||
logging.StreamHandler(sys.stdout),
|
|
||||||
logging.FileHandler(config.BOT_LOG_FILE, mode="a"),
|
|
||||||
],
|
|
||||||
)
|
)
|
||||||
logger = logging.getLogger("notify-bot")
|
logger = logging.getLogger("notify-bot")
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue