Log::Co...eLogger(3)

okay so bestie, welcome to the Log::Contextual::TeeLogger(3) page β€” and yes, it’s from the User Contributed Perl Documentation, with the manual name folded in right here at the top instead of that whole truncated header line. The vibes? Immaculate. The logger? A little demo-y. Let’s get into it. 🫢

🌸 NAME 🌸

Log::Contextual::TeeLogger β€” output to more than one logger. That’s the whole name, and honestly? Iconic. πŸ’…

✨ VERSION ✨

version 0.009001 β€” noted, filed, and slaying. πŸŽ€

🧚 SYNOPSIS 🧚

Here’s the code, bestie β€” exactly as written, no cap:

use Log::Contextual::SimpleLogger;
use Log::Contextual::TeeLogger;
use Log::Contextual qw( :log ),
  -logger => Log::Contextual::TeeLogger->new({ loggers => [
    Log::Contextual::SimpleLogger->new({ levels => [ 'debug' ] }),
    Log::Contextual::SimpleLogger->new({
      levels => [ 'info' ],
      coderef => sub { print @_ },
    }),
  ]});

## docs below here not yet edited

log_info { 'program started' }; # no-op because info is not in levels
sub foo {
  log_debug { 'entered foo' };
  ...
}

Not me keeping the ## docs below here not yet edited comment and the # no-op because info is not in levels note exactly as they are β€” because that’s what the page says, bestie. πŸ™ˆ

πŸ’– DESCRIPTION πŸ’–

okay so real talk: this module is a simple logger made mostly for demonstration and initial experimentation with Log::Contextual. That’s the vibe. We literally recommend you use a real logger instead. 😭

If you want something more serious but not overly complicated, go take a look at Log::Dispatchouli. She’s right there. 🫢

πŸ› οΈ METHODS πŸ› οΈ

Let’s go method by method, bestie. No skipping. πŸ’…

πŸ†• new

Arguments: Dict[ levels => ArrayRef[Str], coderef => Optional[CodeRef] ] $conf

my $l = Log::Contextual::SimpleLogger->new({
  levels => [qw( info warn )],
  coderef => sub { print @_ }, # the default prints to STDERR
});

This makes a brand-new SimpleLogger object with the levels you passed in enabled. Optionally, you can pass a CodeRef to modify how the logs get output or stored β€” cute little customization moment. ✨

Levels may contain:

  • trace
  • debug
  • info
  • warn
  • error
  • fatal

🎚️ $level

Arguments: @anything

All of the following six methods work the same. The basic pattern is:

sub $level {
  my $self = shift;

  print STDERR "[$level] " . join qq{\n}, @_;
      if $self->is_$level;
}

trace

The call looks like:

$l->trace( 'entered method foo with args ' join q{,}, @args );

debug

The call looks like:

$l->debug( 'entered method foo' );

info

The call looks like:

$l->info( 'started process foo' );

warn

The call looks like:

$l->warn( 'possible misconfiguration at line 10' );

error

The call looks like:

$l->error( 'non-numeric user input!' );

fatal

The call looks like:

$l->fatal( '1 is never equal to 0!' );
Note: fatal does not call die for you β€” see "EXCEPTIONS AND ERROR HANDLING" in Log::Contextual β€” yes, that’s the note, don’t shoot the messenger. πŸ’€

βœ… is_$level

These six little check-in functions just return true if their respective level is enabled. Simple. Clean. Vibe check passed. βœ…

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;

πŸ› BUGS πŸ›

Found a bug? Want a feature? Please report it on the bugtracker website: https://github.com/haarg/Log-Contextual/issues β€” she’s waiting. πŸ›πŸ«Ά

When you submit 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 whole ask. No vibes-only reports, bestie. πŸ’…

πŸ‘‘ AUTHOR πŸ‘‘

Arthur Axel "fREW" Schmidt <frioux+cpan@gmail.com> β€” the author, the icon, the legend. πŸ‘‘

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 page. The footer says perl v5.42.0, dated 2024-06-23, and the manual name is Log::Co...eLogger(3) β€” so now you know the source/version and date too. Go log something, and remember: output to more than one logger is a lifestyle. πŸ’…βœ¨

πŸ“¦ where this page comes from