-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLog.pm
More file actions
44 lines (32 loc) · 771 Bytes
/
Log.pm
File metadata and controls
44 lines (32 loc) · 771 Bytes
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!usr/bin/env perl
package Log;
use warnings;
use strict;
use POSIX qw{strftime};
our @ISA = qw{Exporter};
our @EXPORT_OK = qw{
_print_it
};
sub _print_it {
my ($msg, $type) = @_;
$type ||= 'error';
my @caller_args = ();
for (my $i = 0 ; $i < 5 ; $i++) {
my ($package, $filename, $line) = (caller($i))[0..2];
last unless ($package && $filename && $line);
$package = $filename if $package eq "main";
push(@caller_args, "$package:$line")
}
my $output = strftime("%Y/%m/%d %H:%M:%S %z", localtime) . " [$type] " .
( $msg ?
$msg :
'undefined msg variable'
) .
( (scalar(@caller_args) > 0 ) ?
' (' . join(' < ', @caller_args) . ')' :
''
) . "\n";
( $type eq "error" ) ? ( print STDERR $output ) : ( print STDOUT $output ) ;
return 1;
}
1;