https://issues.apache.org/bugzilla/show_bug.cgi?id=44888


Ralph Goers <[EMAIL PROTECTED]> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |[EMAIL PROTECTED]




--- Comment #2 from Ralph Goers <[EMAIL PROTECTED]>  2008-05-15 00:35:44 PST ---
I just tried this with log4j 1.2.15 and could not get my location information.
I am calling the log method from a class that uses SLF4J and does

        if (logger.isTraceEnabled() && logger instanceof LocationAwareLogger)
        {
            ((LocationAwareLogger)logger).log(FLOW_MARKER, FQCN,
LocationAwareLogger.TRACE_INT, "entry", null);
        }

where FQCN is the fully qualified name of my class. This works correctly with
logback. I traced this down and was able to determine that the information
being captured in LocationInfo is wrong.  I was able to hack together a bypass
by creating an appender using the same package name as LocationInfo and doing

    protected void append(LoggingEvent event)
    {
        LocationInfo info = event.getLocationInformation();
        String fqcn = event.getFQNOfLoggerClass();
        Throwable throwable = new Throwable();
        StackTraceElement[] steArray = throwable.getStackTrace();

        int found = LINE_NA;
        for (int i=0; i < steArray.length; ++i)
        {
            if (steArray[i].getClassName().equals(fqcn))
            {
                found = i + 1;
            }
            else if (found != LINE_NA)
            {
                break;
            }
        }
        if (found == LINE_NA)
        {
            return;
        }
        info.className = steArray[found].getClassName();
        info.fileName = steArray[found].getFileName();
        info.lineNumber = Integer.toString(steArray[found].getLineNumber());
        info.methodName = steArray[found].getMethodName();
        info.fullInfo = steArray[found].toString();
    }

By putting this appender first the correct LocationInfo is returned. BTW - this
code came straight from Logback.


-- 
Configure bugmail: https://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to