File: tail.pl

package info (click to toggle)
liblinux-systemd-perl 1.201600-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 284 kB
  • sloc: perl: 640; makefile: 7
file content (32 lines) | stat: -rw-r--r-- 696 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/usr/bin/env perl

use v5.16.2;
use strictures;
use Time::Moment;
use Linux::Systemd::Journal::Read;

sub print_entry {
    my $entry = shift;
    if ($entry->{_SOURCE_REALTIME_TIMESTAMP}) {
        my $epoch_ms = $entry->{_SOURCE_REALTIME_TIMESTAMP};
        my $tm       = Time::Moment->from_epoch($epoch_ms / 1_000_000);
        print "$tm ";
    }

    say $entry->{MESSAGE} if $entry->{MESSAGE};
}

my $jnl = Linux::Systemd::Journal::Read->new;
$jnl->seek_tail;
$jnl->previous(10);
while (my $entry = $jnl->get_next_entry) {
    print_entry($entry);
}

while (1) {
    $jnl->wait;
    say "Done waiting";
    while (my $entry = $jnl->get_next_entry) {
        print_entry($entry);
    }
}