NAME

Venus::Log - Log Class

ABSTRACT

Log Class for Perl 5

SYNOPSIS

package main;

use Venus::Log;

my $log = Venus::Log->new;

# $log->trace(time, 'Something failed!');

# "0000000000 Something failed!"

# $log->error(time, 'Something failed!');

# "0000000000 Something failed!"

DESCRIPTION

This package provides methods for logging information using various log levels. The default log level is trace. Acceptable log levels are trace, debug, info, warn, error, and fatal, and the set log level will handle events for its level and any preceding levels in the order specified.

ATTRIBUTES

This package has the following attributes:

handler

handler(coderef $code) (coderef)

The handler attribute holds the callback that handles logging. The handler is passed the log level and the log messages.

Since 1.68

handler example 1
# given: synopsis

package main;

my $handler = $log->handler;

my $events = [];

$handler = $log->handler(sub{shift; push @$events, [@_]});

level

level(string $name) (string)

The level attribute holds the current log level. Valid log levels are trace, debug, info, warn, error and fatal, and will emit log messages in that order. Invalid log levels effectively disable logging.

Since 1.68

level example 1
# given: synopsis

package main;

my $level = $log->level;

# "trace"

$level = $log->level('fatal');

# "fatal"

separator

separator(any $data) (any)

The separator attribute holds the value used to join multiple log message arguments.

Since 1.68

separator example 1
# given: synopsis

package main;

my $separator = $log->separator;

# ""

$separator = $log->separator("\n");

# "\n"

INHERITS

This package inherits behaviors from:

Venus::Kind::Utility

INTEGRATES

This package integrates behaviors from:

Venus::Role::Buildable

METHODS

This package provides the following methods:

debug

debug(string @data) (Venus::Log)

The debug method logs debug information and returns the invocant.

Since 1.68

debug example 1
# given: synopsis

package main;

# $log = $log->debug(time, 'Something failed!');

# "0000000000 Something failed!"
debug example 2
# given: synopsis

package main;

# $log->level('info');

# $log = $log->debug(time, 'Something failed!');

# noop

error

error(string @data) (Venus::Log)

The error method logs error information and returns the invocant.

Since 1.68

error example 1
# given: synopsis

package main;

# $log = $log->error(time, 'Something failed!');

# "0000000000 Something failed!"
error example 2
# given: synopsis

package main;

# $log->level('fatal');

# $log = $log->error(time, 'Something failed!');

# noop

fatal

fatal(string @data) (Venus::Log)

The fatal method logs fatal information and returns the invocant.

Since 1.68

fatal example 1
# given: synopsis

package main;

# $log = $log->fatal(time, 'Something failed!');

# "0000000000 Something failed!"
fatal example 2
# given: synopsis

package main;

# $log->level('unknown');

# $log = $log->fatal(time, 'Something failed!');

# noop

info

info(string @data) (Venus::Log)

The info method logs info information and returns the invocant.

Since 1.68

info example 1
# given: synopsis

package main;

# $log = $log->info(time, 'Something failed!');

# "0000000000 Something failed!"
info example 2
# given: synopsis

package main;

# $log->level('warn');

# $log = $log->info(time, 'Something failed!');

# noop

input

input(string @data) (string)

The input method returns the arguments provided to the log level methods, to the "output", and can be overridden by subclasses.

Since 1.68

input example 1
# given: synopsis

package main;

my @input = $log->input(1, 'Something failed!');

# (1, 'Something failed!')

output

output(string @data) (string)

The output method returns the arguments returned by the "input" method, to the log handler, and can be overridden by subclasses.

Since 1.68

output example 1
# given: synopsis

package main;

my $output = $log->output(time, 'Something failed!');

# "0000000000 Something failed!"

string

string(any $data) (string)

The string method returns a stringified representation of any argument provided and is used by the "output" method.

Since 1.68

string example 1
# given: synopsis

package main;

my $string = $log->string;

# ""
string example 2
# given: synopsis

package main;

my $string = $log->string('Something failed!');

# "Something failed!"
string example 3
# given: synopsis

package main;

my $string = $log->string([1,2,3]);

# [1,2,3]
string example 4
# given: synopsis

package main;

my $string = $log->string(bless({}));

# "bless({}, 'main')"

trace

trace(string @data) (Venus::Log)

The trace method logs trace information and returns the invocant.

Since 1.68

trace example 1
# given: synopsis

package main;

# $log = $log->trace(time, 'Something failed!');

# "0000000000 Something failed!"
trace example 2
# given: synopsis

package main;

# $log->level('debug');

# $log = $log->trace(time, 'Something failed!');

# noop

warn

warn(string @data) (Venus::Log)

The warn method logs warn information and returns the invocant.

Since 1.68

warn example 1
# given: synopsis

package main;

# $log = $log->warn(time, 'Something failed!');

# "0000000000 Something failed!"
warn example 2
# given: synopsis

package main;

# $log->level('error');

# $log = $log->warn(time, 'Something failed!');

# noop

write

write(string $level, any @data) (Venus::Log)

The write method invokes the log handler, i.e. "handler", and returns the invocant.

Since 1.68

write example 1
# given: synopsis

package main;

# $log = $log->write('info', time, 'Something failed!');

# bless(..., "Venus::Log")

AUTHORS

Awncorp, awncorp@cpan.org

LICENSE

Copyright (C) 2022, Awncorp, awncorp@cpan.org.

This program is free software, you can redistribute it and/or modify it under the terms of the Apache license version 2.0.