Log4j mode


Log4j mode is a major mode for viewing log files in Emacs. It can be used to view any text based log file, even though the name refers to a specific logging package. Log4j mode provides syntax highlighting, filtering, and source code browsing.

There are many applications that can be used to view log files, but using Log4j mode allows you to do it without leaving Emacs. It also provides good integration with the source code.


The major features of Log4j mode are described below. See screenshots for examples of how this looks in GNU Emacs.

Syntax highlighting

Log4j mode uses customizable regexps with keywords such as DEBUG and ERROR to syntax highlight log records. Different faces are used for different log levels. The user can customize both the regexps, and the faces that are used for syntax highlighting.


Log4j mode can filter a log file buffer using keywords specified by the user, creating a new buffer that contains only matching log records. When the source buffer is auto reverted, the filter buffer will be updated too.

To filter a log file buffer, type C-c C-s, and enter the desired filter criteria - any number of keywords separated by spaces. Log records that contain any of the words in the include list, and none of the words in the exclude list, will be copied to the filter buffer. All other log records will be discarded. To stop filtering the log file buffer, just type C-c C-s again.

Source code browsing

Source code browsing is provided using jtags - an Emacs package for editing and browsing Java source code. It is possible to jump from a log file to a point in the source code where a certain log record was generated.

To show the source code for a Java identifier found in the log file, place the point in the identifier, and type C-c C-b. Log4j mode will parse the expression around point, and look up the Java identifier found using package jtags. If you are not using jtags, or if you are not developing in Java, you can still use the built-in tags lookup feature. Type M-. to run the find-tag command in the etags package.


The latest version of Log4j mode has been tested in GNU Emacs 23.1 and GNU Emacs 24.5 running on Windows 7.


Download the latest release version of Log4j mode here, and start viewing your log files in color today. The release notes can be found here. Installation notes are included within the Emacs Lisp file itself. GNU Emacs users can also download and install Log4j mode from MELPA.

The latest development version of log4j-mode can be found in the Git repository.