|
1 ################################################################################################## |
|
2 # |
|
3 # Package: LogItem |
|
4 # |
|
5 ################################################################################################## |
|
6 package LogItem; |
|
7 |
|
8 use FindBin; |
|
9 use lib $FindBin::Bin; |
|
10 use strict; |
|
11 |
|
12 use constant ERROR => 1; |
|
13 use constant WARNING => 2; |
|
14 use constant INFO => 3; |
|
15 use constant VERBOSE => 4; |
|
16 |
|
17 #------------------------------------------------------------------------------------------------- |
|
18 # Subroutine: new |
|
19 # Purpose: Constructor |
|
20 # Input: None (extracted from command line args) |
|
21 # Output: A reference to itself |
|
22 #------------------------------------------------------------------------------------------------- |
|
23 sub new() |
|
24 { |
|
25 my $package = shift; |
|
26 my $self = {}; # Create reference to object |
|
27 bless $self, $package; # Associate a reference with class name |
|
28 my %parameters = @_; |
|
29 $self->{iMessage} = $parameters{'msg'} ? $parameters{'msg'} : ""; |
|
30 $self->{iCode} = $parameters{'code'} ? $parameters{'code'} : 0; |
|
31 $self->{iModule} = $parameters{'module'} ? $parameters{'module'} : 0; |
|
32 $self->{iSeverity} = $parameters{'severity'} ? $parameters{'severity'} : 3; # default is INFO |
|
33 $self->{iDepth} = $parameters{'depth'} ? $parameters{'depth'} : 0; |
|
34 |
|
35 $self->{iCode} = 0; |
|
36 |
|
37 $self->{iDate} = scalar(localtime); |
|
38 return $self; |
|
39 } |
|
40 |
|
41 sub Message() |
|
42 { |
|
43 my $self = shift; |
|
44 $self->{iMessage} = $_[0] if $_[0]; |
|
45 return $self->{iMessage}; |
|
46 } |
|
47 |
|
48 sub Module() |
|
49 { |
|
50 my $self = shift; |
|
51 $self->{iModule} = $_[0] if $_[0]; |
|
52 return $self->{iModule}; |
|
53 } |
|
54 |
|
55 sub Severity() |
|
56 { |
|
57 my $self = shift; |
|
58 $self->{iSeverity} = $_[0] if $_[0]; |
|
59 return $self->{iSeverity}; |
|
60 } |
|
61 |
|
62 sub Depth() |
|
63 { |
|
64 my $self = shift; |
|
65 $self->{iDepth} = $_[0] if $_[0]; |
|
66 return $self->{iDepth}; |
|
67 } |
|
68 |
|
69 sub Date() |
|
70 { |
|
71 my $self = shift; |
|
72 $self->{iDate} = $_[0] if $_[0]; |
|
73 return $self->{iDate}; |
|
74 } |
|
75 |
|
76 sub Code() |
|
77 { |
|
78 my $self = shift; |
|
79 $self->{iCode} = $_[0] if $_[0]; |
|
80 return $self->{iCode}; |
|
81 } |
|
82 |
|
83 sub LogText() |
|
84 { |
|
85 my $self = shift; |
|
86 return $self->SeverityText()."(".$self->{iCode}.") [".$self->{iDate}."]: "." " x $self->{iDepth}.$self->{iMessage}."\n"; |
|
87 } |
|
88 |
|
89 sub SeverityText() |
|
90 { |
|
91 my $self = shift; |
|
92 return " ERROR" if $self->Severity() == ERROR; |
|
93 return "WARNING" if $self->Severity() == WARNING; |
|
94 return "VERBOSE" if $self->Severity() == VERBOSE; |
|
95 return " INFO"; |
|
96 } |
|
97 |
|
98 1; |