NAME
Chandra::Log - Structured logging framework for Chandra applications
SYNOPSIS
use Chandra::Log;
my $log = Chandra::Log->new(
level => 'debug',
output => 'stderr',
);
$log->debug('Variable dump', { x => 42 });
$log->info('Application started');
$log->warn('Deprecated method called');
$log->error('Connection failed', { host => 'db.local' });
$log->fatal('Unrecoverable error');
# Level filtering
$log->set_level('warn'); # Only warn, error, fatal shown
# Contextual logger
my $req_log = $log->with(request_id => 'abc-123');
$req_log->info('Processing');
# JSON formatter
$log->formatter('json');
# File output with rotation
my $log = Chandra::Log->new(
level => 'info',
output => { file => '/var/log/app.log' },
rotate => { max_size => '10M', keep => 5 },
);
# Multiple outputs
my $log = Chandra::Log->new(
output => [
'stderr',
{ file => 'app.log', level => 'info' },
{ callback => sub { my ($entry) = @_; ... } },
],
);
DESCRIPTION
Chandra::Log provides structured, multi-output logging with level filtering, formatters, contextual loggers, file rotation, and DevTools console integration.
METHODS
new(%args)
Create a new logger. Options: level, output, formatter, rotate.
debug($msg, \%data), info, warn, error, fatal
Log at the given level with optional structured data.
level($new_level)
Get or set the current log level.
set_level($level)
Set the log level (alias for level($level)).
formatter($fmt)
Set formatter: 'text', 'json', 'minimal', or a code ref.
with(%context)
Return a child logger with additional context fields.