how i can split log file based on logging level ?
mosi-kha opened this issue · 3 comments
mosi-kha commented
hi
how I can split a log file based on logging level?
for example, I want to error
level save in error.log
and just debug
level save in debug.log
...
thanks :)
Delgan commented
Hi @mosi-kha. :)
I'm not sure this is the intended usage for logging level (generally it's more like "show DEBUG and all higher to developer, show INFO and all above to user"), but this is totally doable using filter
(only logs passing the function will be propagated to the sink):
logger.add("error.log", filter=lambda record: record["level"].name == "ERROR")
logger.add("debug.log", filter=lambda record: record["level"].name == "DEBUG")
Delgan commented
You're welcome. 😉