https://github.com/brandonmpace/logcontrol
logcontrol is intended to simplify managing loggers across a Python program
https://github.com/brandonmpace/logcontrol
log-management log-manager logger logging python
Last synced: 6 months ago
JSON representation
logcontrol is intended to simplify managing loggers across a Python program
- Host: GitHub
- URL: https://github.com/brandonmpace/logcontrol
- Owner: brandonmpace
- License: other
- Created: 2019-08-22T02:05:38.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2020-06-27T21:21:00.000Z (about 6 years ago)
- Last Synced: 2024-08-10T11:52:14.201Z (almost 2 years ago)
- Topics: log-management, log-manager, logger, logging, python
- Language: Python
- Size: 83 KB
- Stars: 0
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.rst
- License: COPYING
Awesome Lists containing this project
README
**logcontrol:** A logger manager for Python programs
It provides:
* Centralized control of log level (per-group)
Original use case:
* Python GUI program containing many packages and modules
* Each source file that logs creates a proper logger for use within that file
* e.g. logger = logging.getLogger(\_\_name__)
* This allows a good logging hierarchy for control at a central point
* I wanted to simplify enabling debug level for specific packages or groups
Installation:
* pip install logcontrol
(Tested for Python >=3.6.5 on Linux (Ubuntu) and Windows 7/10)
Usage:
* example (where otherpackage and anotherpackage are example names)::
# imports of fictitious packages
import otherpackage
import anotherpackage
import logging
import logcontrol
# Register loggers you wish to control.
# You can have user-friendly names for the groups if you wish:
logcontrol.register_logger(otherpackage.logger, group='Other Package')
# Set output file for the root logger:
logcontrol.set_log_file('main_log.txt')
# Enable specific log levels per-group:
logcontrol.set_level(logging.DEBUG, group='Other Package')
# Make specific groups log to console while debugging:
logcontrol.log_to_console(group='Other Package')
# You can even disable or enable propagation per-group:
logcontrol.disable_propagation(group='Other Package')
logcontrol.enable_propagation(group='Other Package')
# Loggers added to the same group will get the same configuration.
# This would automatically set DEBUG level and attach the console logging handler:
logcontrol.register_logger(anotherpackage.module.logger, group='Other Package')
# You can get a dict of group names with level names (good for populating a debug/log control popup):
logcontrol.group_level_names()
# For convenience, the predefined log levels are available:
# - as integers via logcontrol.log_level_integers
# - as strings via logcontrol.log_level_strings
#
# This makes it easy to display them in a combo box for users to choose.