Git Product home page Git Product logo

jjournal's Introduction

Maven Package CodeQL

jjournal

Java API for reading systemd-journald logfiles

Overview

jjournal (AKA libjournal-java-reader) is a library for reading systemd journals with Java.

systemd has become a standard base component in many Linux distributions. Its centralised logging is not using files in /var/log anymore, it uses a specific, internal log database format. Accessing the logs, called "journals", can be done via the commandline tool journalctl. For programmatic access to these journals, though, there wasn't much to be found, save for the systemd C library itself.

Hence this library, which allows you to access these logs/journals from Java. It provides a number of filtering and accessing facilities, retaining the specific structure and model used by the systemd journals.

Dependencies

  • JNR FFI
  • JDK 8 and up

Getting Started

Installation

Maven

The maven artifact vector is

<dependency>
	<groupId>org.metabit.platform.interfacing</groupId>
	<artifactId>jjournal</artifactId>
	<version>0.3.6</version>
</dependency>

Latest version: Maven Central

Prerequisites

The runtime system has to have libsystemd installed and accessible via Java library path.

Usage

  1. Import the Journal class.
  2. Create an instance using the constructor flags indicating which systemd journal to access, and how.
  3. use member functions to access the journal.
  4. .close() the journal after use.

journald features like cursor, field lists, filters are implemented; additional helper functions like foreachInTimerange(), moveForwardUntilTime() etc. are available as well.

If you are unfamiliar with systemd journal concepts, see doc/about_systemd_journals.md or general documentation about it.

Examples

print messages for most recent minute from the journal of the current user:

 import org.metabit.platform.interfacing.jjournal.Journal;
 ...
 Instant now = Instant.now();
 Instant oneMinuteAgo = now.minusSeconds(60);
 
 try (Journal journal = new Journal(EnumSet.of(OpenFlags.CURRENT_USER)))
    {
    journal.foreachInTimerange(oneMinuteAgo,now,jj ->
        {
        final String msg = jj.readMessageField();
        System.err.println(msg);
        });
    }

Deployment

Make sure libsystemd is installed and accessible via Java library path on the runtime system the code is executed on.

(e.g. apt-get install libsystemd0)

Troubleshooting

jjournal is implemented as a JNR wrapper for the standard C systemd-library interface. Because of that, the systemd library must be present and accessible for the Java code using this library. Should this not be the case, the Journal() constructor will throw a RuntimeException.

License

Use of jjournal is free of cost.

  • GPL3: For non-commercial use, it is placed under GNU Public License 3.
  • APL2: For commercial use, or if you prefer this license, you get an Apache 2.0 license after registration, at no cost.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.