Logview major mode for Emacs provides syntax highlighting, filtering and other features for various log files. The main target are files similar to ones generated by Log4j, Logback and other Java logging libraries, but there is really nothing Java-specific in the mode and it should work just fine with any log that follows similar structure, probably after some configuration.
The mode is meant to be operated in read-only buffer, so all the command bindings lack modifiers.
Out-of-the-box the mode should be able to parse standard SLF4J (Log4j,
Logback) files as long as they use ISO 8601 timestamps and certain
UNIX files in
M-x package-install RET logview RET
to install it.
Alternatively, installing Logview from source is not difficult either. First, clone the source code:
$ cd SOME-PATH $ git clone https://github.com/doublep/logview.git
Now, from Emacs execute:
M-x package-install-file RET SOME-PATH/logview
Alternatively to the second step, add this to your
(add-to-list 'load-path "SOME-PATH/logview") (require 'logview)
Since there is no standard log file format, Logview mode has to try and guess how the log file it operates on is formatted. It does so by trying to parse the very first line of the file against various submodes it has.
If it succeeds in guessing, you will see major mode specifed as ‘Logview/...’ in the modeline, where the second part is the submode name.
In case it fails, you will see it complain in the echo area. The buffer will also not be highlighted or switched to read-only mode, so you will be able to edit it.
What to do if Logview mode fails to guess format
This depends on why it fails. If the mode doesn’t know about this
log format at all, customize the relevant options.
C-c C-s will
show you the three variables that are important for submode guessing.
You will need to customize at least one of those, or maybe all three.
All the variables are well-documented in customization interface.
However, it is also possible that Logview fails because it currently
looks only at the first line in the file. If real log entries in your
logs do not start at the very beginning, automatic guessing will not
succeed even when you have already registered the submode. In this
case, you can force Logview to switch to appropriate submode using
C-c C-c shortcut. Remember that you still need to have it
In case you don’t want to manually select submode each time in such
cases, you can set up some automatic switching from a hook using Elisp
If you think your log format is standard enough, you can open an issue and request format addition to the list of mode built-ins.
Nearly all commands have some use for prefix argument. It can be usually just guessed, but you can always check individual command documentation within Emacs.
When buffer is switched to read-write mode, Logview automatically deactivates all its commands so as to not interfere with editing. Once you switch the buffer back to read-only mode, commands will be active again.
- All standard Emacs commands
- Move to the beginning of entry’s message:
- Move to next / previous entry:
- Move to next / previous ‘as important’ [*] entry:
- Move to next / previous entry in the navigation view:
- Move to the next / previous entry with large timestamp gap after the
- Same as above, but only considering entries in the same thread:
- Move to first / last entry:
[*] ‘As important’ means entries with the same or higher level. For example, if the current entry is a warning, ‘as important’ include errors and warnings.
Narrowing and widening
- Narrow from / up to the current entry:
- Widen upwards / downwards only:
Filtering by entry level
- Show only errors:
- Show errors and warnings:
- Show errors, warnings and information:
- Show all levels except trace:
- Show entries of all levels:
- Show entries ‘as important’ as the current one:
Always show entries of certain levels
It is possible to always display entries of certain levels, regardless of any additional text filters.
- Always show errors:
- Always show errors and warnings:
- Always show errors, warnings and information:
- Always show all levels except trace:
- Disable ‘always show’ feature:
Filtering by entry’s logger name, thread or message
- Edit current name, thread and message filters:
f(pops up a separate buffer)
- Add name include / exclude filter:
- Add thread include / exclude filter:
- Add message include / exclude filter:
- Reset level filter:
- Reset name filters:
- Reset thread filters:
- Reset message filters:
- Reset all filters:
- Reset all filters, widen and show all explicitly hidden entries:
- Switch to a view:
- Choose navigation view (for
- Select a view to highlight its entries:
- Remove view highlighting:
- Save the current filters as a view for this submode:
- Save the current filters as a global view:
- Edit submode views:
V e(pops up a separate buffer)
- Edit all views:
V E(pops up a separate buffer)
- Delete a view by name:
Explicitly hide or show individual entries
- Hide one entry:
- Hide entries in the region:
- Show some explicitly hidden entries:
- Show explicitly hidden entries in the region:
- Show all manually hidden entries in the buffer:
In Transient Mark mode
s operate on region when mark is
Entry timestamp commands
- Replace timestamps with their difference to that of the current
- Same as above, but only within the same thread:
- Go to the entry difference to which timestamp is shown:
- Don’t show timestamp differences:
- Don’t show timestamp differences for this thread:
Timestamp differences are displayed in seconds.
Explicitly hide or show details of individual entries
The mode terms all message lines after the first ‘details’. Oftentimes these contain exception stacktrace, but most logging libraries let you write anything here.
- Toggle details of the current entry:
- Toggle details of all entries in the region:
- Toggle details in the whole buffer:
- Show all manually hidden entry details in the buffer:
In Transient Mark mode
d operates on region when mark is active.
Change options for the current buffer
These options can be customized globally and additionally temporarily changed in each individual buffer.
- Change gap length for
z nand similar commands:
- Toggle Auto-Revert mode:
- Toggle Auto-Revert Tail mode:
- Toggle ‘copy only visible text’:
- Toggle ‘search only in messages’:
- Toggle ‘show ellipses’:
- Pulse (briefly highlight) the current log entry:
- Manually choose appropriate submode and timestamp format:
- Customize options that affect submode selection:
- Bury buffer:
- Refresh the buffer (appending, if possible) preserving active filters:
- Append log file tail to the buffer:
- Revert the buffer preserving active filters:
- Universal prefix commands are bound without modifiers:
In addition to level filtering, Logview supports filtering by entry’s logger name, thread and message.
These filters are regular expression and come in two kinds: include and exclude filters. If at least one include filter is set, only those entries where relevant part matches at least one of regular expressions are shown, all others are filtered out. If any exclude filter is set, all entries where relevant part matches its regular expression are filtered out (regardless of any other filters) and hidden.
Easiest way to add filters is by using
A commands (add
include/exclude name filter correspondingly),
M (message filters). You can reset all filters
of given type:
r a for name,
r t for thread and
r m for message
R for all filters at once.
However, oftentimes you need to adjust existing filters, e.g. to fix a
typo or simply change one, while keeping others the same. For this
f command. It pops up a separate buffer with all
currently active filters (both level and text), which you can edit as
you like, using any standard Emacs features.
Lines beginning with ‘#’ character are comments. They and empty lines are ignored. Lines for level filters must start with prefix ‘lv ’ (note the single trailing space!) for normal filtering or ‘LV ’ for ‘always show’ pseudo-filter, and contain the textual level representation afterwards, just as you would see it in the logfile. For example:
lv DEBUG LV ERROR
means “show all entries except trace-level, and additionally show all errors with no regard to text filters.”
Lines for text filters are similar. They must start with ‘a+ ’ (again, remember the trailing space) for name inclusion filters, ‘a- ’ for name exclusion, and similarly ‘t+ ’, ‘t- ’, ‘m+ ’, ‘m- ’ for thread and message filters. Additionally, multiline message filters must use ‘.. ’ prefix (two dots and a space) for continuation lines. For example:
a+ database m+ ^insert.+ .. values
means “show entries with word ‘database’ in the logger name and which message has a line beginning with ‘insert’ and the line after that beginning with ‘values’.”
The buffer mode has some syntax highlighting support, so you should
see if anything goes wrong. The easiest way to figure it out is to
add a few filters using commands described earlier and then open this
f and see how they are represented.
Filter regexp details
Regular expressions can be matched against entry parts either
case-sensitively or case-insensitively, depending on standard Emacs
Filters are matched against relevant entry parts as strings, not
against the whole buffer. Therefore, you can use
characters for the expected meaning. For example, adding
name exclusion filter will hide all entries where logger name begins
with string ‘org’.
Unlike name and thread filters, message filters can span multiple
lines. To enter linefeed in message buffer (after
C-q C-j. When editing a multiline filter with
f, prefix all
continuation lines with ‘.. ’.
T default to the name (or thread) of the
current entry. You can also use
<up>) to browse history of
previously entered values and
<down>) for a few default
Views are named sets of filters that you can activate quickly. They are especially useful if you use name or message filters a lot, and often find yourself typing in the same filters over and over again.
The easiest way to define a view is by first adding all the filters
you need. This way you can see in the buffer if the filtering result
matches what you expect. After you are satisfied, type
V s and a
name for the new view. Notice that the mode line now displays name of
the view in square brackets after the submode name, e.g.:
R to reset all the filters. All previously hidden entries
will be shown again and the view name disappear from the mode line.
However, to restore the filters now you don’t have to re-create them
one-by-one. Simply type
v and whatever name you used when saving
your first view. You can also use text completion to pick among all
the defined views.
Remember that further filtering doesn’t affect view definition. If
you want to change a view, save filters as a view with the same name
again, and confirm that you do want to replace the previous
definition. Alternative way is to edit views using
V e. This pops
up a separate buffer just like
f command does, but instead of
filters you will edit all defined views for the current submode at
once. This way you can change existing definitions, delete unneeded
or add more. Commands like
V s or
V d (delete a view by name) can
be seen as just a convenience.
Views come in two kinds: globally accessible and bound to a specific
submode. This distinction is important if you use logs of different
kinds. Most often you need submode-specific views, because text
filters usually can’t be meaningfully applied without changes to
different programs. When you use
v command, only the views for the
current submode plus any global views are available for selection.
In addition to applying view filters, it is also possible to move
between entries in a view without activating it. For this, define a
view and then set it as as a ‘navigation view’ with
V n command.
After this, use commands
M-p to quickly navigate forward
and backward. Remember that these commands skip all hidden entries,
whether because of your main view (or filters) or manual entry hiding.
Finally, you can highlight all entries in a view, or, more precisely,
those that are visible currently. This can be done with
command. Cancel this by highlighting entries from a different view or
removing highlighting altogether with
You can have any number of named views. Their definitions are stored permanently across Emacs session and are available from all Logview buffers.
At any time you can switch to a view, i.e. replace current filters with those stored in the view’s definition. Changing filters itself doesn’t alter any view definitions.
You can choose one navigation view, independently from the currently applied view. It is used by commands
You can highlight entries of a view, again, independently from current or navigation view.