From: Pete S. <si...@uc...> - 2003-12-30 00:37:30
|
I'd like log4perl to indent messages to show caller depth in the call stack. A sample of this style is main: starting function1: called with arg1, arg2 function1: returning value1 function2: called function3: called function4: called with arg4 function4: returning function3: returning function2: returning main: ending For years, I've been doing this by passing around a scalar named $CallDepth, and incrementing/decrementing it at function entry/exit. I pass around a second scalar named $DbgLevel that works sorta like the levels in log4perl, but with more levels. In the above sample, setting it to 1 shows only the "main" lines, and 2 shows only "main" and "function1" and "function2", etc. I set the DbgLevel with a command-line option, so I can produce logs with shallow or deep hierarchies. This scheme has been extremely useful for me, though a bit cumbersome. It even handles recursion nicely. It seems like "Custom Cspecs" in PatternLayouts is the way to do this in log4perl. It's described at http://log4perl.sourceforge.net/releases/Log-Log4perl/docs/html/Log/Log4perl/Layout/PatternLayout.html#9af52 The $caller_level variable is especially intriguing, as it's *almost* what I need. Instead of being "how many levels back up the call stack you have to go to find the caller", which isn't very useful, I want it to be "how many levels back up the call stack you have to go to find the main program". Perhaps "main program" could be defined by a new function to mark the "zero" depth of the stack. I confess to being a little lost as to how to do this, but I think it's possible. Am I crazy? -- Pete |