AnyEvent-Multilog

 view release on metacpan or  search on metacpan

lib/AnyEvent/Multilog.pm  view on Meta::CPAN


sub handle_completion {
    my ($self, $done) = @_;
    my ($success, $msg);

    $self->set_leftover_data( $done->delegate('input_handle')->wbuf )
        if $done->delegate('input_handle')->has_wbuf;

    if($done->exit_value == 111){
        $success = 0;
        $msg = 'out of memory, or another multilog '.
            'process is touching your files';
    }

    elsif($done->exit_value == 0 && $self->has_leftover_data ){
        $success = 1;
        $msg = 'normal exit, with leftover data';
    }

    elsif($done->is_success){
        $success = 1;
        $msg = 'normal exit';
    }

    else {
        $success = 0;
        $msg = 'abnormal exit with signal '. $done->exit_signal;
    }

    $self->on_exit->($success, $msg, $done) if $self->has_exit_handler;
    return;
}

sub start {
    my $self = shift;
    confess 'already started' if $self->has_run;
    return $self->run;
}

sub push_write {
    my ($self, $line) = @_;
    $self->ensure_validity;
    $line .= "\n" if $line !~ /(?:\r\n|\r|\n)$/;
    $self->run->delegate('input_handle')->handle->push_write($line);
}

sub push_shutdown {
    my $self = shift;
    $self->run->kill('TERM');
}

sub rotate {
    my $self = shift;
    $self->run->kill('ALRM');
}

sub shutdown {
    my $self = shift;
    my $input = $self->run->delegate('input_handle');
    confess 'already shutdown, cannot perform further operations' if $self->is_shutdown;
    $input->handle->do_not_want;
}

__PACKAGE__->meta->make_immutable;

1;



=pod

=head1 NAME

AnyEvent::Multilog - event-driven interface to a multilog process

=head1 VERSION

version 1.102861

=head1 SYNOPSIS

    my $log = AnyEvent::Multilog->new(
        script => [qw{t +* ./log}],
    );

    $log->start;
    $log->push_write('log message');
    $log->push_write('another log message');
    $log->rotate;
    $log->push_write('another log message in a new log file');
    $log->shutdown;

=head1 DESCRIPTION

This module makes it easy to log via a multilog process.  It handles
spawning the multilog process and handling its errors.

=head1 ATTRIBUTES

=head2 script

Required.

This is an ArrayRef representing the multilog script that describes
how to log.  See the L<multilog|multilog man page> for more
information on what this script is and how to write one.

Note that the shell is never invoked, so you don't need to escape
anything from the shell.

To select all lines, add a tai64n timestamp, and log to a directory
called "log", your script should be C<['t', '+*', './log']>.

=head2 multilog

Optional.

The path to the multilog binary.  By default, checks C<$PATH> and uses
the one in there.

=head2 on_exit



( run in 0.850 second using v1.01-cache-2.11-cpan-39bf76dae61 )