Log::Me...:Simple(3)

πŸ’– Log::Message::Simple(3) β€” like, the manual page, but make it make sense πŸŽ€

okay so bestie, welcome to Log::Message::Simple, part of the User Contributed Perl Documentation crew ✨ this is the simplified interface to Log::Message, and honestly? it's giving "logging but make it cute". no cap.


🌸 NAME 🌸

Log::Message::Simple β€” a simplified interface to Log::Message. literally that's the whole vibe. πŸ’…


✨ SYNOPSIS ✨

here's the whole thing, copy-paste ready, i did not touch a single character:

    use Log::Message::Simple qw[msg error debug
                                carp croak cluck confess];

    use Log::Message::Simple qw[:STD :CARP];

    ### standard reporting functionality
    msg(    "Connecting to database",           $verbose );
    error(  "Database connection failed: $@",   $verbose );
    debug(  "Connection arguments were: $args", $debug );

    ### standard carp functionality
    carp(   "Wrong arguments passed: @_" );
    croak(  "Fatal: wrong arguments passed: @_" );
    cluck(  "Wrong arguments passed -- including stacktrace: @_" );
    confess("Fatal: wrong arguments passed -- including stacktrace: @_" );

    ### retrieve individual message
    my @stack = Log::Message::Simple->stack;
    my @stack = Log::Message::Simple->flush;

    ### retrieve the entire stack in printable form
    my $msgs  = Log::Message::Simple->stack_as_string;
    my $trace = Log::Message::Simple->stack_as_string(1);

    ### redirect output
    local $Log::Message::Simple::MSG_FH     = \*STDERR;
    local $Log::Message::Simple::ERROR_FH   = \*STDERR;
    local $Log::Message::Simple::DEBUG_FH   = \*STDERR;

    ### force a stacktrace on error
    local $Log::Message::Simple::STACKTRACE_ON_ERROR = 1

like, yes, that last line really is missing its semicolon in the original. i'm just the messenger 🫢


πŸ¦‹ DESCRIPTION πŸ¦‹

this module hands you standardized logging facilities, and it does it all by leaning on the "Log::Message" module underneath. one job, done well. iconic behavior, honestly πŸ‘‘


πŸ’œ FUNCTIONS πŸ’œ

okay so these are the little guys you call all day long:

  • msg("message string" [,VERBOSE]) β€” records a message on the stack, and prints it to "STDOUT" (or actually $MSG_FH, peek at the GLOBAL VARIABLES section below πŸ‘€) if the "VERBOSE" option is true. "VERBOSE" defaults to false. exported by default, or via the ":STD" tag.
  • debug("message string" [,VERBOSE]) β€” records a debug message on the stack, and prints it to "STDOUT" (or actually $DEBUG_FH, again, GLOBAL VARIABLES section below) if the "VERBOSE" option is true. "VERBOSE" defaults to false. exported by default, or via the ":STD" tag.
  • error("error string" [,VERBOSE]) β€” records an error on the stack, and prints it to "STDERR" (or actually $ERROR_FH, yep, GLOBAL VARIABLES sections below) if the "VERBOSE" option is true. and heads up: the "VERBOSE" option defaults to true here β€” not false like its siblings, she's different πŸ’… exported by default, or via the ":STD" tag.
  • carp(); β€” gives you functionality equal to Carp::carp() while still logging to the stack. best of both worlds fr fr. exported by using the ":CARP" tag.
  • croak(); β€” gives you functionality equal to Carp::croak() while still logging to the stack. exported by using the ":CARP" tag.
  • confess(); β€” gives you functionality equal to Carp::confess() while still logging to the stack. exported by using the ":CARP" tag.
  • cluck(); β€” gives you functionality equal to Carp::cluck() while still logging to the stack. exported by using the ":CARP" tag.
πŸ’€ quick vibe check: carp, croak, confess and cluck are all ":CARP" tag exclusives β€” they do not come in with the default export. don't come for me, it's in the source.

🌈 CLASS METHODS 🌈

these are the ones you call on the class itself, main character energy:

  • Log::Message::Simple->stack() β€” retrieves all the items on the stack. and because "Log::Message::Simple" is implemented using "Log::Message", you gotta consult its manpage for the function "retrieve" to see what actually comes back and how to use the items. iykyk 🧚
  • Log::Message::Simple->stack_as_string([TRACE]) β€” returns the whole stack as a printable string. if the "TRACE" option is true, all items come back with "Carp::longmess" output instead of just the message. "TRACE" defaults to false. so chill by default πŸ“
  • Log::Message::Simple->flush() β€” removes all the items from the stack and returns them. gone but not forgotten 😭 and again, since "Log::Message::Simple" is implemented using "Log::Message", consult its manpage for the function "retrieve" to see what gets returned and how to use the items.

πŸ’… GLOBAL VARIABLES πŸ’…

yes, they're package variables, yes, you can local them, yes, that's the whole trick:

πŸŽ€ $ERROR_FH

the filehandle that all the messages sent to error() get printed to. defaults to *STDERR. 🚨

πŸŽ€ $MSG_FH

the filehandle that all the messages sent to msg() get printed to. defaults to *STDOUT. 🌸

πŸŽ€ $DEBUG_FH

the filehandle that all the messages sent to debug() get printed to. defaults to *STDOUT. πŸ”

πŸŽ€ $STACKTRACE_ON_ERROR

if this option is set to "true", every single call to error() generates a stacktrace using Carp::shortmess(). defaults to "false". flip it and suddenly every error comes with receipts, periodt πŸ”₯


⭐ little reminder bestie: setting $STACKTRACE_ON_ERROR affects every error() call from then on β€” it's not a per-call thing. plan accordingly 🫢

and that's the whole page! πŸŒˆπŸ’–βœ¨

this masterpiece of documentation ships with perl v5.42.0 and is dated 2014-07-27 β€” yeah, she's been serving since 2014 and she still ate πŸ’…πŸŽ€ bye bestie, go log something πŸ¦‹

πŸ“¦ where this page comes from