bag.log module¶
Easily set up logging.
- bag.log.setup_log(name=None, path='logs', rotating=True, backups=3, file_mode='a', disk_level=10, screen_level=20, encoding='utf-8')[source]¶
This logs to screen if
screen_level
is not None, and logs to disk ifdisk_level
is not None.If you do not pass a log
name
, the root log is configured and returned.If
rotating
is True, a RotatingFileHandler is configured on the directory passed aspath
.If
rotating
is False, a single log file will be created atpath
. Itsfile_mode
defaults to a (append), but you can set it to w.
- bag.log.setup_rotating_logger(logger=None, backups=4, size=250000000, level=10, encoding='utf-8', format='%(asctime)s %(levelname)s %(message)s', directory='.')[source]¶
You may pass either a name or an existing logger as the first argument. This attaches a RotatingFileHandler to the specified logger. Returns the logger object.
- bag.log.setup_timed_rotating_logger(logger=None, level=10, backups=14, when='D', interval=1, utc=True, delay=False, encoding='utf-8', format='%(asctime)s %(levelname)s %(message)s', directory='.')[source]¶
You may pass either a name or an existing logger as the first argument. This attaches a TimedRotatingFileHandler to the specified logger. Returns the logger object.
- bag.log.setup_watched_file_handler(logger=None, level=10, format='%(asctime)s %(levelname)s %(message)s', encoding='utf-8', delay=False, directory='.')[source]¶
You may pass either a name or an existing logger as the first argument. This attaches a WatchedFileHandler to the specified logger. Returns the logger object.
The WatchedFileHandler detects when the log file is moved, so it is compatible with the logrotate daemon.