I would like to know how would i implement a logger in python? More specifically, after a response is dispatched to the client i would like to log some information to confirm that the response has just been processed and sent.
|
|
I would like to know how would i implement a logger in python? More specifically, after a response is dispatched to the client i would like to log some information to confirm that the response has just been processed and sent.
"Nothing is gained without sacrificing something of equal value..." Principles of Life: Equivalent Trade
ŪNetŪ
Hi,
If you want to use the Ice logger, a Python program can call
If you want to replace Ice's default logger implementation, define your class and pass an instance of it when initializing a communicator:Code:communicator.getLogger().trace("MyApp", "My message")
Hope that helps,Code:class MyLogger(object): def trace(self, category, message): # Log the message ... id = Ice.InitializationData() id.logger = MyLogger() communicator = Ice.initialize(id)
Mark
Thank you for your quick reply. In addition is there a way that i can place this call in a central place so that the trace is performed on all exposed service calls?
"Nothing is gained without sacrificing something of equal value..." Principles of Life: Equivalent Trade
ŪNetŪ
On the client side, the ice_sent callback notifies the application that Ice has successfully handed a message off to the transport layer, which is about as much of a guarantee as you can get that a request has been sent. However, no such mechanism exists for a server to be notified when a response message has been successfully sent.
Even if you simply want to log a message after a servant has completed an operation and aren't concerned about network-level guarantees, there are still some hurdles to overcome in order to centralize this logging. You could use a servant locator as Bernard suggested in another thread; the locator's finished method would be the appropriate place to log such a message. The problem is that the locator doesn't know whether the operation completed successfully or raised an exception. You could work around this limitation, for example by wrapping the servant returned by locate in a special Python object that intercepts the dispatched operation and keeps track of whether the servant raises an exception. However, that may be more trouble than it's worth.
Dispatch interceptors (if they were implemented in Python) would help, but only to a certain degree. A dispatch interceptor knows whether a synchronous invocation completed successfully or raised an exception, but does not know the status of an invocation dispatched asynchronously.
Take care,
Mark
That's cool, but the problem becomes how to create a servant locator in ICE? I did look into that at first, but there is no Ice.ServantLocator to even descend from.
"Nothing is gained without sacrificing something of equal value..." Principles of Life: Equivalent Trade
ŪNetŪ
The Ice.ServantLocator type is generated from the corresponding Slice definition. You'll find it defined in python/Ice_ServantLocator_ice.py in your Ice installation. If you have a source distribution of Ice, you can also use the test case in py/test/Ice/servantLocator as an example.
Regards,
Mark
Thank you, i will definitely try to work with this.
"Nothing is gained without sacrificing something of equal value..." Principles of Life: Equivalent Trade
ŪNetŪ
There are currently 1 users browsing this thread. (0 members and 1 guests)