• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

can I use a Logger for writing debug statements?

 
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
can I write debugging statements in a jsp or servlet that will appear in one of the log files associated with a "Logger" entry in server.xml?
for example, I have the following entry for a Logger in server.xml, associated with a particular context:
<Logger className="org.apache.catalina.logger.FileLogger" prefix="imf_catali
na." suffix=".log" timestamp="true" verbosity="4"/>
what syntax should I use in a jsp to write a debugging statement that will appear in the logfile associated with this logger entry?
do Loggers even support this type of functionality, or is this why I need Log4J?
thanks,
John
 
John Holme
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ok, guys, I finally figured this one out myself:
the log() method of ServletContext can be used to write messages to the log file designated by the operative Logger object designated in server.xml. (Loggers can be defined at various levels of the Tomcat environment, including Context, Host and Engine. A logger defined at a lower level supplants one defined at a higher level.)
in a jsp, you can get the ServletContext and call it's log() method as follows:
ServletContext context =
getServletConfig().getServletContext();
context.log("LOG_MESSAGE");
as of Servlets 2.1, the ServletContext.log() method has 2 signatures:
log(java.lang.String message) AND
log(java.lang.String message, java.lang.Throwable throwable)
 
Rototillers convert rich soil into dirt. Please note that this tiny ad is not a rototiller:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic