| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Kephra::Log; |
|
2
|
|
|
|
|
|
|
$VERSION = '0.01'; |
|
3
|
|
|
|
|
|
|
|
|
4
|
1
|
|
|
1
|
|
1081
|
use strict; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
32
|
|
|
5
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
1533
|
|
|
6
|
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
sub setup_logging { |
|
8
|
0
|
|
|
0
|
0
|
|
eval { |
|
9
|
0
|
|
|
|
|
|
require Log::Dispatch; |
|
10
|
0
|
|
|
|
|
|
require Log::Dispatch::File; |
|
11
|
|
|
|
|
|
|
}; |
|
12
|
0
|
0
|
|
|
|
|
if ($@) { |
|
13
|
0
|
|
|
|
|
|
_setup_fake_logger(); |
|
14
|
|
|
|
|
|
|
} else { |
|
15
|
0
|
|
|
|
|
|
_setup_real_logger(); |
|
16
|
|
|
|
|
|
|
} |
|
17
|
0
|
|
|
|
|
|
$main::logger->info("Starting"); |
|
18
|
0
|
|
|
|
|
|
return; |
|
19
|
|
|
|
|
|
|
} |
|
20
|
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub _setup_fake_logger { |
|
22
|
|
|
|
|
|
|
package Kephra::FakeLogger; |
|
23
|
0
|
|
|
0
|
|
|
$main::logger = bless {}, __PACKAGE__; |
|
24
|
1
|
|
|
1
|
|
25
|
no strict 'refs'; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
774
|
|
|
25
|
0
|
|
|
|
|
|
foreach my $l ( qw( debug info notice warning err error crit critical alert emerg emergency ) ) |
|
26
|
|
|
|
|
|
|
{ |
|
27
|
0
|
|
|
0
|
|
|
*{$l} = sub {}; |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
} |
|
29
|
0
|
|
|
|
|
|
return; |
|
30
|
|
|
|
|
|
|
} |
|
31
|
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub _setup_real_logger { |
|
33
|
0
|
|
|
0
|
|
|
mkdir $Kephra::temp{path}{logger}; |
|
34
|
|
|
|
|
|
|
# TODO: setup pseudo logger in case the directory does not exist or |
|
35
|
|
|
|
|
|
|
# otherwise cannot start the logger, report error |
|
36
|
0
|
|
|
|
|
|
$main::logger = Log::Dispatch->new; |
|
37
|
0
|
|
|
|
|
|
require POSIX; |
|
38
|
0
|
|
|
|
|
|
my $ts = POSIX::strftime("%Y%m%d", localtime); |
|
39
|
0
|
|
|
|
|
|
print File::Spec->catfile($Kephra::temp{path}{logger}, "$ts.log"); |
|
40
|
0
|
|
0
|
|
|
|
$main::logger->add( Log::Dispatch::File->new( |
|
41
|
|
|
|
|
|
|
name => 'file1', |
|
42
|
|
|
|
|
|
|
min_level => ($ENV{KEPHRA_LOGGIN} || 'debug'), |
|
43
|
|
|
|
|
|
|
filename => File::Spec->catfile($Kephra::temp{path}{logger}, "$ts.log"), |
|
44
|
|
|
|
|
|
|
mode => 'append', |
|
45
|
|
|
|
|
|
|
callbacks => \&_logger, |
|
46
|
|
|
|
|
|
|
)); |
|
47
|
0
|
|
|
0
|
|
|
$SIG{__WARN__} = sub { $main::logger->warning($_[0]) }; |
|
|
0
|
|
|
|
|
|
|
|
48
|
0
|
|
|
|
|
|
return; |
|
49
|
|
|
|
|
|
|
} |
|
50
|
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub _logger { |
|
53
|
0
|
|
|
0
|
|
|
my %data = @_; |
|
54
|
|
|
|
|
|
|
# TODO maybe we should use regular timestamp here and turn on the hires timestamp |
|
55
|
|
|
|
|
|
|
# only if KEPHRA_TIME or similar env variable is set |
|
56
|
0
|
|
|
|
|
|
require Time::HiRes; |
|
57
|
0
|
|
|
|
|
|
return sprintf("%s - %s - %s - %s\n", Time::HiRes::time(), $$, $data{level}, $data{message}); |
|
58
|
|
|
|
|
|
|
} |
|
59
|
|
|
|
|
|
|
|
|
60
|
0
|
|
|
0
|
0
|
|
sub msg { message(@_) } |
|
61
|
0
|
|
|
0
|
0
|
|
sub message { |
|
62
|
|
|
|
|
|
|
#Wx::LogMessage( "Hello from MyTimer::Notify!" ); |
|
63
|
|
|
|
|
|
|
# Wx::Log::SetActiveTarget( delete $this->{OLDLOG} ); |
|
64
|
|
|
|
|
|
|
#$this->{OLDLOG} = |
|
65
|
|
|
|
|
|
|
#Wx::Log::SetActiveTarget( Wx::LogTextCtrl->new( $this->{TEXT} ) ); |
|
66
|
|
|
|
|
|
|
# |
|
67
|
|
|
|
|
|
|
#Wx::LogTraceMask( 'test', "You can't see this!" ); |
|
68
|
|
|
|
|
|
|
#Wx::Log::AddTraceMask( 'test' ); |
|
69
|
|
|
|
|
|
|
#Wx::LogTraceMask( "Wx::LogTraceMask" ); |
|
70
|
|
|
|
|
|
|
#Wx::Log::SetActiveTarget( $this->{PANEL}->{OLDLOG} ); |
|
71
|
|
|
|
|
|
|
} |
|
72
|
|
|
|
|
|
|
|
|
73
|
0
|
|
|
0
|
0
|
|
sub warn { Kephra::App::StatusBar::info_msg(@_) } |
|
74
|
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
1; |