feat(Handlers): allow for configuration of log outputs
beneboy opened this issue · 0 comments
Logga has so far been built just for capturing errors, not outputting them anywhere. Since existing logging solutions aren't configurable with files in a nice way, we could add this functionality to logga for configurable output.
{
"level": "debug",
"format": "${time} ${levelname} ${message}"
"handlers": [
{
"type": "file",
"path": "/path/to/file",
"level": "warning"
},
{
"type": "file",
"path": "/errors/only",
"level": "error"
}
{
"type": "console",
"level": "debug",
"format": "${levelEmoji} ${levelName} ${time} ${message} ${trace}"
},
{
"type": "syslog"
"level": "error"
}
],
"loggas": {
"stencila.encoda": {
"handlers": []
},
"stencila.schema": {
"level": "error",
"handlers": [
{
"type": "console",
"level": "debug"
}
]
}
}
}
The message level
must exceed both the handler level, global level
and (if in a module) the module level
to be logged somewhere.
If a logging module name is not found in the loggas
dictionary it will fall back to the defaults.
Some examples:
log = getLogger('stencila.thema')
log.debug('some message')
Would log only to the console with a 🚨 emoji.
log.error('Some error')
Would log to /errors/only
, /path/to/file
, console and syslog. The syslog and file formats would be the global format
.
encLogger = getLogger('stencila.encoda')
log.critical('some message')
Would not log anywhere as stencila.encoda
has no handlers.
encLogger = getLogger('stencila.schema')
log.debug('some debug message')
Would not log anywhere because the stencila.schema
log level is error
so handlers can not override it.
There could be a standard list of default locations to look for a configuration file in, or passed in from the command line. (logga.json
in the project dir, ~/.logga.json
, /etc/logga.json
etc)