NAME

App::CLI::Plugin::Log::Message - for App::CLI::Extension logging module

VERSION

0.2

SYNOPSIS

# MyApp.pm
package MyApp;

use strict;
use base qw(App::CLI::Extension);

# extension method
__PACKAGE__->load_plugins(qw(Log::Message));

__PACKAGE__->config(log_message => { private => 1, level => "log", tag => "myapp" });

1;

# MyApp/Hello.pm
package MyApp::Hello;
use strict;
use feature ":5.10.0";
use base qw(App::CLI::Command);

sub run {

    my($self, @args) = @_;
    $self->log->store("myapp execute start");
    $self->log->store("myapp execute end");
    foreach my $stack($self->log->retrieve) {
        say sprintf("%s ID[%05i]: %s", $stack->when, $stack->id, $stack->message);
    }
}

# myapp
#!/usr/bin/perl

use strict;
use MyApp;

MyApp->dispatch;

# execute
[kurt@localhost ~] ./myapp hello
Sun Sep  6 20:43:39 2009 ID[00000]: myapp execute start
Sun Sep  6 20:43:39 2009 ID[00001]: myapp execute end

DESCRIPTION

App::CLI::Extension Log::Message plugin module

log method setting

__PACKAGE__->config( log_message => {%log_message_option} );

EXTENDED METHOD

Log::Message::stringfy_stack

Log::Message stack object to converts a string

Example:

# MyApp::Hello(App::CLI::Command base package)
sub run {

    my($self, @args) = @_;
    $self->log->store("myapp execute start");
    $self->log->store("myapp execute end");
    say $self->log->stringfy_stack;
    # for option(same Log::Message#retrieve option)
    #say $self->log->stringfy_stack(level => "log", tag => qr/myapp/);
}

# execute
[kurt@localhost ~] ./myapp hello
Sun Sep  6 20:57:10 2009 ID:00000000 myapp[2027]: myapp execute start(at /usr/local/lib/perl5/5.10.0/Log/Message.pm line 410
        Log::Message::store('Log::Message=HASH(0x96855f0)', 'myapp execute start') called at /home/kurt/lib/MyApp/Log.pm line 13
        MyApp::Log::run('MyApp::Log=HASH(0x9607790)') called at /usr/local/lib/perl5/site_perl/5.10.0/App/CLI/Command.pm line 53
        App::CLI::Command::run_command('MyApp::Log=HASH(0x9607790)') called at /usr/local/lib/perl5/site_perl/5.10.0/App/CLI.pm line 79
        App::CLI::dispatch('MyApp') called at ./myapp.pl line 8)
Sun Sep  6 20:57:10 2009 ID:00000001 myapp[2027]: myapp execute end(at /usr/local/lib/perl5/5.10.0/Log/Message.pm line 410
        Log::Message::store('Log::Message=HASH(0x96855f0)', 'myapp execute end') called at /home/kurt/lib/MyApp/Log.pm line 14
        MyApp::Log::run('MyApp::Log=HASH(0x9607790)') called at /usr/local/lib/perl5/site_perl/5.10.0/App/CLI/Command.pm line 53
        App::CLI::Command::run_command('MyApp::Log=HASH(0x9607790)') called at /usr/local/lib/perl5/site_perl/5.10.0/App/CLI.pm line 79
        App::CLI::dispatch('MyApp') called at ./myapp.pl line 8)

Log::Message::Handlers::stderr

Log::Message::Handlers custom message handler

Example:

# MyApp::Hello(App::CLI::Command base package)
sub run {

    my($self, @args) = @_;
    $self->log->store(level => "stderr", message => "myapp execute start");
    $self->log->store(level => "stderr", message => "myapp execute end");
}

METHOD

log

return Log::Message object

SEE ALSO

App::CLI::Extension Log::Message

AUTHOR

Akira Horimoto

COPYRIGHT AND LICENSE

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

Copyright (C) 2009 Akira Horimoto