mirror of
https://github.com/agessaman/meshcore-bot.git
synced 2026-03-29 03:19:51 +00:00
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:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -43,3 +43,5 @@ Shorter retention (e.g. 2–3 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.
|
||||
|
||||
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user