NAME

Treex::Core::Log - logger tailored for the needs of Treex

VERSION

version 2.20151210

SYNOPSIS

use Treex::Core::Log;

Treex::Core::Log::log_set_error_level('DEBUG');

sub epilog {
    print STDERR "I'm going to cease!";
}
Treex::Core::Log::add_hook('FATAL',&epilog());

sub test_value {
    my $value = shift;
    log_fatal "Negative values are unacceptable" if $ARGV < 0;
    log_warn "Zero value is suspicious" if $ARGV == 0;
    log_debug "test: value=$value";
}

DESCRIPTION

Treex::Core::Log is a logger developed with the Treex system. It uses more or less standard leveled set of reporting functions, printing the messages at STDERR.

Note that this module might be completely substituted by more elaborate solutions such as Log::Log4perl in the whole Treex in the future

Error levels

Specifying error level can be used for suppressing reports with lower severity. This module supports four ordered levels of report severity (plus a special value comprising them all).

FATAL
WARN
INFO - the default value
DEBUG
ALL

The current error level can be accessed by the following functions:

log_set_error_level($error_level)
get_error_level()

Basic reporting functions

All the following functions are exported by default.

log_fatal($message)

print the message, print the Perl stack too, and exit

log_warn($message)
log_info($message)
log_debug($message)

Other reporting functions

log_memory

print the consumed memory

progress

print another asterisk in a 'progress bar' composed of asterisks

Hooks

Another functions can be called prior to reporting events, by hooking a function on a certain error level event.

add_hook($level, &hook_subroutine)

add the subroutine to the list of subroutines called prior to reporting events with the given level

run_hooks($level)

run all subroutines for the given error level

AUTHOR

Zdeněk Žabokrtský <zabokrtsky@ufal.mff.cuni.cz>

COPYRIGHT AND LICENSE

Copyright © 2011 by Institute of Formal and Applied Linguistics, Charles University in Prague

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