NAME

Gears::Logger - Abstract logging interface

SYNOPSIS

package My::Gears::Logger;

use v5.40;
use Mooish::Base -standard;

extends 'Gears::Logger';

sub _log_message ($self, $level, $message)
{
	say STDERR $message;
}

# In your code
use My::Gears::Logger;

my $logger = My::Gears::Logger->new;
$logger->message(error => 'Something went wrong');
$logger->message(info => 'All is well');

DESCRIPTION

Gears::Logger is an abstract base class for logging functionality. It provides message formatting capabilities but leaves the actual logging implementation to subclasses. This allows different logging backends (files, STDERR, syslog, etc.) to be used with a consistent interface.

The logger formats messages with a timestamp and log level, and can handle both scalar and reference values using Data::Dumper for complex data structures.

EXTENDING

This logger is abstract by design. A subclass must be created that implements the _log_message method to define where and how log messages are written.

Here is how a minimal working logger subclass could be implemented:

package My::Gears::Logger;

use v5.40;
use Mooish::Base -standard;

extends 'Gears::Logger';

sub _log_message ($self, $level, $message)
{
	# Write to STDERR
	say STDERR $message;
}

INTERFACE

Attributes

date_format

A string specifying the date format for log timestamps. Uses Time::Piece strftime format. Defaults to '%a %b %d %T %Y' (Apache log format).

Available in constructor

log_format

A string specifying the overall log message format. Uses sprintf format with three placeholders: timestamp, log level, and message. Defaults to '[%s] [%s] %s'.

Available in constructor

Methods

new

$object = $class->new(%args)

A standard Mooish constructor. Consult "Attributes" section to learn what keys can be passed in %args.

message

$logger = $logger->message($level, @messages)

Logs one or more messages at the specified level. The $level is a string (typically 'error', 'warn', 'info', 'debug', etc.) and @messages can be scalar strings or references. References will be formatted using Data::Dumper.

Returns the logger object for method chaining.