0

I have a j2ee web application which uses log4j for logging. I want to have a log viewer on the admin page. This should allow the users to view the log4j logs on the application UI. Does anyone know how can this be implemented in java, maybe, - realtime scrolling logs would be great, - otherwise lets say last 500 lines of logs with manual refreshes can be done. The issue with the latter using file operations is that i am not sure how long each refresh would be as the log file can be 10 MiB in size before log4j generates a new file.

What would be the best way to do it. any pointers would be great.. Thanks

Ash
  • 128
  • 2
  • 11
  • Is it running on Linux? You could always pipe a stream from `tail -f`. –  Nov 04 '11 at 07:35
  • yes the server is a unix server. I can see the logs on the unix terminal with tail -f but how to view it on the application page in a browser. – Ash Nov 04 '11 at 08:56
  • would it be a possible (as in, a good idea) to invoke the native tail -f command from the application and then show the output on the page?? – Ash Nov 04 '11 at 09:51
  • Check out this thread: http://stackoverflow.com/questions/144807/java-log-viewer – dcernahoschi Nov 04 '11 at 11:34

3 Answers3

0

IMHO you can't manage files at low level like C, that's why you can't read the last X row from the file without you read the whole file.

But the Log4j can send the log to a database (JDBCAppender) and from a database you can manage the log easily.

Csujo
  • 507
  • 2
  • 6
0

you can do this, you have to look at the following constructs.

  1. in your log4j.xml for your appliction, make sure your appender is sending to a publically accessable folder.

  2. in your view application, everytime you refresh (a refesh button on the page), go to the server, read the file, spurt out the contents to your page.

  3. better still, the read request should be behind a JMS implementation, so it can read in the background without blocking the view request at the front. IE, if the file is quite large, you are not blocking requests to the servlet. Once you have finished the read, you can search for an occurence of a string to truncate the file contents (probably the output date and timestamp). It is going to be memmory intensive, but its been done quite a lot of times.

kevin the kitten
  • 344
  • 1
  • 2
  • 8
0

You can provide a rest api/url to access the servver log. It is easy for people to debug / bookmark / refresh.

r0ast3d
  • 2,639
  • 1
  • 14
  • 18