first commit
This commit is contained in:
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,23 @@
|
||||
# Import python libs
|
||||
import logging
|
||||
import pop.hub
|
||||
from typing import Any, Dict
|
||||
|
||||
|
||||
def setup(hub: "pop.hub.Hub", conf: Dict[str, Any]):
|
||||
"""
|
||||
Given the configuration data set up the logger
|
||||
"""
|
||||
level = hub.conf.log.LEVELS.get(conf["log_level"].lower(), logging.INFO)
|
||||
root = logging.getLogger("")
|
||||
root.setLevel(level)
|
||||
cf = logging.Formatter(fmt=conf["log_fmt_console"], datefmt=conf["log_datefmt"])
|
||||
ch = logging.StreamHandler()
|
||||
ch.setLevel(level)
|
||||
ch.setFormatter(cf)
|
||||
root.addHandler(ch)
|
||||
ff = logging.Formatter(fmt=conf["log_fmt_console"], datefmt=conf["log_datefmt"])
|
||||
fh = logging.FileHandler(conf["log_file"])
|
||||
fh.setLevel(level)
|
||||
fh.setFormatter(ff)
|
||||
root.addHandler(fh)
|
||||
@@ -0,0 +1,62 @@
|
||||
"""
|
||||
This sub is used to set up logging for pop projects and injects logging
|
||||
options into conf making it easy to add robust logging
|
||||
"""
|
||||
# Import python libs
|
||||
import logging
|
||||
import pop.hub
|
||||
from typing import Any, Dict
|
||||
|
||||
|
||||
def __init__(hub: "pop.hub.Hub"):
|
||||
"""
|
||||
Set up variables used by the log subsystem
|
||||
"""
|
||||
hub.conf.log.LEVELS = {
|
||||
"debug": logging.DEBUG,
|
||||
"info": logging.INFO,
|
||||
"warning": logging.WARNING,
|
||||
"error": logging.ERROR,
|
||||
"critical": logging.CRITICAL,
|
||||
}
|
||||
|
||||
|
||||
def conf(hub: "pop.hub.Hub", name: str) -> Dict[str, Any]:
|
||||
"""
|
||||
Return the conf dict for logging, this should be merged OVER by the loaded
|
||||
config dict(s)
|
||||
"""
|
||||
# TODO: Make this more robust to handle more logging interfaces
|
||||
ldict = {
|
||||
"log_file": {
|
||||
"default": f"{name}.log",
|
||||
"help": "The location of the log file",
|
||||
"group": "Logging Options",
|
||||
},
|
||||
"log_level": {
|
||||
"default": "warning",
|
||||
"help": "Set the log level, either quiet, info, warning, or error",
|
||||
"group": "Logging Options",
|
||||
},
|
||||
"log_fmt_logfile": {
|
||||
"default": "%(asctime)s,%(msecs)03d [%(name)-17s][%(levelname)-8s] %(message)s",
|
||||
"help": "The format to be given to log file messages",
|
||||
"group": "Logging Options",
|
||||
},
|
||||
"log_fmt_console": {
|
||||
"default": "[%(levelname)-8s] %(message)s",
|
||||
"help": "The log formatting used in the console",
|
||||
"group": "Logging Options",
|
||||
},
|
||||
"log_datefmt": {
|
||||
"default": "%H:%M:%S",
|
||||
"help": "The date format to display in the logs",
|
||||
"group": "Logging Options",
|
||||
},
|
||||
"log_plugin": {
|
||||
"default": "basic",
|
||||
"help": "The logging plugin to use",
|
||||
"group": "Logging Options",
|
||||
},
|
||||
}
|
||||
return ldict
|
||||
Reference in New Issue
Block a user