You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-dev@logging.apache.org by Ronald Blaschke <ma...@rblasch.org> on 2003/11/16 01:00:12 UTC

Re[2]: log4j location information issue

Hello Ceki,

CG> Ronald,

CG> Since you are familiar with the relevant log4j code, do you know the stack
CG> trace lines look like?

Not an easy question.  In Java 1.4.2, Sun implements the information as either
(<Filename>:<LineNumber>)
(<Filename>)
(Native Method)
(Unknown Source)

(see http://java.sun.com/j2se/1.4.2/docs/api/java/lang/StackTraceElement.html#toString())

In 1.3.1 the implementation is similar, but directly in the VM (in
method pc2string in classruntime.c).

I'd recommend changing the code to the one below, which would leave
"Native Method" and "Unknown Source" as is.  Replacing "Unknown Source"
with NA might be considered, though.

    public
    String getFileName() {
        if(fullInfo == null) return NA;

        if(fileName == null) {
            int iend = fullInfo.lastIndexOf(':');
            if(iend == -1) {
                iend = fullInfo.lastIndexOf(')');
            }

            if (iend == -1) {
                fileName = NA;
            } else {
                int ibegin = fullInfo.lastIndexOf('(', iend - 1);
                fileName = this.fullInfo.substring(ibegin + 1, iend);
            }
        }
        return fileName;
    }
    
Ron


---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: log4j-dev-help@jakarta.apache.org