Use custom logger instead of logging.root
rwckr opened this issue · 1 comments
rwckr commented
Issue
- Any error raised by the jsonrpcserver dispatcher overwrites existing logger formats.
- Unable to suppress error messages on the console
Solution
Use a custom "jsonrpcserver" logger instead of logging.root.
Demonstration
Calling logging.exception automatically adds a StreamHandler to logging.root:
>>> import logging
>>> logging.root.handlers
[]
>>> logging.exception("")
ERROR:root:
NoneType: None
>>> logging.root.handlers
[<StreamHandler <stderr> (NOTSET)>]The StreamHandler being added to root.logging also changes the formatting for all child loggers:
>>> import logging
>>> log1 = logging.getLogger("log1")
>>> log1.error("test")
test
>>> logging.exception("test")
ERROR:root:test
NoneType: None
>>> log1.error("test")
ERROR:log1:test