RotatingFileHandler implementation for the Micropython Logging library
- Thread-safe
- Rotates files by adding an index to the old log files like
log.txt.1
,log.txt.2
, etc.
- Download the latest release
- Copy the file into the
/lib
directory on your device or to your source code folder
- Use mpremote to install the library to the device:
mpremote mip install https://github.com/PolarGoose/MicroPython-Logging-RotatingFileHandler/releases/download/v1.0/rotating_file_handler.py
from rotating_file_handler import RotatingLogFileHandler
from logging import getLogger, DEBUG, Formatter
handler = RotatingLogFileHandler(log_file_name, 20, 2)
formatter = Formatter("%(message)s")
handler.setFormatter(formatter)
logger = getLogger("test_logger")
logger.addHandler(handler)
logger.setLevel(DEBUG)
logger.info("message")