This project provides a capability to tail log files in a web browser. It uses the emerging websockets technology to stream new log lines to the browser for display in a scrollable text area. The log files tailed may be either on a filesystem locally mounted on the web application server, or on a remote server accessible via ssh.
The client-side software is written in Javascript, and browser compatibility as at autumn 2012 is as follows:
A comprehensive table of browser websocket support is here.
The server-side implementation of websockets does not as yet have a standard Java API. Therefore different web container providers require the use of container-specific classes to service websocket actions.
The implementation provided here comes with:
A separate Play framework project using the common core is available [here]().
There is no reason implementations could not be provided for other containers without too much difficulty.
git clone url
logviewer-common/src/main/resources/LogConfigDefault.properties
to adjust log
directory if requiredJAVA_HOME
set to reference a Java 6 JDK (not JRE), e.g. on Windows:
set JAVA_HOME=C:\Program Files\Java\jdk1.6.0_35
mvn.bat clean install
cd logviewer-webapp
mvn.bat -P jetty clean jetty:run
cd logviewer-webapp
mvn.bat -P tomcat clean tomcat7:run
cd logviewer-grizzly
mvn.bat exec:java
Click the pick log File pulldown to select a file to be tailed.
ssh://userid@hostname/path/to/file
Note that, at the time of writing, the standard Eclipse Maven plugin m2e has an issue whereby source code cannot be found when debugging with the above Jetty/Tomcat7 run configuratations: this is due to dynamic code loading, see the bug report. As an interim fix, an additional m2e extension plugin may be installed from here which provides the currently missing functionality.
Execution of the command:
mvn.bat javadoc:javadoc
at base directory level will result in Javadoc being created under javadoc/site/apidocs
.
Communication between client- and server-side is very simple, using one JSON-encoded object, declared as a LogMessage
in the Java codebase. On loading the web page the user is presented with a list of available log files, and
when one is selected then updates are sent to refresh the web page text area. The updating is continuous, unless
paused via the provided checkbox.
The following additional Javascript libraries are used:
The server-side component implements the appropriate container servlet and responds to the messages as necessary. We use the Apache CommonsIO Tailer to perform the tracking of the log file.
A simple implementation of the standard Java Executor interface is provided to manage the necessary thread pool.
A utility program named LogGenerator
is provided: it writes to a log file on a regular basis to simulate what
would happen with a real log file, and is useful during testing. The log file location is configured in
logviewer-common/src/main/resources/generator.log4j.properties
.
To run the generator, from the main working directory do the following:
set JAVA_HOME=C:\Program Files\Java\jdk1.6.0_35
cd logviewer-common
mvn.bat -P generator exec:java -Dexec.args=100
which generates 100 lines of output then exits. Omit the line limit number to make the program run indefinitely.