Linux-Systemd
view release on metacpan or search on metacpan
lib/Linux/Systemd/Journal/Write.pm view on Meta::CPAN
package Linux::Systemd::Journal::Write 1.201600;
# ABSTRACT: XS wrapper around sd-journal
# TODO Helper script to generate message catalogs?
# http://www.freedesktop.org/wiki/Software/systemd/catalog/
# TODO make sure all text is utf8
use v5.10.1;
use Moo;
use Carp;
use XSLoader;
XSLoader::load;
has app_id => (
is => 'ro',
lazy => 1,
default => sub {
require File::Basename;
return File::Basename::basename($0);
},
);
has priority => (
is => 'ro',
lazy => 1,
default => 6,
isa => sub {
die 'Invalid log level' unless (defined $_[0] && $_[0] =~ /^[0-7]$/);
},
);
has caller_details => (
is => 'ro',
default => 1,
);
has caller_level => (
is => 'ro',
default => 0,
);
sub print {
my ($self, $msg, $pri) = @_;
$pri //= $self->priority;
__sd_journal_print($pri, $msg);
return 1;
}
sub send {
my $self = shift;
my $data;
if (scalar @_ == 2 && !ref $_[0]) {
my $ref = ref $_[1];
if ($ref eq 'HASH') {
$data = {%{$_[1]}};
} elsif ($ref eq 'ARRAY') {
lib/Linux/Systemd/Journal/Write.pm view on Meta::CPAN
Will be used to set C<SYSLOG_IDENTIFIER>. Defaults to C<basename($0)>;
=head2 C<priority>
Default log priority. See L</"Log Levels">
=head2 C<caller_details>
Boolean controlling whether to log the C<CODE_FILE>, C<CODE_LINE>, and
C<CODE_FUNC> of the L<caller>.
Optional. Defaults to C<true>;
See also L<systemd.journal-fields(7)>
=head2 C<caller_level>
If this module is not being used directly, but through some proxy module for
instance, C<caller_level> is used to determine the number of frames to look back
through.
Optional. Defaults to C<0>;
=head1 METHODS
=head2 C<print($msg, $pri?)>
$msg should be either a string. $pri is optional, and defaults to $self->priority
=head2 C<send($msg_or_data, $data?)>
If there is one arg, it may be a simple string to log. Or, it could be a hashref
or an arrayref. In this case, one of the keys sent MUST be 'message'.
If there are two args, the first must be the string to use as a message, the
second a hashref or arrayref. In this case, a key called message should not be
set.
Finally, C<send> can also be called with an array of key => values, one of which
must be message.
Keys will be uppercased.
=head2 C<perror($msg)>
Logs the string of the current set C<errno>, prefixed with C<$msg>.
=head1 SEE ALSO
=over 4
=item *
L<Log::Journald>
At some point between me writing this module and getting around to releasing it,
another module was released to write the journal.
=item *
L<systemd|http://www.freedesktop.org/wiki/Software/systemd/>
The main C<systemd> page.
=item *
L<sd-journal(3)>
Man page of the C API
=back
=head1 AUTHOR
Ioan Rogers <ioanr@cpan.org>
=head1 COPYRIGHT AND LICENSE
This software is Copyright (c) 2020 by Ioan Rogers.
This is free software, licensed under:
The GNU Lesser General Public License, Version 2.1, February 1999
=cut
( run in 0.621 second using v1.01-cache-2.11-cpan-39bf76dae61 )