Skip to content

About

Major mode to view journalctl's output in Emacs

Resources

Stars

88 stars

Watchers

5 watching

Forks

Latest commit

 

History

103 Commits

Folders and files

Repository files navigation

journalctl-mode.el

Introduction

This Emacs major mode is designed for viewing the output from systemd’s journalctl within Emacs. It provides a convenient way to interact with journalctl logs, including fontification, chunked loading for performance, asynchronous journalctl processes, follow mode, and a transient interface for building queries.

journalctl.v1.1.gif

Installation

To install, place journalctl-mode.el in your load-path and add the following to your .emacs file:

(require 'journalctl-mode)

The mode requires Emacs 27.1 or newer, the Emacs Lisp libraries transient and array, and a system with journalctl and systemctl available.

Alternatively, if journalctl-mode is available through one of your configured package archives, you can install it using use-package:

(use-package journalctl-mode
  :ensure t)

Define a global key

It might be a good idea to define a global key to journalctl with:

(global-set-key (kbd "C-c t") 'journalctl)

or with use-package:

(use-package journalctl-mode
  :ensure t
  :bind (("C-c t" . journalctl)))

Features

  • Fontification: Customize the appearance of errors, warnings, starting and finished processes, timestamps, hosts, and process names with faces.
  • Chunked Loading: Load journalctl output in manageable chunks for better performance.
  • Asynchronous Processes: journalctl output is collected asynchronously, so Emacs stays responsive while the command is running.
  • Keyword Highlighting: Define custom keywords for error, warning, starting, and finished log messages.
  • Transient Menu: Build journalctl queries interactively using output, source, constraint, and filter options.
  • Follow Mode: Run journalctl with -f and keep up with new log entries asynchronously.
  • Completion: Select known system units, user units, boots, output fields, facilities, output formats, and priority ranges from dynamically generated lists.

Usage

Once installed, journalctl-mode can be invoked with M-x journalctl.

The command initially loads up to 250 journal entries into the *journalctl* buffer and opens the transient menu. The menu allows journalctl command-line options to be combined dynamically and the query to be rerun without leaving Emacs.

The transient menu contains the following groups:

  • Output: --all, --no-full, --merge, --field, --quiet, --utc, and --output.
  • Sources: --machine, --directory, --file, --root, --image, and --namespace.
  • Constraint: kernel, system or user messages, boot, identifier, unit, user unit, facility, and priority.
  • Filters: --since, --until, reverse output, catalog explanations, line limit, and grep pattern.

From the transient menu:

KeyAction
SPCRun journalctl and keep the menu open
RETRun journalctl and close the menu
fRun journalctl in follow mode
qQuit the journalctl session

Follow mode starts journalctl -f with the currently selected transient options. The initial number of lines used for follow mode is controlled by journalctl-follow-lines. To keep the buffer from growing without limit, older lines are removed as new output arrives.

Customization

Customize the mode to your liking by setting the following variables:

  • journalctl-chunk-size: Number of lines per chunk (default 250).
  • journalctl-error-keywords: List of keywords to highlight as errors.
  • journalctl-warn-keywords: List of keywords to highlight as warnings.
  • journalctl-starting-keywords: Keywords for starting processes.
  • journalctl-finished-keywords: Keywords for finished processes.
  • journalctl-follow-lines: Number of initial lines to show in follow mode (default "240").
  • journalctl-default-options: List of default options in the transient menu (default ("--lines=240")).

The faces journalctl-error-face, journalctl-warning-face, journalctl-starting-face, journalctl-finished-face, journalctl-timestamp-face, journalctl-host-face, and journalctl-process-face can also be customized.

Key Bindings

KeyAction
+Rerun journalctl and open the transient menu
-Rerun journalctl and open the transient menu
nLoad next chunk of journalctl output
pLoad previous chunk of journalctl output
C-vMove 25 lines forward; load next chunk when necessary
M-vMove 25 lines backward; load previous chunk when necessary
qQuit journalctl mode

Other Packages

There is another package journalctl (rather than journalctl-mode) by James Ferguson that fetches and interleaves JSON data using multiple simultaneous asynchronous journalctl queries, while mine offers a UI for query-building and chunked asynchronous data loading.

License

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see https://www.gnu.org/licenses/.

Support

For support, feedback, or to contribute to the project, please visit the homepage at https://github.com/SebastianMeisel/journalctl-mode.

Acknowledgements

Thanks to all contributors and users for their support and feedback which continue to improve this mode.

About

Major mode to view journalctl's output in Emacs

Resources

Stars

88 stars

Watchers

5 watching

Forks

Releases

Packages

Contributors

Languages