Skip to content

Commit 24452b0

Browse files
committed
More documentation, and .gitignore
1 parent a48a6ff commit 24452b0

File tree

2 files changed

+75
-5
lines changed

2 files changed

+75
-5
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
/Fluent-LibFluentBit-*
2+
/.build

lib/Fluent/LibFluentBit/Logger.pm

Lines changed: 74 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,84 @@
11
package Fluent::LibFluentBit::Logger;
2+
# VERSION
23
use strict;
34
use warnings;
45
use Carp;
56
use Time::HiRes 'time';
67
use JSON::MaybeXS;
78

9+
# ABSTRACT: Perl-style logger object that logs to the 'lib' input of fluent-bit
10+
11+
=head1 SYNOPSIS
12+
13+
my $logger= Fluent::LibFluentBit->new_logger;
14+
$logger->trace(...);
15+
$logger->debug(...);
16+
$logger->info(...);
17+
$logger->warn(...);
18+
$logger->notice(...);
19+
$logger->error(...);
20+
21+
=head1 DESCRIPTION
22+
23+
The fluent-bit library allows an input of type "lib" which is written directly from code
24+
in the same process. (this is the primary point of the library)
25+
26+
This logger object writes to that input, using a key of C<"message"> for the text of the
27+
log message, and a key of C<"status"> for the log-level.
28+
29+
=head1 ATTRIBUTES
30+
31+
=head2 context
32+
33+
An instance of Fluent::LibFluentBit. Read-only. Required.
34+
35+
=head2 input_id
36+
37+
The ID of the 'lib' input for libfluent-bit, which these messages are written into.
38+
Read-only. Required.
39+
40+
=head2 include_caller
41+
42+
Boolean. If set to true, this will inspect the caller on each log message and include that
43+
in the logged data as keys C<'file'>, C<'line'>, and C<'caller'> (package or function name
44+
where the call was made).
45+
46+
=cut
47+
48+
sub include_caller {
49+
$_[0]{include_caller}= $_[1] if @_ > 1;
50+
$_[0]{include_caller}
51+
}
52+
53+
=head1 METHODS
54+
55+
=head2 Log Delivery Methods
56+
57+
$logger->info("message");
58+
$logger->info(message => "message");
59+
$logger->info({ message => "message" });
60+
61+
Each method allows a single scalar, or hashref, or list of key/value pairs.
62+
A single scalar becomes the value for the key 'message'. They all return $self.
63+
64+
=over
65+
66+
=item trace
67+
68+
=item debug
69+
70+
=item info
71+
72+
=item warn
73+
74+
=item notice
75+
76+
=item error
77+
78+
=back
79+
80+
=cut
81+
882
sub new {
983
my $class= shift;
1084
my %attrs= @_;
@@ -14,11 +88,6 @@ sub new {
1488
bless \%attrs, $class;
1589
}
1690

17-
sub include_caller {
18-
$_[0]{include_caller}= $_[1] if @_ > 1;
19-
$_[0]{include_caller}
20-
}
21-
2291
sub _log_data {
2392
my ($self, $data, $level)= @_;
2493
$data= ref $data eq 'HASH'? { %$data } : { message => $data };

0 commit comments

Comments
 (0)