NAME

Thunderhorse::Module::Logger - Logger module for Thunderhorse

SYNOPSIS

# in application build method
$self->load_module('Logger' => {
	outputs => [
		screen => {
			'utf-8' => true,
		},
	],
});

# in controller method
sub some_action ($self, $ctx)
{
	$self->log(info => 'Processing request');
	$self->log(error => 'Something went wrong');

	return "Done";
}

DESCRIPTION

The Logger module adds logging capabilities to the application. It wraps the entire application to catch and log errors, and adds a log method to controllers.

CONFIGURATION

Configuration is passed to Gears::Logger::Handler, which handles the actual logging using Log::Handler. Common configuration keys:

  • outputs - hash of Log::Handler output destinations (file, screen, etc.)

  • date_format - strftime date format in logs, mimicing apache format by default

  • log_format - sprintf log format, mimicing apache format by default

The default log_format is [%s] [%s] %s, where placeholders are: date, level and message. Log format can be specified on Log::Handler level in outputs (per output), but it would cause duplication of formatting. In that case log_format must be set to undef to avoid an exception on startup.

ADDED INTERFACE

Controller Methods

log

$self->log(info => 'Processing request');
$self->log(error => 'Something went wrong');

Logs a message at the specified level. Returns the controller instance for method chaining. Accepts the same arguments as Gears::Logger::Handler's message method.

Hooks

error

Automatically logs any unhandled exceptions that occur during request processing at the error level.

SEE ALSO

Thunderhorse::Module, Gears::Logger