Log::Journald - Send messages to a systemd journal
use Log::Journald; use Sys::Syslog qw/:macros/; # Easy. journal_log(LOG_INFO, "Hello (1) from PID $$!"); # Send arbitrary fields, even binary data Log::Journald::send(PRIORITY => LOG_INFO, MESSAGE => "Hello (2) from PID $$!", PERL_PACKAGE => __PACKAGE__, _YOLO => "SW\x00AG") or warn "Could not send log: $!"; # Raw Log::Journald::sendv('PRIORITY=6', "MESSAGE=Hello (3) from PID $$!");
Please consider this an alpha quality code, whose API can change at any time, until we reach version 1.00.
This module wraps sd-journal(3) APIs for easy use in Perl. It makes it possible to easily use systemd-journald.service(8)'s structured logging capabilities and includes location of the logging point in the source code in the messages.
Backends for Log::Dispatch and Log::Log4perl exist: Use Log::Dispatch::Journald and Log::Log4perl::Appender::Journald respectively.
Log a message at given priority. Exported by default.
Returns true upon success, false while setting $! on failure.
$!
Log a message with given key-value pairs. MESSAGE and PRIORITY keys are mandatory. See systemd.journal-fields(7) for list and description of known fields.
MESSAGE
PRIORITY
Same as above, apart from that instead of key and value pair, strings that contain key and value concatenated with "=" are expected. This avoids an extra copy and might me slightly more efficient.
Sys::Syslog -- Traditiona logging mechanism. The module provides useful macros.
sd-journal(3) -- Description of C language API for journal.
systemd-journald.service(8) -- Manual of the journal service.
Log::Dispatch::Journald -- Log::Dispatch backend.
Log::Log4perl::Appender::Journald -- Log::Log4perl appender.
journal_log() terminates the message at a NUL byte. You need to use another interface to log binary data.
journal_log()
To get priority constants, you still need to include Sys::Syslog.
There's no way to override caller depth. Therefore if you add a wrapper for any of this module's interfaces, you'll get the location of the wrapper in the messages.
A way to disable or override inclusion of code location would be nice.
Copyright 2014 Lubomir Rintel
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
Lubomir Rintel, <lkundrak@v3.sk>
The code is hosted on GitHub http://github.com/lkundrak/perl-Log-Journald. Bug fixes and feature enhancements are always welcome.
To install Log::Journald, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Log::Journald
CPAN shell
perl -MCPAN -e shell install Log::Journald
For more information on module installation, please visit the detailed CPAN module installation guide.