2 |
## $Id$ |
## $Id$ |
3 |
## --------------------------------------------------------------------------- |
## --------------------------------------------------------------------------- |
4 |
## $Log$ |
## $Log$ |
5 |
|
## Revision 1.10 2003/05/13 08:46:08 joko |
6 |
|
## pod and comments |
7 |
|
## |
8 |
|
## Revision 1.9 2003/03/27 15:44:32 joko |
9 |
|
## fixes/enhancements to 'sub log_basic' |
10 |
|
## |
11 |
|
## Revision 1.8 2003/02/19 00:36:59 joko |
12 |
|
## + bugfix: this {logger} is the instance itself, so has to be fed with ( level => xyz and namespace => xyz ) |
13 |
|
## + minor modifications in behaviour |
14 |
|
## |
15 |
## Revision 1.7 2003/02/18 18:34:35 joko |
## Revision 1.7 2003/02/18 18:34:35 joko |
16 |
## + fix: just logs if possible (sub log_basic) |
## + fix: just logs if possible (sub log_basic) |
17 |
## |
## |
35 |
## |
## |
36 |
## --------------------------------------------------------------------------- |
## --------------------------------------------------------------------------- |
37 |
|
|
38 |
|
=pod |
39 |
|
|
40 |
|
=head1 NAME |
41 |
|
|
42 |
|
DesignPattern::Object |
43 |
|
|
44 |
|
|
45 |
|
=head1 TODO |
46 |
|
|
47 |
|
o use Class::Loader |
48 |
|
|
49 |
|
|
50 |
|
=cut |
51 |
|
|
52 |
package DesignPattern::Object; |
package DesignPattern::Object; |
53 |
|
|
184 |
eval($evstring); |
eval($evstring); |
185 |
|
|
186 |
# report errors |
# report errors |
187 |
|
# Could this be united with DesignPattern::Loader::checkExceptions? |
188 |
if ($@) { |
if ($@) { |
189 |
# build error-messages |
# build error-messages |
190 |
my $errmsg_native = __PACKAGE__ . ':' . __LINE__ . " Error in eval \"$evstring\": " . $@; |
my $issuer = __PACKAGE__ . ':' . __LINE__; |
191 |
|
my $errmsg_native = "Error in eval: " . $@; |
192 |
#my $classname = $self->{__classname}; |
#my $classname = $self->{__classname}; |
193 |
my $errmsg_critical = ''; |
my $errmsg_critical = ''; |
194 |
if ($errmsg_native =~ m/Can't locate (.+?) in \@INC/) { |
if ($errmsg_native =~ m/Can't locate (.+?) in \@INC/) { |
197 |
$errmsg_critical = $errmsg_native; |
$errmsg_critical = $errmsg_native; |
198 |
} |
} |
199 |
# write error to logging-output (console|file|database) |
# write error to logging-output (console|file|database) |
200 |
$self->log_basic( $errmsg_native, 'debug' ); |
$self->log_basic( $errmsg_native . " (issuer='$issuer', code='$evstring')", 'debug' ); |
201 |
$self->log_basic( $errmsg_critical, 'warning' ); |
$self->log_basic( $errmsg_critical, 'warning' ); |
202 |
return; |
return; |
203 |
} |
} |
205 |
# object-creation |
# object-creation |
206 |
my $object = $pkgname->new(@args); |
my $object = $pkgname->new(@args); |
207 |
|
|
208 |
|
# trace |
209 |
|
#print Dumper($object); |
210 |
|
|
211 |
# run boot-methods on object |
# run boot-methods on object |
212 |
$object->_init() if $object->can('_init'); |
$object->_init() if $object->can('_init'); |
213 |
$object->constructor() if $object->can('constructor'); |
$object->constructor() if $object->can('constructor'); |
219 |
my $self = shift; |
my $self = shift; |
220 |
my $message = shift; |
my $message = shift; |
221 |
my $level = shift; |
my $level = shift; |
222 |
|
|
223 |
|
#return; |
224 |
|
$level ||= 'info'; |
225 |
|
|
226 |
|
my $notSoGood = ($level =~ /warning|error|critical/); |
227 |
|
|
228 |
|
# STDERR? |
229 |
|
if ($level && $notSoGood) { |
230 |
|
print STDERR $level, ": ", $message, "\n"; |
231 |
|
} |
232 |
|
|
233 |
if ($_dp_globals->{TRACE} || ($level && $level =~ /warning|error|critical/)) { |
# STDOUT? |
234 |
|
if ($_dp_globals->{TRACE} || $notSoGood) { |
235 |
print $level, ": ", $message, "\n"; |
print $level, ": ", $message, "\n"; |
236 |
} |
} |
237 |
|
|
241 |
} |
} |
242 |
|
|
243 |
if ($_dp_globals->{logger}) { |
if ($_dp_globals->{logger}) { |
244 |
$_dp_globals->{logger}->log($level, $message); |
$_dp_globals->{logger}->log( level => $level, message => $message); |
245 |
#} else { |
#} else { |
246 |
#print $level, ": ", $message, "\n"; |
#print $level, ": ", $message, "\n"; |
247 |
} |
} |