You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-user@logging.apache.org by "Michael P. Canzoneri" <mc...@biztech.com> on 2002/10/25 17:14:12 UTC

Interesting Problem

I recently received a very interesting question on the jGuru site pertaining
to the classname and line number in the code not showing up in the log
output.

normal:

<Date> ERROR (MyClassName.java: 100)

but what the user got was:

<Date> ERROR (?:?) - Some message

One of the visitors to the forum encountered the same problem.  The solution
to the problem seemed to lie in the version of ANT (ant1.5.1) they used to
build the project.  The developer used an earlier version of ANT and the
problem seemed to disappear.

Has anyone else encountered the same problem?

Just wondering.

Michael


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Missing location thru SocketServer (was: Interesting Problem)

Posted by Thomas Saxtoft <t....@sondagsavisen.dk>.
> Found the problem.
Sure you did :-)
I have the impression that you have been using a lot of time on this 
problem.
I really appreciate the effort you have, and should you one day pass thru Copenhagen I'll give a beer :-)

Thank you,

Thomas Saxtoft


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Missing location thru SocketServer (was: Interesting Problem)

Posted by gautamsatpathy <ga...@yahoo.com>.
Hello Thomas,

Found the problem. It is in SocketAppender. The SocketAppender uses 
an option called "LocationInfo" which defaults to "false". As a 
result, the LoggingEvent object written to the socket does not 
contain any location information. That is, it does not contain a 
reference to a "LocationInfo" object. Hence, no location information.

Add  the following to your log4j configuration for the client (the 
classes logging to the ServerSocket) :

log4j.appender.socketserver.LocationInfo=true

When you are done, your configuration file should have the following:

log4j.appender.socketserver = org.apache.log4j.net.SocketAppender
log4j.appender.socketserver.RemoteHost = 127.0.0.1
log4j.appender.socketserver.Port = 8889
log4j.appender.socketserver.LocationInfo=true

This is not mentioned anywhere in the documentation (at least I 
couldn't locate anything). The JavaDoc for SocketAppender does 
mention the following:

"getLocationInfo() 
          Returns value of the LocationInfo option
          
setLocationInfo(boolean locationInfo) 
          The LocationInfo option takes a boolean value. "

Hope this helps.

Regards,

Gautam Satpathy

--- In Log4J@y..., "Thomas Saxtoft" <t....@s...> wrote:
> Hi Gautam
> 
> Finally I got that far. Now I get location information on both 
client and server. Thank you Gautam.
> But I still has got a problem. I don't get any location info thru 
my Log4j SocketServer. 
> I write to a log file on the client, the server and the socket 
server using the same ConversionPattern:
> 
> log4j.appender.R.layout.ConversionPattern=[slf5s.start]%d{DATE}
[slf5s.DATE]%n\
> %p[slf5s.PRIORITY]%n%x[slf5s.NDC]%n%t[slf5s.THREAD]%n\
> %c[slf5s.CATEGORY]%n%l[slf5s.LOCATION]%n%m[slf5s.MESSAGE]%n%n
> 
> But when I read the log file on the SocketServer in does not 
contain any location info.
> I am able to find the exact same log statement on both 
client/server and SocketServer, but on the SocketServer location info 
is missing!
> 
> I initialize the SocketServer like this:
> log4j.appender.socketserver = org.apache.log4j.net.SocketAppender
> log4j.appender.socketserver.RemoteHost = 127.0.0.1
> log4j.appender.socketserver.Port = 8889
> 
> 
> Thomas Saxtoft
> 
> 
> --
> To unsubscribe, e-mail:   <ma...@j...>
> For additional commands, e-mail: <ma...@j...>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Missing location thru SocketServer (was: Interesting Problem)

Posted by Thomas Saxtoft <t....@sondagsavisen.dk>.
Hi Gautam

Finally I got that far. Now I get location information on both client and server. Thank you Gautam.
But I still has got a problem. I don't get any location info thru my Log4j SocketServer. 
I write to a log file on the client, the server and the socket server using the same ConversionPattern:

log4j.appender.R.layout.ConversionPattern=[slf5s.start]%d{DATE}[slf5s.DATE]%n\
%p[slf5s.PRIORITY]%n%x[slf5s.NDC]%n%t[slf5s.THREAD]%n\
%c[slf5s.CATEGORY]%n%l[slf5s.LOCATION]%n%m[slf5s.MESSAGE]%n%n

But when I read the log file on the SocketServer in does not contain any location info.
I am able to find the exact same log statement on both client/server and SocketServer, but on the SocketServer location info is missing!

I initialize the SocketServer like this:
log4j.appender.socketserver = org.apache.log4j.net.SocketAppender
log4j.appender.socketserver.RemoteHost = 127.0.0.1
log4j.appender.socketserver.Port = 8889


Thomas Saxtoft


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


RE: Interesting Problem

Posted by gautam <ga...@applabs.net>.
Hello Thomas,

Log4J uses the debug information in Java class files to generate the
"Location" information. In order to see this info, your source has to be
compiled with the "-g:...." option of "javac".

Please try compiling with "javac -g ....." or "javac -g:lines,vars,source
.....".

For example,
javac -verbose -classpath
./libs/log4j-1.2.6.jar;./libs/junit.jar;./libs/servlet.jar; -d
./build/ -g:lines,vars,source @sourcefiles.txt

Check the javac documentation at
http://java.sun.com/j2se/1.3/docs/tooldocs/win32/javac.html#options

I have tested the above using a plain Java class and a servlet (LF5Test in
the logs below) running under Tomcat 4.0.5/JDK 1.3.1_04. Without debug
information I get :

[slf5s.start]30 Oct 2002 13:41:59,953[slf5s.DATE]
DEBUG[slf5s.PRIORITY]
[slf5s.NDC]
HttpProcessor[8080][1][slf5s.THREAD]
LF5Test[slf5s.CATEGORY]
LF5Test.init(Unknown Source)[slf5s.LOCATION]
Hello, my name is Homer Simpson.[slf5s.MESSAGE]

With debug information I get :

[slf5s.start]30 Oct 2002 13:32:13,687[slf5s.DATE]
DEBUG[slf5s.PRIORITY]
[slf5s.NDC]
HttpProcessor[80][4][slf5s.THREAD]
LF5Test[slf5s.CATEGORY]
LF5Test.init(LF5Test.java:42)[slf5s.LOCATION]
Hello, my name is Homer Simpson.[slf5s.MESSAGE]

Hope this helps.

Regards

Gautam Satpathy

-----Original Message-----
From: Thomas Saxtoft [mailto:t.saxtoft@sondagsavisen.dk]
Sent: Tuesday, October 29, 2002 7:39 PM
To: log4j-user@jakarta.apache.org
Subject: Re: Interesting Problem


Gautam, please read my posting here
http://groups.yahoo.com/group/Log4J/message/2852
As you can see I get the location information on the client but not on the
server. I have made a typo in that posting. Where I do get location
information is on the client side.

What would I write directly in the command line, when not using Ant? I'm
referring to the debug stuff in your post.

Thomas

--- In Log4J@y..., "gautam" <ga...@a...> wrote:
> Hello,
>
> Log4J does not output the classname and line number when using the "%F:%L"
> pattern if the class files do not have debug information. In ANT 1.5
(which
> I am using), the "debug" attribute of the javac task has to be set to
"on".
> Also the "debuglevel" attribute should be set to "lines" ("lines, vars,
and
> source"). The "debug" attribute defaults to "off" and hence the
"debuglevel"
> attribute is ignored. With debug="on" debuglevel="lines", the javac -g
> option used is "-g:lines". Using the ANT 1.5 defaults, you end up the
> "-g:none". Result; No debug info in class files and ?:? in Log4J logs.
>
> My javac target has the following:
>
> <javac srcdir="${java.source.dir}" destdir="${build.dir}" debug="on"
> debuglevel="lines">
> 	<classpath refid="compile.classpath"/>
> </javac>
>
> With these two attributes in my build file, Log4J is able to find the
> required debug information and displays output like the following :
>
> INFO [main] [model.AbstractDataListHandler] {3875}
> (AbstractDataListHandler.java:263) - Leased the DataListHandler. Lease
> Counter = 1
>
> I suspect the defaults for these two attributes were different in earlier
> ANT versions. I have to check the source to make sure.
>
> Hope this helps.
>
> Regards,
>
> Gautam Satpathy



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>




--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Interesting Problem

Posted by Thomas Saxtoft <t....@sondagsavisen.dk>.
Gautam, please read my posting here http://groups.yahoo.com/group/Log4J/message/2852
As you can see I get the location information on the client but not on the server. I have made a typo in that posting. Where I do get location information is on the client side.

What would I write directly in the command line, when not using Ant? I'm referring to the debug stuff in your post.

Thomas

--- In Log4J@y..., "gautam" <ga...@a...> wrote:
> Hello,
> 
> Log4J does not output the classname and line number when using the "%F:%L"
> pattern if the class files do not have debug information. In ANT 1.5 (which
> I am using), the "debug" attribute of the javac task has to be set to "on".
> Also the "debuglevel" attribute should be set to "lines" ("lines, vars, and
> source"). The "debug" attribute defaults to "off" and hence the "debuglevel"
> attribute is ignored. With debug="on" debuglevel="lines", the javac -g
> option used is "-g:lines". Using the ANT 1.5 defaults, you end up the
> "-g:none". Result; No debug info in class files and ?:? in Log4J logs.
> 
> My javac target has the following:
> 
> <javac srcdir="${java.source.dir}" destdir="${build.dir}" debug="on"
> debuglevel="lines">
> 	<classpath refid="compile.classpath"/>
> </javac>
> 
> With these two attributes in my build file, Log4J is able to find the
> required debug information and displays output like the following :
> 
> INFO [main] [model.AbstractDataListHandler] {3875}
> (AbstractDataListHandler.java:263) - Leased the DataListHandler. Lease
> Counter = 1
> 
> I suspect the defaults for these two attributes were different in earlier
> ANT versions. I have to check the source to make sure.
> 
> Hope this helps.
> 
> Regards,
> 
> Gautam Satpathy



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


RE: Interesting Problem

Posted by gautam <ga...@applabs.net>.
Hello,

Log4J does not output the classname and line number when using the "%F:%L"
pattern if the class files do not have debug information. In ANT 1.5 (which
I am using), the "debug" attribute of the javac task has to be set to "on".
Also the "debuglevel" attribute should be set to "lines" ("lines, vars, and
source"). The "debug" attribute defaults to "off" and hence the "debuglevel"
attribute is ignored. With debug="on" debuglevel="lines", the javac -g
option used is "-g:lines". Using the ANT 1.5 defaults, you end up the
"-g:none". Result; No debug info in class files and ?:? in Log4J logs.

My javac target has the following:

<javac srcdir="${java.source.dir}" destdir="${build.dir}" debug="on"
debuglevel="lines">
	<classpath refid="compile.classpath"/>
</javac>

With these two attributes in my build file, Log4J is able to find the
required debug information and displays output like the following :

INFO [main] [model.AbstractDataListHandler] {3875}
(AbstractDataListHandler.java:263) - Leased the DataListHandler. Lease
Counter = 1

I suspect the defaults for these two attributes were different in earlier
ANT versions. I have to check the source to make sure.

Hope this helps.

Regards,

Gautam Satpathy

-----Original Message-----
From: Thomas Saxtoft [mailto:t.saxtoft@sondagsavisen.dk]
Sent: Monday, October 28, 2002 1:15 PM
To: log4j-user@jakarta.apache.org
Subject: Re: Interesting Problem


> Has anyone else encountered the same problem?
Yes I have. And I have posted two times before to the list, without getting
any help, so I think that the problem is very rare. Thus I have not found
out what is wrong, but I will give it a try and change to another ant
version.

Thomas Saxtoft



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>




--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Interesting Problem

Posted by Thomas Saxtoft <t....@sondagsavisen.dk>.
> Has anyone else encountered the same problem?
Yes I have. And I have posted two times before to the list, without getting any help, so I think that the problem is very rare. Thus I have not found out what is wrong, but I will give it a try and change to another ant version.

Thomas Saxtoft



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>