On 5 March 2013 19:05, David Coombes <[email protected]> wrote:
> I have a method in a class that calls Logger::info() The issue is the
> file:line column in the html appender will always report my helper method
> and not the calling file:line. Using php's debug_backtrace I can get the
> calling file:line but can't see how I can dynamically change the column. Is
> this possible, or is there a Logger::method() that I need to overwrite?

Hi!

Currently it's not possible to override the location information.
There is a hackish way of doing this, but you have to modify log4php
code.

Add this method to LoggerLoggingEvent class (located in /src/main/php/):
public function setLocationInformation(LoggerLocationInfo $locationInfo) {
    $this->locationInfo = $locationInfo;
}

And then do this:

public function log($msg, $level = "info")
{
    // Manually construct a logging event
    $level = LoggerLevel::toLevel($level);
    $logger = Logger::getLogger(__CLASS__);
    $event = new LoggerLoggingEvent(__CLASS__, $logger, $level, $msg);

    // Override the location info
    $bt = debug_backtrace();
    $caller = array_shift($bt);
    $location = new LoggerLocationInfo($caller);
    $event->setLocationInformation($location);

    // Log it
    $logger->logEvent($event);
}

Just tried it out. Seems to work fine. Let me know how it works.

I will add LoggerLoggingEvent::setLocationInformation() to the develop
branch so it will be included in next release.

Looking at the HTML layout... man, it's really outdated. Still has
Category instead of Logger, and other stuff... Will have to update it.
:)

Best regards,
Ivan

Reply via email to