/[cvs]/nfo/perl/libs/DesignPattern/Exception.pm
ViewVC logotype

Diff of /nfo/perl/libs/DesignPattern/Exception.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.1 by joko, Wed Feb 19 00:35:09 2003 UTC revision 1.3 by joko, Fri Feb 21 08:39:31 2003 UTC
# Line 2  Line 2 
2  ##  $Id$  ##  $Id$
3  ## ------------------------------------------------------------------------  ## ------------------------------------------------------------------------
4  ##  $Log$  ##  $Log$
5    ##  Revision 1.3  2003/02/21 08:39:31  joko
6    ##  raises exceptions via logger
7    ##
8    ##  Revision 1.2  2003/02/20 20:53:55  joko
9    ##  + fix: using Object's basic log method if not running together with the Logger
10    ##
11  ##  Revision 1.1  2003/02/19 00:35:09  joko  ##  Revision 1.1  2003/02/19 00:35:09  joko
12  ##  + initial commit  ##  + initial commit
13  ##  ##
# Line 13  package DesignPattern::Exception; Line 19  package DesignPattern::Exception;
19  use strict;  use strict;
20  use warnings;  use warnings;
21    
22    
23    use base qw( DesignPattern::Object );
24    
25    
26  sub checkExceptions {  sub checkExceptions {
27    my $self = shift;    my $self = shift;
28    
# Line 21  sub checkExceptions { Line 31  sub checkExceptions {
31    
32    # behaviour B: log the error message as a warning    # behaviour B: log the error message as a warning
33      if ($@) {      if ($@) {
34        $self->log($@, 'warning');        if ($self->can('log')) {
35            $self->log($@, 'warning');
36          } else {
37            #print "warning: ", $@, "\n";
38            #print "warning: ", $@, "\n";
39            $self->log_basic($@, 'warning');
40          }
41          return 1;
42      }      }
43        
44  }  }
45    
46    sub raiseException {
47      my $self = shift;
48      my $message = shift;
49      my $level = shift;
50      $message ||= 'UNKNOWN ERROR';
51      $level ||= 'critical';
52      $self->_viaLogger($message, $level);
53    }
54    
55    sub _viaLogger {
56      my $self = shift;
57      my $message = shift;
58      my $level = shift;
59      # get logger instance
60      my $logger = eval { Log::Dispatch::Config->instance; };
61      if ($logger) {
62        $logger->log( message => $message, level => $level );
63      } else {
64        print "ERROR[$level] $message", "\n";
65      }
66    }
67    
68  1;  1;
69  __END__  __END__

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.3

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