explodinglabs / jsonrpcserver

Process incoming JSON-RPC requests in Python
https://www.jsonrpcserver.com
MIT License
185 stars 40 forks source link

Use custom logger instead of logging.root #239

Closed rwckr closed 1 year ago

rwckr commented 1 year ago

Issue

  1. Any error raised by the jsonrpcserver dispatcher overwrites existing logger formats.
  2. 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
rwckr commented 1 year ago

Pull request submitted #240