Results 1 to 7 of 7

Thread: Logging in Python

  1. #1
    Netmaster0000's Avatar
    Netmaster0000 is offline Registered User
    Name: Neel Edwards
    Organization: Home(Student)
    Project: Server based application wide security.
    Join Date
    Dec 2008
    Posts
    21

    Question Logging in Python

    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Ū

  2. #2
    mes's Avatar
    mes
    mes is offline ZeroC Staff
    Name: Mark Spruiell
    Organization: ZeroC, Inc.
    Project: Ice Developer
    Join Date
    Feb 2003
    Location
    California
    Posts
    1,445
    Hi,

    If you want to use the Ice logger, a Python program can call
    Code:
    communicator.getLogger().trace("MyApp", "My message")
    If you want to replace Ice's default logger implementation, define your class and pass an instance of it when initializing a communicator:
    Code:
    class MyLogger(object):
        def trace(self, category, message):
            # Log the message
    
        ...
    
    id = Ice.InitializationData()
    id.logger = MyLogger()
    communicator = Ice.initialize(id)
    Hope that helps,
    Mark

  3. #3
    Netmaster0000's Avatar
    Netmaster0000 is offline Registered User
    Name: Neel Edwards
    Organization: Home(Student)
    Project: Server based application wide security.
    Join Date
    Dec 2008
    Posts
    21
    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Ū

  4. #4
    mes's Avatar
    mes
    mes is offline ZeroC Staff
    Name: Mark Spruiell
    Organization: ZeroC, Inc.
    Project: Ice Developer
    Join Date
    Feb 2003
    Location
    California
    Posts
    1,445
    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

  5. #5
    Netmaster0000's Avatar
    Netmaster0000 is offline Registered User
    Name: Neel Edwards
    Organization: Home(Student)
    Project: Server based application wide security.
    Join Date
    Dec 2008
    Posts
    21
    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Ū

  6. #6
    mes's Avatar
    mes
    mes is offline ZeroC Staff
    Name: Mark Spruiell
    Organization: ZeroC, Inc.
    Project: Ice Developer
    Join Date
    Feb 2003
    Location
    California
    Posts
    1,445
    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

  7. #7
    Netmaster0000's Avatar
    Netmaster0000 is offline Registered User
    Name: Neel Edwards
    Organization: Home(Student)
    Project: Server based application wide security.
    Join Date
    Dec 2008
    Posts
    21
    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Ū

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Logging all calls for IceGrid node servers
    By cfrauenberger in forum Help Center
    Replies: 4
    Last Post: 01-24-2011, 04:33 AM
  2. Logging Java process with IceGrid
    By joshmoore in forum Help Center
    Replies: 3
    Last Post: 02-18-2008, 07:28 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •