NAME

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

VERSION

0.4

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(level => "warn", message => "warning message");
     $self->log->store(level => "cluck", message => "cluck message");
     $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");
 }
 
 # execute
 [kurt@localhost ~] ./myapp hello 2>/dev/null
 Sat Sep 19 00:20:02 2009 log      ID:00000000 NONE[3963]: myapp execute start
 Sat Sep 19 00:20:02 2009 log      ID:00000003 NONE[3963]: myapp execute end

 # stringfy_stack verbose option
 sub options {
     return (
        "verbose|v"   => "verbose",
     );
 }
 
 sub run {

     my($self, @args) = @_;
     $self->log->store("myapp execute start");
     $self->log->store(level => "warn", message => "warning message");
     $self->log->store(level => "cluck", message => "cluck message");
     $self->log->store("myapp execute end");
     say $self->log->stringfy_stack(level => "log", verbose => $self->{verbose});
 }
 
 # verbose execute
 [kurt@localhost ~] ./myapp hello --verbose 2>/dev/null
  Sat Sep 19 00:23:07 2009 log      ID:00000000 NONE[3968]: at /usr/local/lib/perl5/5.10.0/Log/Message.pm line 410
          Log::Message::store('Log::Message=HASH(0x9b468f0)', 'myapp execute start') called at /home/holly/lib/MyApp/Log.pm line 19
          MyApp::Log::run('MyApp::Log=HASH(0x9bb2498)') called at /home/kurt/App/CLI/Plugin/InstallCallback.pm line 183
          App::CLI::Plugin::InstallCallback::_run_command('MyApp::Log=HASH(0x9bb2498)') 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
  Sat Sep 19 00:23:07 2009 log      ID:00000003 NONE[3968]: at /usr/local/lib/perl5/5.10.0/Log/Message.pm line 410
          Log::Message::store('Log::Message=HASH(0x9b468f0)', 'myapp execute end') called at /home/holly/lib/MyApp/Log.pm line 22
          MyApp::Log::run('MyApp::Log=HASH(0x9bb2498)') called at /home/kurt/App/CLI/Plugin/InstallCallback.pm line 183
          App::CLI::Plugin::InstallCallback::_run_command('MyApp::Log=HASH(0x9bb2498)') 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 Class::Data::Accessor 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