NAME

Medusa::XS::Logger - XS-accelerated file logger with flock locking

VERSION

Part of Medusa::XS version 0.01.

SYNOPSIS

use Medusa::XS::Logger;

my $logger = Medusa::XS::Logger->new(file => '/var/log/audit.log');

$logger->debug("Starting process");
$logger->info("User logged in: user123");
$logger->error("Failed to connect to database");

# Or use the generic log method:
$logger->log("any message");

DESCRIPTION

Medusa::XS::Logger is a pure-C file logger used as the default logging backend for Medusa::XS. All I/O is performed in C via PerlIO with flock(2)-based locking, making it safe for concurrent writes from multiple processes.

The logger is automatically instantiated by Medusa::XS when the first :Audit-wrapped subroutine is called, using the LOG_FILE value from %Medusa::XS::LOG. You can also create instances directly.

When Medusa::XS detects that the configured logger is a Medusa::XS::Logger instance, it bypasses Perl method dispatch entirely and writes directly from C — eliminating all call overhead on the logging path.

CONSTRUCTOR

new

my $logger = Medusa::XS::Logger->new();
my $logger = Medusa::XS::Logger->new(file => 'audit.log');
my $logger = Medusa::XS::Logger->new({ file => 'audit.log' });

Creates a new logger and opens the file for appending. Accepts arguments as a hash, a list of key-value pairs, or a hash reference.

file (string, default "audit.log")

Path to the log file. The file is opened in append mode (>>) and created if it does not exist.

Dies if the file cannot be opened.

METHODS

All write methods acquire an exclusive flock before writing, flush the handle, and release the lock — ensuring atomic line writes even under concurrent access.

debug

$logger->debug("message text");

Writes a line to the log file.

info

$logger->info("message text");

Writes a line to the log file.

error

$logger->error("message text");

Writes a line to the log file.

log

$logger->log("message text");

Generic write — identical behaviour to debug, info, and error. The level-named methods exist for API compatibility with higher-level loggers; Medusa::XS::Logger does not filter by level.

DESTRUCTION

The file handle is closed automatically when the logger object goes out of scope. Cleanup is handled by a C-level magic destructor attached to the underlying SV.

SEE ALSO

Medusa::XS — the audit framework that uses this logger.

LICENSE

This module is free software; you may redistribute and/or modify it under the same terms as Perl itself.