We love logs because it helps us to debug during development. We also need a quick way to enable / disable logs because it’s not necessary for everybody :
- you maybe want logs during the development of your module
- people who will use it don’t necessary want to watch it
When testing a module and building a distribution, you maybe don’t want to inject dirt in your tests output. In the case of debuging, I think it’s a good thing to write it to a file and
tail on it.
We’re gonna use two CPAN’s modules, Log::Minimal, a minimal but custimizable logger and File::Stamped, that allows stamped log file. They are not supposed to be build together, but Tokuhiro Matsuno(
File::Stamped creator) recommend
Log::Minimal in a code example.
My aim was to create a log system for the debug moment, because I was boring of using
p() function from Data::Printer during my development and tests, because it was a bad thing: I was constantly adding and moving debug-print-code, that is a bad practice because it makes you repeat stupid tasks and encourage to test in a random way. I took a look at CPAN and Stack Overflow for some logging solutions, and Log::Log4Perl seems to be a recommended solution for most of serious apps. But it seems to much complicated to me, I don’t want to manage a new conf file, etc.
Log::Minimal seems to be really simple to use, I’ve installed it and was very satisfacted of it quickly. Now, we are going to see how to use it to create a temporary file that will contain the traces.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
/home/user/Documents/log.2013-09-24.out (adjust this to your own OS) from your terminal during your module tests…
… it will log the following :
1 2 3 4
That was a very minimal blog post, but I hope it could be usefull. Thanx to nmishin for cross-platforming advices !