Log::Co...rnLogger(3)
Okay bestie, welcome to the Log::Co...rnLogger(3) man page β yep, a User Contributed Perl Documentation page. It's all about Log::Contextual::WarnLogger, and the vibe is literally βlogger for libraries using Log::Contextual.β No cap. π
πΈ NAME πΈ
Log::Contextual::WarnLogger β a logger for libraries using Log::Contextual. That's the name, bestie, and I'm obsessed. π«Ά
π VERSION π
version 0.009001 β exact number, preserved with love. β¨
β¨ SYNOPSIS β¨
Okay so here's the setup, and yes, every character is staying:
package My::Package;
use Log::Contextual::WarnLogger;
use Log::Contextual qw( :log ),
-default_logger => Log::Contextual::WarnLogger->new({
env_prefix => 'MY_PACKAGE',
levels => [ qw(debug info notice warning error critical alert emergency) ],
});
# warns '[info] program started' if $ENV{MY_PACKAGE_TRACE} is set
log_info { 'program started' }; # no-op because info is not in levels
sub foo {
# warns '[debug] entered foo' if $ENV{MY_PACKAGE_DEBUG} is set
log_debug { 'entered foo' };
...
}
π DESCRIPTION π
This module is a simple logger made for libraries using Log::Contextual. We recommend the use of this logger as your default logger as it is simple and useful for most users, yet users can use set_logger in Log::Contextual to override your choice of logger in their own code thanks to the way Log::Contextual works. Slay. π
π οΈ METHODS π οΈ
Let's get into the methods, bestie. π«Ά
π new π
Arguments: Dict[ env_prefix => Str, levels => List ] $conf β yup, exactly that.
my $l = Log::Contextual::WarnLogger->new({ env_prefix => 'BAR' });
or:
my $l = Log::Contextual::WarnLogger->new({
env_prefix => 'BAR',
levels => [ 'level1', 'level2' ],
});
Creates a new logger object where env_prefix defines what the prefix is for the environment variables that will be checked for the log levels. Iconic. β¨
The log levels may be customized, but if not defined, these are used:
tracedebuginfowarnerrorfatal
For example, if env_prefix is set to FREWS_PACKAGE the following environment variables will be used:
FREWS_PACKAGE_UPTO
FREWS_PACKAGE_TRACE
FREWS_PACKAGE_DEBUG
FREWS_PACKAGE_INFO
FREWS_PACKAGE_WARN
FREWS_PACKAGE_ERROR
FREWS_PACKAGE_FATAL
Note that UPTO is a convenience variable. If you set FOO_UPTO=TRACE it will enable all log levels. Similarly, if you set it to FATAL only fatal will be enabled. Lowkey handy. π
π
$level π
Arguments: @anything β that's it.
All of the following six methods work the same. The basic pattern is:
sub $level {
my $self = shift;
warn "[$level] " . join qq{\n}, @_;
if $self->is_$level;
}
πΈ trace πΈ
$l->trace( 'entered method foo with args ' join q{,}, @args );
πΈ debug πΈ
$l->debug( 'entered method foo' );
πΈ info πΈ
$l->info( 'started process foo' );
πΈ warn πΈ
$l->warn( 'possible misconfiguration at line 10' );
πΈ error πΈ
$l->error( 'non-numeric user input!' );
πΈ fatal πΈ
$l->fatal( '1 is never equal to 0!' );
If different levels are specified, appropriate functions named for your custom levels work as you expect. Custom levels = custom functions, bestie. π
Note:fataldoes not calldiefor you, see"EXCEPTIONS AND ERROR HANDLING" in Log::Contextual.
π is_$level π
All of the following six functions just return true if their respective environment variable is enabled. Periodt. β¨
π is_trace π
say 'tracing' if $l->is_trace;
π is_debug π
say 'debuging' if $l->is_debug;
π is_info π
say q{info'ing} if $l->is_info;
π is_warn π
say 'warning' if $l->is_warn;
π is_error π
say 'erroring' if $l->is_error;
π is_fatal π
say q{fatal'ing} if $l->is_fatal;
If different levels are specified, appropriate is_$level functions work as you would expect. Slay. π
π BUGS π
Please report any bugs or feature requests on the bugtracker website https://github.com/haarg/Log-Contextual/issues β that's the exact URL, bestie. π«Ά
When submitting a bug or request, please include a test-file or a patch to an existing test-file that illustrates the bug or desired feature. That's the assignment. π
π AUTHOR π
Arthur Axel "fREW" Schmidt <frioux+cpan@gmail.com> β yes, that's the author and email. π
π COPYRIGHT AND LICENSE π
This software is copyright (c) 2024 by Arthur Axel "fREW" Schmidt. π
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. Periodt. β¨
Okay bestie, that's the whole Log::Co...rnLogger(3) page! Mwah π β source/version is perl v5.42.0, date is 2024-06-23, and the manual name is Log::Co...rnLogger(3) again because I'm extra. πππ¦
π¦ where this page comes from
- opensuse-leap 16.0: perl-Log-Contextual 0.009001-bp160.1.11 Β· Artistic-1.0 OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms