tcalmant / jsonrpclib

A Python (2 & 3) JSON-RPC over HTTP that mirrors the syntax of xmlrpclib (aka jsonrpclib-pelix)
https://jsonrpclib-pelix.readthedocs.io/
Apache License 2.0
53 stars 24 forks source link

SimpleJSONRPCServer.py: fix logging #40

Closed FATruden closed 4 years ago

FATruden commented 4 years ago

server's code:

from jsonrpclib.SimpleJSONRPCServer import PooledJSONRPCServer
from jsonrpclib.threadpool import ThreadPool
...
...
pool = ThreadPool(max_threads=50, min_threads=10)
pool.start()
server = PooledJSONRPCServer((IP, PORT), thread_pool=pool)

# All rigistred methods
server.register_function(foo)
...

When i call (on client side) unregistered method, i see in server logs:

Oct 03 12:04:52 dc01.dc.int.c2.croc.ru python[22924]: No handlers could be found for logger "jsonrpclib.SimpleJSONRPCServer"
Oct 03 12:04:52 dc01.dc.int.c2.croc.ru python[22924]: 172.20.36.102 - - [03/Oct/2019 12:04:52] "POST / HTTP/1.1" 200 -

after this fix, logging works correctly:

Oct 03 12:14:59 dc01.dc.int.c2.croc.ru python[25408]: WARNING:jsonrpclib.SimpleJSONRPCServer:Unknown method: <Fault -32601: Method test not supported.>
Oct 03 12:14:59 dc01.dc.int.c2.croc.ru python[25408]: 172.20.36.102 - - [03/Oct/2019 12:14:59] "POST / HTTP/1.1" 200 -
...
Oct 03 12:18:03 dc01.dc.int.c2.croc.ru python[25408]: WARNING:jsonrpclib.SimpleJSONRPCServer:Invalid call parameters: <Fault -32602: Invalid parameters: update() takes no arguments (1 given)>
Oct 03 12:18:03 dc01.dc.int.c2.croc.ru python[25408]: 172.20.36.102 - - [03/Oct/2019 12:18:03] "POST / HTTP/1.1" 200 -
coveralls commented 4 years ago

Coverage Status

Coverage decreased (-2.4%) to 81.557% when pulling 033a33acfa46b21659d10c7bbcad03653eaf29b8 on FATruden:logging_fix into fe9fcf2c99973507f7055d6c9e05e155957c2549 on tcalmant:master.

coveralls commented 4 years ago

Coverage Status

Coverage decreased (-1.6%) to 82.346% when pulling dcdbf592ce4e3b941e13e57d039cac8ccb0b633a on FATruden:logging_fix into fe9fcf2c99973507f7055d6c9e05e155957c2549 on tcalmant:master.

tcalmant commented 4 years ago

Hi, I'm not sure the logger configuration should be set by the library itself. It is intended to use the logging configuration set by the developer using the library, at the beginning of the software.

FATruden commented 4 years ago

Hi, i agree with you and i put logging.basicConfig() before creating server object and it works fine. But it's a little misleading. You use logging in our code but it is not working without logging configuration. May be you should add this to README.

tcalmant commented 4 years ago

You're right, I'll add it to the README file

FATruden commented 4 years ago

Thank you!