You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Bart Vandewoestyne <Ba...@telenet.be> on 2009/12/04 16:02:51 UTC

Logging with Log4J

Hello list,

Up until now, I have used simple System.out.println() statements
to do the logging of my web applications, but I want to start
using a more advanced system with more possibilities.  Log4J
seemed like a good choice.  The most important thing for me is that the
log messages are written nicely into a separate file.

Based on stuff I found using Google, I have created a
log4j.properties file (see bottom of this mail) which is saved under
the WEB-INF/classed directory.

It seems like things are working *partly*... because although I
do specify the file testbart.log, there is no testbart.log file
on the tomcat server (i checked this with find / -name
testbart.log as root).  I *do* however see log messages appearing
in /var/log/syslog, but that is not what i want.  I want them to be written
into a separate logfile.

Can somebody point me in the right direction here?  All i want is
that the logs for my webapp (written using Log4J) are written in to a 
file

/var/log/tomcat/mywebapp.log

It is however unclear to me where i have to configure this... is
it a Debian config thing?  Is it a Tomcat config thing?  Is it a
log4J config thing?  Do I config this in the log4j.properties
file?

Just for the record: we're using Tomcat 5.5 on a Debian GNU/Linux
stable system.

Kind regards,
Bart

----------------------- log4j.properties ------------------------------
log4j.rootLogger=DEBUG, cons
log4j.logger.com.jspservletcookbook=, myAppender

# The root logger's appender
log4j.appender.cons=org.apache.log4j.ConsoleAppender

# The com.jspservletcookbook logger's appender
log4j.appender.myAppender=org.apache.log4j.RollingFileAppender

log4j.appender.myAppender.File=testbart.log
log4j.appender.myAppender.MaxBackupIndex=1
log4j.appender.myAppender.MaxFileSize=1MB

# The root logger's layout
log4j.appender.cons.layout=org.apache.log4j.SimpleLayout

# The com.jspservletcookbook logger's layout
log4j.appender.myAppender.layout=org.apache.log4j.PatternLayout

log4j.appender.myAppender.layout.ConversionPattern=%-5p Logger:%c{1} Date: %d{ISO8601} - %m%n
----------------------------------------------------------------------

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Logging with Log4J

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Bart,

On 12/5/2009 7:55 AM, Bart Vandewoestyne wrote:
>>> log4j.appender.myAppender.File=testbart.log
>>
>> I would have done:
>> log4j.appender.myAppender.File=/var/log/tomcat/mywebapp.log
>>
>> Make sure that the user running Tomcat has rights to write to that
>> file/directory.
> 
> OK.  I also figured out that it works if i specify the absolute
> path /var/log/tomcat/mywebapp.log
> 
> I thought that if i only specify the filename, by default it
> would arrive in /var/log/tomcat/ but apparently this is not the
> case.

Why would you think that the file would magically appear in
/var/log/tomcat? There is no default log file location for log4j, nor
for any logging mechanism that I know of. The best you could hope for is
the current working directory of the process, which could be anything.
It's always best to fully-specify path names.

> Anyway, my problem seems solved. All i have to do now is continue
> reading the Log4J docs to better understand and configure my
> logging :-)

Enjoy!

- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAksec9MACgkQ9CaO5/Lv0PDXMgCeNOq1OiKDb+r+6EenGHwZ1M8m
WiIAoKDCdo3ZBhqIQIVGcsP2/nhVQzYs
=h4Tp
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Logging with Log4J

Posted by Bart Vandewoestyne <Ba...@telenet.be>.
On Fri, Dec 04, 2009 at 05:08:05PM -0500, Christopher Schultz wrote:
>
> [snip]
> 
> > log4j.rootLogger=DEBUG, cons
> 
> See Jeffrey's suggestion in his post.

OK.  I changed that... and I'm working my way through the Log4J
docs to better understand how it works...
 
> > log4j.appender.myAppender.File=testbart.log
> 
> I would have done:
> log4j.appender.myAppender.File=/var/log/tomcat/mywebapp.log
> 
> Make sure that the user running Tomcat has rights to write to that
> file/directory.

OK.  I also figured out that it works if i specify the absolute
path /var/log/tomcat/mywebapp.log

I thought that if i only specify the filename, by default it
would arrive in /var/log/tomcat/ but apparently this is not the
case.

Anyway, my problem seems solved. All i have to do now is continue
reading the Log4J docs to better understand and configure my
logging :-)

Thanks!
Bart

-- 
	"Share what you know.  Learn what you don't."

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Logging with Log4J

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Bart,

On 12/4/2009 10:02 AM, Bart Vandewoestyne wrote:
> I *do* however see log messages appearing in /var/log/syslog, but
> that is not what i want.

That's very weird: you have no configuration whatsoever that would lead
me to believe that your webapp's messages are going to syslog. Are you
sure you don't have something else logging to syslog?

> /var/log/tomcat/mywebapp.log

[snip]

> log4j.rootLogger=DEBUG, cons

See Jeffrey's suggestion in his post.

> log4j.appender.myAppender.File=testbart.log

I would have done:
log4j.appender.myAppender.File=/var/log/tomcat/mywebapp.log

Make sure that the user running Tomcat has rights to write to that
file/directory.

- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAksZiEUACgkQ9CaO5/Lv0PDuAACgr9akSt+bLoUK66POxEq275/x
IucAoKz1XnMtclmhigcgSajbx9vkg7Lb
=vq1l
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


RE: Logging with Log4J

Posted by Jeffrey Janner <Je...@PolyDyne.com>.
Change your first line from "DEBUG, cons" to "DEBUG, myAppender"

-----Original Message-----
From: Bart Vandewoestyne [mailto:Bart.Vandewoestyne@telenet.be] 
Sent: Friday, December 04, 2009 9:03 AM
To: users@tomcat.apache.org
Subject: Logging with Log4J

Hello list,

Up until now, I have used simple System.out.println() statements
to do the logging of my web applications, but I want to start
using a more advanced system with more possibilities.  Log4J
seemed like a good choice.  The most important thing for me is that the
log messages are written nicely into a separate file.

Based on stuff I found using Google, I have created a
log4j.properties file (see bottom of this mail) which is saved under
the WEB-INF/classed directory.

It seems like things are working *partly*... because although I
do specify the file testbart.log, there is no testbart.log file
on the tomcat server (i checked this with find / -name
testbart.log as root).  I *do* however see log messages appearing
in /var/log/syslog, but that is not what i want.  I want them to be
written
into a separate logfile.

Can somebody point me in the right direction here?  All i want is
that the logs for my webapp (written using Log4J) are written in to a 
file

/var/log/tomcat/mywebapp.log

It is however unclear to me where i have to configure this... is
it a Debian config thing?  Is it a Tomcat config thing?  Is it a
log4J config thing?  Do I config this in the log4j.properties
file?

Just for the record: we're using Tomcat 5.5 on a Debian GNU/Linux
stable system.

Kind regards,
Bart

----------------------- log4j.properties ------------------------------
log4j.rootLogger=DEBUG, cons
log4j.logger.com.jspservletcookbook=, myAppender

# The root logger's appender
log4j.appender.cons=org.apache.log4j.ConsoleAppender

# The com.jspservletcookbook logger's appender
log4j.appender.myAppender=org.apache.log4j.RollingFileAppender

log4j.appender.myAppender.File=testbart.log
log4j.appender.myAppender.MaxBackupIndex=1
log4j.appender.myAppender.MaxFileSize=1MB

# The root logger's layout
log4j.appender.cons.layout=org.apache.log4j.SimpleLayout

# The com.jspservletcookbook logger's layout
log4j.appender.myAppender.layout=org.apache.log4j.PatternLayout

log4j.appender.myAppender.layout.ConversionPattern=%-5p Logger:%c{1}
Date: %d{ISO8601} - %m%n
----------------------------------------------------------------------

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org



*******************************  NOTICE  *********************************
This message is intended for the use of the individual or entity to which 
it is addressed and may contain information that is privileged, 
confidential, and exempt from disclosure under applicable law.  If the 
reader of this message is not the intended recipient or the employee or 
agent responsible for delivering this message to the intended recipient, 
you are hereby notified that any dissemination, distribution, or copying 
of this communication is strictly prohibited.  If you have received this 
communication in error, please notify us immediately by reply or by 
telephone (call us collect at 512-343-9100) and immediately delete this 
message and all its attachments.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org