/[cvs]/nfo/perl/libs/Log/Dispatch/Config/Object.pm
ViewVC logotype

Contents of /nfo/perl/libs/Log/Dispatch/Config/Object.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (show annotations)
Tue Feb 18 15:57:34 2003 UTC (21 years, 6 months ago) by joko
Branch: MAIN
+ initial commit, refactored from DesignPattern::Object::Logger

1 ## ------------------------------------------------------------------------
2 ## $Id: Logger.pm,v 1.2 2003/02/14 14:20:42 joko Exp $
3 ## ------------------------------------------------------------------------
4 ## $Log: Logger.pm,v $
5 ## Revision 1.2 2003/02/14 14:20:42 joko
6 ## + decreased default log-level to debug
7 ##
8 ## Revision 1.1 2002/12/22 14:17:38 joko
9 ## + initial check-in, refactored
10 ##
11 ## Revision 1.1 2002/12/19 01:14:48 cvsjoko
12 ## + initial check-in
13 ##
14 ## ------------------------------------------------------------------------
15
16
17 package Log::Dispatch::Config::Object;
18
19 use strict;
20 use warnings;
21
22 use Data::Dumper;
23 use Log::Dispatch;
24 use Log::Dispatch::Config;
25 use Log::Dispatch::Configurator::Hardwired;
26 use Cwd;
27
28
29 # TODO: review, revise and rewire this!
30 #my $logger = Log::Dispatch::Config->instance;
31
32 sub __init {
33 my $self = shift;
34 my $action = shift;
35 my $message = shift;
36 #my $options = shift; # ??? or: $self->{options} already...?
37
38 # configure
39 if (!$self->{__logger}->{configured}) {
40 $self->{__logger}->{configured} = 1;
41 $self->_configure_LogDispatch();
42 }
43
44 # set passed-in arguments
45 $self->{action} = $action;
46 $self->{message} = $message;
47
48 # set default arguments
49 $self->{classname} = ref $self;
50 $self->{caller} = caller;
51
52 # set default values
53 $self->{action} ||= '';
54 $self->{options}->{tag} ||= '';
55
56 #$self->{level} ||= 'info';
57 $self->{level} ||= 'debug';
58
59 }
60
61 sub __out {
62 my $self = shift;
63 my $message = shift;
64
65 # if message given here, append to message stored inside object
66 $self->{message} .= ' - ' . $message if $message;
67
68 # TODO: refactor this:
69 # - push '$self->__get_prefix()' to additional log-entry-metadata, don't show it on/in any console/logfile output
70 #$logger->log( level => $self->{level}, message => $self->__get_prefix_long() . $message );
71 #$logger->log( level => $self->{level}, message => $message );
72 #$logger->warning( __PACKAGE__ . "->_skip: '$caller' (mixed into '$classname'): ($options->{tag}) $message.");
73 #$self->{__logger}->{instance}->log( level => $self->{level}, message => $self->__get_prefix_short() . $self->{message} );
74 $self->{__logger}->{instance}->log( level => $self->{level}, message => $self->__get_prefix_module() . $self->{message} );
75 }
76
77
78 sub __handle_options {
79 my $self = shift;
80 #my $options = shift; # ??? or: $self->{options} already...?
81 }
82
83 sub __get_prefix_long {
84 my $self = shift;
85 return __PACKAGE__ . "->$self->{action}: '$self->{caller}' (mixed into '$self->{classname}'): ($self->{options}->{tag}) - ";
86 }
87
88 sub __get_prefix_short {
89 my $self = shift;
90 my $tag_append = '';
91 $tag_append = "$self->{options}->{tag} - " if $self->{options}->{tag};
92 return $self->{classname} . "->$self->{action}: $tag_append";
93 }
94
95 sub __get_prefix_module {
96 my $self = shift;
97 my $tag_append = '';
98 $tag_append = "$self->{options}->{tag} - " if $self->{options}->{tag};
99 return $self->{classname} . ": $tag_append";
100 }
101
102
103 sub log {
104 my $self = shift;
105 my $message = shift;
106 $self->{level} = shift; # TODO: implement propagation of this into Log::Dispatch-object '$logger'!
107 $self->{options} = shift; # TODO: implement additional behaviours: e.g. { exit => 1 } would exit after tracedump
108
109 #$self->__init('log', $message);
110 $self->__init('log', $message);
111 $self->__out();
112
113 }
114
115 sub skip {
116 my $self = shift;
117 my $message = shift;
118 my $condition = shift;
119 $self->{level} = shift; # TODO: implement propagation of this into Log::Dispatch-object '$logger'!
120 $self->{options} = shift; # TODO: implement additional behaviours: e.g. { exit => 1 } would exit after tracedump
121
122 my $classname = ref $self;
123 my $caller = caller;
124
125 $self->{options}->{tag} ||= '';
126
127 if ($condition) {
128 # V1:
129 #$logger->warning( __PACKAGE__ . "->_skip: '$caller' (mixed into '$classname'): ($options->{tag}) $message.");
130 # V2:
131 $self->__init('skip', $message);
132 $self->__out();
133 return 1;
134 }
135 }
136
137 sub trace {
138 my $self = shift;
139 my $message = shift;
140 my $data = shift;
141 my $condition = shift;
142 $self->{level} = shift; # TODO: implement propagation of this into Log::Dispatch-object '$logger'!
143 $self->{options} = shift; # TODO: implement additional behaviours: e.g. { exit => 1 } would exit after tracedump
144
145 my $classname = ref $self;
146 my $caller = caller;
147
148 $self->{options}->{tag} ||= '';
149
150 # don't do _any_ tracing if disabled
151 return if $self->{TRACE_DISABLED};
152
153 # overwrite condition with local configured want-TRACE
154 $condition ||= $self->{TRACE};
155
156 # dump data
157 my $result = 0;
158 if ($condition) {
159 $message .= " - " . Dumper($data);
160
161 # V1:
162 # $self->__init('trace');
163 # $logger->info( __PACKAGE__ . "->trace: '$caller' (mixed into '$classname'): ($options->{tag}) $message.");
164
165 # V2:
166 $self->__init('trace', $message);
167 $self->__out();
168
169 $result = 1;
170 } else {
171 $result = 0;
172 }
173
174 # handle additional options
175 if ($self->{TRACE_OPTIONS}) {
176 exit if $self->{options}->{exit};
177 }
178
179 return $result;
180 }
181
182
183 sub _configure_LogDispatch {
184 my $self = shift;
185 my $logHandlerMeta = Log::Dispatch::Configurator::Hardwired->new();
186
187 my $basepath = cwd() . '/..';
188 #print "base: $basepath", "\n";
189 #exit;
190
191 # configure custom logHandler
192 $logHandlerMeta->{file_filename} = "$basepath/var/log/logfile.txt";
193 $logHandlerMeta->{screen_min_level} = 'info';
194
195 if ($self->{quiet}) {
196 $logHandlerMeta->{screen_min_level} = 8;
197 }
198
199 if ($self->{debug}) {
200 $logHandlerMeta->{screen_min_level} = 'debug';
201 }
202
203 if ($self->{verbose}) {
204 $logHandlerMeta->{verbose} = 1;
205 }
206
207 Log::Dispatch::Config->configure($logHandlerMeta);
208
209 $self->{__logger}->{instance} = Log::Dispatch::Config->instance;
210
211 }
212
213 1;
214 __END__

MailToCvsAdmin">MailToCvsAdmin
ViewVC Help
Powered by ViewVC 1.1.26 RSS 2.0 feed