STeN
STeN

Reputation: 6268

Access to servlet logs on localhost (jetty) when developing app for Google Application engine

I am prototyping an java servlet application using Google application engine. Is there any way how I can access the log4j servlet logs in when testing on localhost? E.g. if I use the Logger class instance and I call log.info("Request comes"); in HttpServlet::doGet() method I would like to use the tail+grep or other tools to analyze the logs during the development. Are those logs saved into some file? If using external tools is not possible I would like to see the logs at least into Eclipse console output.

When the application is deployed into Google (http://appengine.google.com/) cloud I can see my logs via web interface, but I need the access on localhost during the development.

Upvotes: 0

Views: 747

Answers (1)

Igor Artamonov
Igor Artamonov

Reputation: 35961

Log4j is easily configurable, I guess you know that you need to add `log4j.properties' into your classpath, etc? Other way, it have good documentation, see Configuration block.

If you need to put log into file, just add:

log4j.appender.file=org.apache.log4j.FileAppender
log4j.appender.file.file=/path/to/logfile.log
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.conversionPattern=%d{ABSOLUTE} %5p %t %c{1}:%M:%L - %m%n

where /path/to/logfile.log if log you can tail+grep

To put it into eclipse console (I guess it's just a console output), you have to add:

log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.conversionPattern=%d{ABSOLUTE} %5p %t %c{1}:%M:%L - %m%n

and don't forget about adding this appenders into an logger, for example into root logger:

log4j.rootLogger=INFO, stdout, file

Upvotes: 1

Related Questions