Real time Java server logs in your web browser
IMPORTANT: Real-time log monitoring in a browser-add on is no longer supported with LogDigger Connector 3.0. We plan to address this soon with a browser independent solution using server push mechanism. Stay tuned! Follow us on @logdigger .
In this tutorial we’ll show you how you can use free LogDigger tools to get request-scoped log messages from your Java based web application right into your browser.
How does it work?
We’re going to use the LogDigger Connector for Java and accompanying add-on for Firefox. Here’s a somewhat simplified explanation of how it works:
- When Firefox sends an HTTP request to your server, the add-on inserts an additional header that activates LogDigger (LD) servlet filter.
- The LD servlet filter collects log messages related to the request and, as a part of the response header, returns a “token” that identifies your logs.
- The Firefox add-on uses the received token to send an additional HTTP request to the server, this time requesting the log messages.
- The LD servlet filter fulfills this second request, sending logs back to the browser (so this second request doesn’t reach your application).
Using LogDigger console in Firefox
LogDigger console appears as a tab in Firebug, so first go and get Firebug if you don’t have it already. Next, download and install Firefox add-on with LogDigger console. (Due to historical reasons, LogDigger console is not available as a separate download but is included with our BugDigger add-on for Firefox product, which is also free.) If asked, allow Firefox to retrieve the extension from bugdigger.com.
After installing add-on and restarting the Firefox, open http://testlab.logdigger.com/. That’s a simple application we’re going to use here to test our real-time server log monitoring. LogDigger will not request logs from the server unless it’s enabled, so open Firebug and enable LogDigger panel for the current site:
The Test Lab can log a desired number of messages and exceptions using Log4J, Commons Logging and java.util.logging. Choose at least one logging framework, submit the form and server logs should appear in the LogDigger console:
In accordance with server logging settings you will see only informational and error messages. Now, in LogDigger console change the logging level to DEBUG and submit the form again. This time you will get a long list of log messages that also includes framework’s logs.
What happens on the server is that the LogDigger Connector temporary changes the application logging level while your request is being handled.
Now it’s time to add the LogDigger Connector to your application.
Installing LogDigger Connector
LogDigger Connector natively supports Log4j and java.util.logging but, with the help of adapters (see SLF), can be used with other logging frameworks as well. If you’re using Log4j, version 1.2.15 or higher is required.
After you download LogDigger Connector, copy logdigger-connector–all.jar to your WEB-INF/lib directory and add LogDigger servlet filter to the web.xml:
LogDiggerServletFilter com.logdigger.connector.servlet.LogDiggerConnectorFilter config AllowMonitoring Collect logs LogDiggerServletFilter /*
Behavior of LogDigger servlet filter is controlled by DSL-like (domain-specific language) directives specified as a value of the config parameter. The above configuration tells LogDigger filter to allow log monitoring and to collect logs for all supported frameworks.
That’s all! Start your application, direct Firefox to it, enable LogDigger and see how it works for you.
Controlling access to logs
We can’t stress enough how important it is that you put restrictions on who can pull your server logs, especially when going live with your application.
While you can write your own log request authorizer, LogDigger Connector provides a default implementation that can filter requests depending on the presence of a session attribute, server name, remote IP address or host name (as Java regexp expressions). For example:
... config AllowMonitoring authorizer=servlet remoteIP=192.168.1.[1-9]* userRole=admin Collect always logs ...
For additional details please check the documentation.