Re: method name

From: Chris Uppal (chris.uppal_at_metagnostic.REMOVE-THIS.org)
Date: 02/15/05


Date: Tue, 15 Feb 2005 19:42:26 -0000

John C. Bollinger wrote:

> > Creating new object with every call in unacceptable because of limited
> > memory. The less objects the better.
>
[...]
> For what it's worth, you could put a stack-trace based solution into
> your logging mechanism instead of into every method. The logger would
> just need to look one level further down in the stack trace

As a slight improvement on that, the logging API could take an optional method
name, and the logging code would fall back to using reflection to find the
caller only if the name wasn't explicitly provided. Presumably the usual
80%/20% (or 95%/5%) rule apply to logging as much as anything else. So you
could eliminate the overhead of reflection in the few cases that took the bulk
of the execution time by passing an explicit (hand coded) method name in only
those cases.

But that's just an obvious refinement. Here's a not-at-all serious suggestion
to improve matters further:

Presumably each call to the logger will want to say something different, so the
main "message" string will be different for each call-site (at least to a good
approximation), so the logger object could contain a Map from message strings
to calling method names. It would fill that map in lazily during execution,
the first time it saw a message it didn't know about, it would use reflection
to determine the caller, and enter that into the map. Thus magically
combining the efficiency of hard-coded method names with the flexibility of
reflective lookup.

No, it's not a serious suggestion, but it would be interesting to see how far
one could get along such lines.

Any ideas for further improvements, anyone ?

    -- chris



Relevant Pages

  • Re: General question about logging concept
    ... or class to Debug to get more log messages (assuming you have more ... Also, by default the log messages include the logger info, so it's a ... Once you configure logging it's configured for the entire appdomain, ... I'm just now configuring some logging module in my web app (I'm using ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Simple logging example doesnt work!
    ... file handler explicitly. ... See the logging docs for more info on Filters. ... # syslog adds its own time and level stamp. ... # Set up initial logger. ...
    (comp.lang.python)
  • logging via SocketHandler and TCPserver
    ... I find that I REALLY need to be able to monitor LOTS of running programs/processes and thought it would be nice to have them use SocketHandler logging and then I would write TCPServer to accept the log messages for real-time monitoring. ... I Googled for several hours and came up with some code that I've turned in to something that works, but I can't figure out how to disconnect the server once it is connected The goal is to be able to start TCPServer, monitor the log messages sent via SocketHandler logger, disconnect, and move to the next application. ... def unPickle: ...
    (comp.lang.python)
  • Passing contextual information when logging
    ... difficulty of passing additional contextual information when logging. ... Logger instances. ...
    (comp.lang.python)
  • Re: logging: local functions ==> loss of lineno
    ... BUT when I have to wrap the logger call in some other function, ... import logging ... wrapper.py: foo ... if filename in self.exclude_files: ...
    (comp.lang.python)