Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Dear All,

I am being used Log::Agent module. Now I want to differentiate the logs based on some unique id. It can be done by using Log::Agent::Tag module. Can you any one help me to give the usage of this module with an example?

-tags is the argument of logconfig() call in Log::Agent module

Replies are listed 'Best First'.
Re: Help in Log::Agent module
by moritz (Cardinal) on Jul 27, 2010 at 09:50 UTC
    Most modules on CPAN come with a test suite, which contain runnable code that exercises most features.

    That's also true for Log::Agent, which has the tag_string.t test file.

    I hope this make things a bit easier for you.

Re: Help in Log::Agent module
by Khen1950fx (Canon) on Jul 27, 2010 at 10:33 UTC
    I followed moritz's advice and used tag_string.t. The documentation for Log::Agent::Tag is extremely dry and probably confusing for you. I hope this helps.
    #!/usr/bin/perl use strict; use warnings; use Log::Agent; require Log::Agent::Driver::File; require Log::Agent::Tag::String; require qw(/path/to/my_code.pl); # the script to run my $err = '/path/to/file.err'; my $out = '/path/to/file.out'; my $driver = Log::Agent::Driver::File->make( -prefix => 'me', -channels => { 'error' => $err, 'output' => $out }, ); my $t1 = Log::Agent::Tag::String->make(-value => "<tag #1>"); my $t2 = Log::Agent::Tag::String->make(-value => "<tag #2>", -postfix +=> 1); logconfig( -driver => $driver, -tags => [$t1], ); logerr "error string"; use Log::Agent qw(logtags); my $tags = logtags; $tags->append($t2); logwarn "warn string";