Syntactic Confectionery Delight | |
PerlMonks |
Re: How to log to different outputs from different packagesby 1nickt (Canon) |
on Nov 19, 2017 at 14:33 UTC ( [id://1203781]=note: print w/replies, xml ) | Need Help?? |
Hi, you should use tools built for the purpose, for example Log::Any to produce log output, and a Log::Any::Adapter to consume (and display, or not) the log output. Then you can can control the output of your debugging as well as the levels at which information is displayed/saved or whatever. In the example below I am using Log::Dispatch as an adapter to process the log output, since you indicated that you want output from different packages handled differently. You can use a simple adapter if all your log output should go to one place. I generally use Log::Dispatch by default, as logging needs typically grow over time. MyFirst.pm : MySecond.pm : 1203778.pl (or another package, whatever...) : Output: Log file:
You can easily create your own Log::Any::Adapter class, which you will need to do if you want timestamp, caller info, etc. ( For a simpler scenario, just import $log from Log::Any into your package and use use Log::Any::Adapter qw/ Stderr /; in your script, and you are done. ) Hope this helps!
The way forward always starts with a minimal test.
In Section
Seekers of Perl Wisdom
|
|