1Log::Contextual::SimpleULsoegrgeCro(n3t)ributed Perl DocLuomge:n:tCaotnitoenxtual::SimpleLogger(3)
2
3
4

NAME

6       Log::Contextual::SimpleLogger - Super simple logger made for playing
7       with Log::Contextual
8

VERSION

10       version 0.008001
11

SYNOPSIS

13        use Log::Contextual::SimpleLogger;
14        use Log::Contextual qw( :log ),
15          -logger => Log::Contextual::SimpleLogger->new({ levels => [qw( debug )]});
16
17        log_info { 'program started' }; # no-op because info is not in levels
18        sub foo {
19          log_debug { 'entered foo' };
20          ...
21        }
22

DESCRIPTION

24       This module is a simple logger made mostly for demonstration and
25       initial experimentation with Log::Contextual.  We recommend you use a
26       real logger instead.  For something more serious but not overly
27       complicated, take a look at Log::Dispatchouli.
28

METHODS

30   new
31       Arguments: "Dict[
32         levels      => Optional[ArrayRef[Str]],
33         levels_upto => Level,
34         coderef     => Optional[CodeRef], ] $conf"
35
36        my $l = Log::Contextual::SimpleLogger->new({
37          levels  => [qw( info warn )],
38          coderef => sub { print @_ }, # the default prints to STDERR
39        });
40
41       or
42
43        my $l = Log::Contextual::SimpleLogger->new({
44          levels_upto => 'debug',
45          coderef     => sub { print @_ }, # the default prints to STDERR
46        });
47
48       Creates a new SimpleLogger object with the passed levels enabled and
49       optionally a "CodeRef" may be passed to modify how the logs are
50       output/stored.
51
52       "levels_upto" enables all the levels upto and including the level
53       passed.
54
55       Levels may contain:
56
57        trace
58        debug
59        info
60        warn
61        error
62        fatal
63
64   $level
65       Arguments: @anything
66
67       All of the following six methods work the same.  The basic pattern is:
68
69        sub $level {
70          my $self = shift;
71
72          print STDERR "[$level] " . join qq{\n}, @_;
73             if $self->is_$level;
74        }
75
76       trace
77
78        $l->trace( 'entered method foo with args ' join q{,}, @args );
79
80       debug
81
82        $l->debug( 'entered method foo' );
83
84       info
85
86        $l->info( 'started process foo' );
87
88       warn
89
90        $l->warn( 'possible misconfiguration at line 10' );
91
92       error
93
94        $l->error( 'non-numeric user input!' );
95
96       fatal
97
98        $l->fatal( '1 is never equal to 0!' );
99
100       Note: "fatal" does not call "die" for you, see "EXCEPTIONS AND ERROR
101       HANDLING" in Log::Contextual
102
103   is_$level
104       All of the following six functions just return true if their respective
105       level is enabled.
106
107       is_trace
108
109        say 'tracing' if $l->is_trace;
110
111       is_debug
112
113        say 'debuging' if $l->is_debug;
114
115       is_info
116
117        say q{info'ing} if $l->is_info;
118
119       is_warn
120
121        say 'warning' if $l->is_warn;
122
123       is_error
124
125        say 'erroring' if $l->is_error;
126
127       is_fatal
128
129        say q{fatal'ing} if $l->is_fatal;
130

AUTHOR

132       Arthur Axel "fREW" Schmidt <frioux+cpan@gmail.com>
133
135       This software is copyright (c) 2018 by Arthur Axel "fREW" Schmidt.
136
137       This is free software; you can redistribute it and/or modify it under
138       the same terms as the Perl 5 programming language system itself.
139
140
141
142perl v5.36.0                      2022-07-22  Log::Contextual::SimpleLogger(3)
Impressum