-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add option for extra verbose logging. Bump version to 0.2.1
- Loading branch information
Showing
4 changed files
with
65 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
from logging import Logger, NOTSET, addLevelName, INFO, DEBUG, StreamHandler, Formatter | ||
import sys | ||
|
||
VERBOSE = 5 | ||
|
||
|
||
class VerboseLogger(Logger): | ||
""" | ||
Logger with custom log level VERBOSE which is lower than DEBUG. | ||
""" | ||
|
||
def __init__(self, name, level=NOTSET): | ||
super().__init__(name, level) | ||
addLevelName(VERBOSE, "VERBOSE") | ||
|
||
def verbose(self, msg, *args, **kwargs): | ||
if self.isEnabledFor(VERBOSE): | ||
self._log(VERBOSE, msg, args, **kwargs) | ||
|
||
|
||
def get_logger(verbosity: int) -> VerboseLogger: | ||
""" | ||
Get logger object which logs to stdout with given verbosity. | ||
:param verbosity: logs INFO if 0, DEBUG if 1 and VERBOSE if >1 | ||
:return: | ||
""" | ||
if verbosity <= 0: | ||
log_level = INFO | ||
elif verbosity == 1: | ||
log_level = DEBUG | ||
else: | ||
log_level = VERBOSE | ||
|
||
logger = VerboseLogger("connectbox_exporter") | ||
logger.setLevel(log_level) | ||
handler = StreamHandler(sys.stdout) | ||
handler.setLevel(log_level) | ||
formatter = Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s") | ||
handler.setFormatter(formatter) | ||
logger.addHandler(handler) | ||
|
||
return logger |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,7 @@ | |
|
||
setup( | ||
name="connectbox-prometheus", | ||
version="0.2.0", | ||
version="0.2.1", | ||
author="Michael Bugert", | ||
author_email="[email protected]", | ||
description='Prometheus exporter for Compal CH7465LG cable modems, commonly sold as "Connect Box"', | ||
|