-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlogger.pm
135 lines (105 loc) · 2.38 KB
/
logger.pm
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#!/usr/bin/perl
use warnings;
use strict;
package Logger;
my $instance = undef;
sub new()
{
my $class = shift;
if( defined( $instance ) )
{
return $instance;
}
my $time = Utils->new()->getTime("time");
my $self =
{
_logFilePath => $Utils::scriptPath . "/log/output_$time.log",
_windLogFilePath => $Utils::scriptPath . "/log/WindRiverLocations_$time.log",
_logDescriptor => undef,
_windLogDescriptor => undef,
};
$instance = bless( $self , $class );
return $instance;
}
sub log
{
my $self = shift;
my $lognum = shift;
my $line = shift;
if( $lognum == 1 )
{
if( !defined( $self->{ _logDescriptor } ) )
{
open( $self->{ _logDescriptor }, ">", $self->{ _logFilePath } );
}
if( defined( $self->{ _logDescriptor } ) )
{
my $tf = $self->{ _logDescriptor };
print $tf $line;
}
}
if( $lognum == 2 )
{
if( !defined( $self->{ _windLogDescriptor } ) )
{
open( $self->{ _windLogDescriptor }, ">", $self->{ _windLogFilePath } );
}
if( defined( $self->{ _windLogDescriptor } ) )
{
my $tf = $self->{ _windLogDescriptor };
print $tf $line;
}
}
if( $lognum == 3 )
{
print $line . "\n";
}
}
sub tidy()
{
my @arr = FileManager->new()->readFile( Logger->new->{ _windLogFilePath } );
my @skipArray;
my $lineDiff=0;
my $lineNum=0;
my $i=0;
my $outputStr = "";
foreach my $line ( @arr )
{
if($line =~ m/\@windriver.com|of an applicable Wind River license agreement./i)
{
push(@skipArray, $lineNum-1);
push(@skipArray, $lineNum);
$lineDiff+=2;
}
$lineNum++;
}
my $arrSize = @arr;
for ( $i=0 ; $i<$arrSize ; $i++ )
{
if( $i ~~ @skipArray )
{
next;
}
else
{
$outputStr .= "$arr[$i]\n";
}
}
my $writeLocation = Logger->new->{ _windLogFilePath } =~ s/\.log$/_tidied\.log/r;
Logger->new()->log( 3 , "\n$lineDiff lines removed\n");
FileManager->new()->writeFile( $writeLocation , $outputStr );
}
sub get
{
my $self = shift;
my $key = shift;
return $self->{ $key };
}
sub set
{
my $self = shift;
my $key = shift;
my $value = shift;
$self->{ $key } = $value;
}
1;