1Level(3) User Contributed Perl Documentation Level(3)
2
3
4
6 Log::Log4perl::Level - Predefined log levels
7
9 use Log::Log4perl::Level;
10 print $ERROR, "\n";
11
12 # -- or --
13
14 use Log::Log4perl qw(:levels);
15 print $ERROR, "\n";
16
18 "Log::Log4perl::Level" simply exports a predefined set of Log4perl log
19 levels into the caller's name space. It is used internally by
20 "Log::Log4perl". The following scalars are defined:
21
22 $OFF
23 $FATAL
24 $ERROR
25 $WARN
26 $INFO
27 $DEBUG
28 $TRACE
29 $ALL
30
31 "Log::Log4perl" also exports these constants into the caller's
32 namespace if you pull it in providing the ":levels" tag:
33
34 use Log::Log4perl qw(:levels);
35
36 This is the preferred way, there's usually no need to call
37 "Log::Log4perl::Level" explicitly.
38
39 The numerical values assigned to these constants are purely virtual,
40 only used by Log::Log4perl internally and can change at any time, so
41 please don't make any assumptions. You can test for numerical equality
42 by directly comparing two level values, that's ok:
43
44 if( get_logger()->level() == $DEBUG ) {
45 print "The logger's level is DEBUG\n";
46 }
47
48 But if you want to figure out which of two levels is more verbose, use
49 Log4perl's own comparator:
50
51 if( Log::Log4perl::Level::isGreaterOrEqual( $level1, $level2 ) ) {
52 print Log::Log4perl::Level::to_level( $level1 ),
53 " is equal or more verbose than ",
54 Log::Log4perl::Level::to_level( $level2 ), "\n";
55 }
56
57 If the caller wants to import level constants into a different
58 namespace, it can be provided with the "use" command:
59
60 use Log::Log4perl::Level qw(MyNameSpace);
61
62 After this $MyNameSpace::ERROR, $MyNameSpace::INFO etc. will be
63 defined accordingly.
64
65 Numeric levels and Strings
66 Level variables like $DEBUG or $WARN have numeric values that are
67 internal to Log4perl. Transform them to strings that can be used in a
68 Log4perl configuration file, use the c<to_level()> function provided by
69 Log::Log4perl::Level:
70
71 use Log::Log4perl qw(:easy);
72 use Log::Log4perl::Level;
73
74 # prints "DEBUG"
75 print Log::Log4perl::Level::to_level( $DEBUG ), "\n";
76
77 To perform the reverse transformation, which takes a string like
78 "DEBUG" and converts it into a constant like $DEBUG, use the
79 to_priority() function:
80
81 use Log::Log4perl qw(:easy);
82 use Log::Log4perl::Level;
83
84 my $numval = Log::Log4perl::Level::to_priority( "DEBUG" );
85
86 after which $numval could be used where a numerical value is required:
87
88 Log::Log4perl->easy_init( $numval );
89
91 Copyright 2002-2013 by Mike Schilli <m@perlmeister.com> and Kevin Goess
92 <cpan@goess.org>.
93
94 This library is free software; you can redistribute it and/or modify it
95 under the same terms as Perl itself.
96
98 Please contribute patches to the project on Github:
99
100 http://github.com/mschilli/log4perl
101
102 Send bug reports or requests for enhancements to the authors via our
103
104 MAILING LIST (questions, bug reports, suggestions/patches):
105 log4perl-devel@lists.sourceforge.net
106
107 Authors (please contact them via the list above, not directly): Mike
108 Schilli <m@perlmeister.com>, Kevin Goess <cpan@goess.org>
109
110 Contributors (in alphabetical order): Ateeq Altaf, Cory Bennett, Jens
111 Berthold, Jeremy Bopp, Hutton Davidson, Chris R. Donnelly, Matisse
112 Enzer, Hugh Esco, Anthony Foiani, James FitzGibbon, Carl Franks, Dennis
113 Gregorovic, Andy Grundman, Paul Harrington, Alexander Hartmaier David
114 Hull, Robert Jacobson, Jason Kohles, Jeff Macdonald, Markus Peter,
115 Brett Rann, Peter Rabbitson, Erik Selberg, Aaron Straup Cope, Lars
116 Thegler, David Viner, Mac Yang.
117
118
119
120perl v5.32.0 2020-09-07 Level(3)