TobKra96 / music_led_strip_control

Audio visualization for LED strips in real-time with web interface on a raspberry pi.
https://tobkra96.github.io/music_led_strip_control/
MIT License
298 stars 64 forks source link

Central Logging Library #71

Closed TobKra96 closed 3 years ago

TobKra96 commented 3 years ago

Check if we can use a logging library, that can save rolling logs, manage the console output. Convert all print commands to the logging mechanism.

TobKra96 commented 3 years ago

Evaluate https://docs.python.org/3.8/howto/logging.html

Teraskull commented 3 years ago

Something like this. It has 5 rolling logs up to 5mb each, and outputs to console.

from logging.handlers import RotatingFileHandler
import logging

logging.basicConfig(handlers=[
                    RotatingFileHandler('../../.mlsc/mlsc.log', mode='a', maxBytes=5 * 1024 * 1024, backupCount=5, encoding='utf-8'),
                    logging.StreamHandler()
                    ],
                    format='%(asctime)s - %(levelname)s - %(message)s',
                    datefmt='%Y.%m.%d %H:%M:%S',
                    level=logging.INFO
                    )

logger = logging.getLogger('dev')
logger.setLevel(logging.DEBUG)

And to disable logging to the console, for example with a checkbox:

logger.StreamHandler(stream=None)