Howdy,
I had actually implemented something like that for the system.out/.err
log ($CATALINA_HOME/logs/catalina.out by default) as well as the host
log ($CATALINA_HOME/logs/localhost_log.yyyy-mm-dd.txt by default).  It's
not too difficult to implement:

- Add a <context-param> to the web.xml file to the context in which you
"log monitoring servlet" will run:
<context-param>
  <param-name>tomcatLogDir</param-name>
  <param-value>/var/tomcat/logs</param-value>
</context-param>
- Have your servlet simply open a FileReader (buffered ideally, although
you still have large memory consumption) to the file, e.g:
String logDir = getServletContext().getInitParameter("tomcatLogDir");
File systemOutLogFile = new File(logDir, "Catalina.out");
FileReader fileReader = new FileReader(systemOutLogFile);
BufferedReader bin = new BufferedReader(fileReader);
String line = null;

Out.println("System.out Log File Contents:");

while((line = bin.readLine()) != null) {
  out.println(line);
}

bin.close();
fileReader.close();

Of course, I did all this before I started using log4j.  When I started
using log4j, I eliminated all System.out, System.err, printStackTrace,
and getServletContext().log(...) calls.  Everything went to log4j.  I
now use Chainsaw for live monitoring (and filtering, and saving, and
more) of the log files.  This solution is container-independent and thus
portable, unlike the above.

Yoav Shapira
Millennium ChemInformatics


>-----Original Message-----
>From: Peng Tuck Kwok [mailto:[EMAIL PROTECTED]]
>Sent: Monday, February 17, 2003 4:04 AM
>To: [EMAIL PROTECTED]
>Subject: Reading large log files with a servlet.
>
>I've noticed that app servers like Sun One allows a administrator to
>view the contents of the log file in the administrative interface. Has
>anyone have any experience in doing that with a servlet in tomcat ?
>Could you share you experience please ? Thanks.
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: [EMAIL PROTECTED]
>For additional commands, e-mail: [EMAIL PROTECTED]




This e-mail, including any attachments, is a confidential business communication, and 
may contain information that is confidential, proprietary and/or privileged.  This 
e-mail is intended only for the individual(s) to whom it is addressed, and may not be 
saved, copied, printed, disclosed or used by anyone else.  If you are not the(an) 
intended recipient, please immediately delete this e-mail from your computer system 
and notify the sender.  Thank you.


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to