Enhance logging configuration and documentation

- Added support for rotating log files in `core.py` using `RotatingFileHandler`, with a maximum size of 5 MB and up to 3 backup files.
- Updated `config.ini.example`, `config.ini.minimal-example`, and `config.ini.quickstart` to include descriptions of the new log rotation feature.
- Enhanced `data-retention.md` to clarify log file management and retention policies.
This commit is contained in:
agessaman
2026-03-08 12:41:15 -07:00
parent adf5bc191e
commit 6b4e6351c4
6 changed files with 13 additions and 1 deletions

1
.gitignore vendored
View File

@@ -128,6 +128,7 @@ config.min.ini
mctomqtt.py
bot_cli.py
bot_start_time.txt
*.log.*
# Test files and development artifacts (root level)
test_*.py

View File

@@ -389,6 +389,7 @@ log_level = INFO
# Log file path (leave empty for console only)
# Bot will write logs to this file in addition to console
# Logs rotate at 5 MB with up to 3 backup files (e.g. meshcore_bot.log.1, .2, .3)
log_file = meshcore_bot.log
# Enable colored console output

View File

@@ -231,6 +231,7 @@ log_level = INFO
# Log file path (leave empty for console only)
# Bot will write logs to this file in addition to console
# Logs rotate at 5 MB with up to 3 backup files (e.g. meshcore_bot.log.1, .2, .3)
log_file = meshcore_bot.log
# Enable colored console output

View File

@@ -35,6 +35,7 @@ help = "Bot Help: test (or t), ping, help, hello, cmd, advert, wx, aqi, sun, moo
[Logging]
log_level = INFO
# Rotates at 5 MB, keeps 3 backups (e.g. meshcore_bot.log.1, .2, .3)
log_file = meshcore_bot.log
# Weather (for wx command) - set default_state to your region

View File

@@ -43,3 +43,5 @@ Shorter retention (e.g. 23 days for `packet_stream`) is enough for the web vi
- Deletes old rows from **mesh_connections** (mesh graph).
So as long as the bot is running, the database is pruned on a schedule regardless of whether you run the standalone web viewer or the stats command.
**Log files** (`[Logging] log_file`, e.g. `meshcore_bot.log`) use rotating file logging: the bot rotates at 5 MB and keeps up to 3 backup files (same policy as the web viewer), so log disk use stays bounded.

View File

@@ -8,6 +8,7 @@ import asyncio
import configparser
import json
import logging
from logging.handlers import RotatingFileHandler
import colorlog
import time
import threading
@@ -862,7 +863,12 @@ long_jokes = false
if log_file:
try:
file_handler = logging.FileHandler(log_file)
file_handler = RotatingFileHandler(
log_file,
maxBytes=5 * 1024 * 1024,
backupCount=3,
encoding='utf-8',
)
file_handler.setFormatter(formatter)
self.logger.addHandler(file_handler)
except (OSError, PermissionError) as e: