6 use POSIX
qw(strftime);
12 Thrasher::Log - contains logging functions that control log output
16 use Thrasher::Log qw(log);
17 log("Error in sample code for POD documentation for Thrasher::Log.");
21 Obviously, this is the logging function.
23 This was pulled out into a separate function due to load order issues;
24 it turns out this really needs to be in a separate module.
30 # Ugly, but we need to consolidate the two debugging modules...
31 our @EXPORT_OK = qw(log logger debug dies);
32 our %EXPORT_TAGS = (all
=> \
@EXPORT_OK);
35 our $SILENT = 0; # Really only useful for testing this module
38 binmode STDERR
, ':utf8';
44 my ($package, $filename, $line);
46 ($package, $filename, $line) = caller;
48 ($package, $filename, $line) = caller $depth;
51 my $time = strftime
("%F %H:%M:%S", localtime());
52 my $outp = "($time) $package\:$line - $msg\n";
54 if (defined($logger_sub)) {
59 #my $out_octets = encode("utf-8", $outp);
61 print STDERR
$outp if not $SILENT;
62 return ($filename, $line, $msg);
67 my $level = shift || 1;
69 if ($level > $DEBUG) {
74 if (ref($s) eq 'CODE') {
81 return Thrasher
::Log
::log("While trying to print debug message "
82 ."based on a code ref, got an error: $@", 1);
84 return Thrasher
::Log
::log($result, 1);
87 return Thrasher
::Log
::log($s, 1);
94 # logger is a wrapper for calls to old Debug module. We should
95 # antiquate "log" in favor of something else. Perhaps this?
100 return Thrasher
::Log
::log($s, 1);
106 C<dies>($subroutine, $check, $name) - Evaluates $subroutine and fails if
109 If $check is defined, it is tested for truth. This may also be a reference
110 to a regex. In which case the regex is called and tested for truth.
112 $name simply defines what is initially displayed on pass or fail.
117 eval 'use Test::More;';
134 my $die_message = $@
. '';
136 if (ref($check) eq 'Regexp') {
137 if ($die_message !~ /$check/) {
138 fail
($name . " (regex $check not in '$die_message')");
141 if (index($die_message, $check) == -1) {
142 fail
($name . " (string $check not in $die_message)");