http://www.perlmonks.org?node_id=1108270

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

I have a bunch of utility scripts I'd like to test in part by scraping their log output. The scripts use Log::Dispatch with the default screen output and a file output for logging. Presently, the tests use Test::Trap to check log output on STDOUT.

This approach works well when proving tests directly from the command line. However, we run automated tests nightly via cron and under these conditions either Dispatch::Log doesn't write log entries (likely because STDOUT goes nowhere) or Test::Trap doesn't get them. I see the same results when running the tests with nohup prove ... --html

I'd rather not completely change the test approach (to reading the file, for example, instead of using Test::Trap) just because the logging tests fail under cron. On the other hand, we rely on the nightly test output to alert us to trouble and don't want a bunch of "known" failing results.

Supposing I can detect when running under cron (probably with ENV injection in the cron script that launches the tests--I've found checking PS1 is not sufficient to know) is there some UNIX or Perl hack I can use to persuade Log::Dispatch to log such that Test::Trap gets the lines?