Python logging module
To use it my own projects and practice decorators and console output styling
import dlogging as log
log.debug('debug')
log.info('info')
log.warning('warning')
log.error('error')
log.critical('critical')
log.info_forced('info_forced')
Yeah! First time you run programm with imported dlogging module, it will create dlogging.json
file in your working directory. It will help you to configure your output.
Like this
{
"log_template": "[{date}][{file}]{style}[{mode}]{endstyle} - {message}",
"file_template": "{}:{}",
"level": "DEBUG",
"DEBUG": {
"outputs": [
{
"type": "console",
"style": [
"bold"
]
}
]
},
"INFO": {
"outputs": [
{
"type": "console",
"style": [
"bold",
"cyan"
]
},
{
"type": "file",
"path": "{wd}/LOGS",
"name": "dloggingOut.log"
}
]
},
"WARNING": {
"outputs": [
{
"type": "console",
"style": [
"bold",
"yellow"
]
},
{
"type": "file",
"path": "{wd}/LOGS",
"name": "dloggingOut.log"
}
]
},
"ERROR": {
"outputs": [
{
"type": "console",
"style": [
"bold",
"red"
]
},
{
"type": "file",
"path": "{wd}/LOGS",
"name": "dloggingOut.log"
}
]
},
"CRITICAL": {
"outputs": [
{
"type": "console",
"style": [
"bold",
"red_background"
]
},
{
"type": "file",
"path": "{wd}/LOGS",
"name": "dloggingOut.log"
},
{
"type": "file",
"path": "{wd}/LOGS",
"name": "dloggingOutCritical.log"
}
]
}
}
String template for your logs. You can use this tags to put data in it:
{date}
- date-time inYYYY-MM-DD hh:mm:ss
format{file}
- file, from where logging was called{style}
and{endstyle}
- where style formatting for console output starts and ends{message}
- logging message
Logging level like DEBUG
, INFO
, WARNING
, ERROR
, CRITICAL
or INFO_FORCED
. How logging levels works? Simple example:
If your logging level set to INFO
, only messages with logging level higher then INFO
(WARNING
, ERROR
, CRITICAL
or INFO_FORCED
) would be written.
Then there is field for each logging level except of INFO_FORCED
. In each that field you can configure outputs with outputs list
It can be console
or file
to write your logs to console or file respectively
If type field equals console
this list represents which would be used in {style}
tag in log_template. Can hold up to 2 strings
If type field equals file
this field represents path to your log file. Tag {wd}
means your working directory
If type field equals file
this field represents name of your log file