Object:...::Logger(3)

πŸ’… Object::Remote::Logging::Logger β€” the glow-up page

okay so real talk, bestie: this is a page from the User Contributed Perl Documentation set, and it's all about Object::Remote::Logging::Logger β€” the class that formats your log messages and yeets them out to the world. Let's get into it ✨


πŸŽ€ NAME

Object::Remote::Logging::Logger β€” literally formats a log message and outputs it. That's the whole job. Iconic behavior honestly.


✨ SYNOPSIS

okay so here's the vibe in code form, copying exactly so you don't have to squint:

use Object::Remote::Logging::Logger;
use Object::Remote::Logging qw( router arg_levels );

my $app_output = Object::Remote::Logging::Logger->new(
  level_names => arg_levels, format => '%t %s',
  min_level => 'verbose', max_level => 'info',
);

#Selector method can return 0 or more logger
#objects that will receive the messages
my $selector = sub {
  my ($generating_package, $metadata) = @_;
  return unless $metadata->{exporter} eq 'App::Logging::Subclass';
  return $app_output;
};

#true value as second argument causes the selector
#to be stored with a weak reference
router->connect($selector, 1);

#disconnect the selector from the router
undef($selector);

#router will hold this logger forever
#and send it all log messages
router->connect(Object::Remote::Logging::Logger->new(
  level_names => arg_levels, format => '%s at %f line %i, log level: %l'
  min_level => 'warn', max_level => 'error',
));

like… it's giving "here's every way you could ever wire a logger up" and honestly? we love that for us 🫢


πŸ’– DESCRIPTION

so this class is basically the main character of the logging pipeline: it receives log messages from an instance of Object::Remote::Logging::Router, formats them according to its configuration, and then outputs them straight to STDERR. πŸ“€

and the little matchmaker sitting between the router and the logger? that's a selector method β€” it peeks at the log message metadata and returns 0 or more loggers that should receive that message. no cap, zero is a totally valid answer. πŸ’…


🌸 USAGE

A logger object receives the log messages that get generated, converts them into formatted log entries, and then shows them to the end user. every logger has its own set of active log levels, and it will only output a log entry if the message lands on one of those active levels. picky? yes. correct? also yes. ✨

now, to actually get access to the stream of log messages, you make a connection to the log router. and you've got two flavors, bestie:

  • A logger can connect directly to the router and receive an unfiltered stream of log messages.
  • Or you can use a selector closure instead. πŸ¦‹

the selector gets executed for each log message along with the message metadata, and it returns a list of 0 or more loggers that should receive that message. when the selector runs:

  1. the first argument is the name of the package that generated the log message
  2. the second argument is a hash reference containing the message metadata

that's it, that's the contract. iykyk 😌


πŸ¦‹ METADATA

the message metadata is a hash reference, and here are its keys β€” every single one, no skipping πŸ‘‘

  • message_level β€” name of the log level of the message.
  • exporter β€” package name of the logging API that was used to generate the log message.
  • caller_package β€” name of the package that generated the log message.
  • method β€” name of the method the message was generated inside of.
  • timestamp β€” Unix time of the message generation.
  • pid β€” process id of the Perl interpreter the message was generated in.
  • hostname β€” hostname of the system where the message was generated.
  • filename β€” name of the file the message was generated in.
  • line β€” line of the source file the message was generated at.
  • object_remote β€” a reference to another hash holding the Object::Remote specific info. its keys are:
    • connection_id β€” if the log message was generated on a remote Perl interpreter, then the Object::Remote::Connection id of that interpreter will be available right here. 🌈

πŸ‘‘ ATTRIBUTES

okay bestie, here's where the configuration lives. read carefully, some of these have no default and that's not a drill πŸ’€

πŸ’œ level_names

This is a required attribute. It must be an array ref with the list of log level names in it. the list must be ordered with the lowest level as element 0 and the highest level as the last element. there is no default value. fr fr, you have to pass it. πŸ™ˆ

πŸ’œ min_level

The lowest log level that will be output by the logger. there is no default value.

πŸ’œ max_level

The highest log level that will be output by the logger. the default value is the highest level present in level_names. so like, it just figures it out for you. slay.

πŸ’œ format

The printf style format string used when rendering the log message. The following sequences are significant:

  • %l β€” level name that the log message was generated at.
  • %s β€” log message rendered into a string with a leading space before any additional lines in a multiple line message.
  • %t β€” time the log message was generated rendered into a string. ⏰ the time value is taken from the Perl interpreter that generated the log message; it is not the time that the logger received the log message on the local interpreter if the log message was forwarded. important distinction, don't @ me.
  • %r β€” Object::Remote connection information rendered into a string.
  • %c β€” package name of the logging API that was used to generate the log message.
  • %p β€” name of the package that generated the log message.
  • %m β€” method name that generated the log message.
  • %f β€” filename that the log message was generated in.
  • %i β€” line number the log message was generated at.
  • %h β€” hostname the log message was generated on.
  • %P β€” process id of the Perl interpreter that generated the log message. (yes, capital P β€” lowercase p is the package, don't mix 'em up πŸ’…)
  • %% β€” a literal %.
  • %n β€” a newline.
lowkey watch out for %P vs %p and %t vs everything else β€” the format string is doing a lot of heavy lifting here 🫢

and that's the whole page, bestie. go forth and log with main character energy. πŸ§šβ€β™€οΈπŸ’–


sign-off szn πŸŽ€ β€” this page is from perl v5.40.2, dated 2026-07-16, and it's all Object:...::Logger(3) business. catch you in the next manpage, mwah πŸ’‹

πŸ“¦ where this page comes from