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

Annotation of /nfo/perl/libs/DesignPattern/Object/Logger.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.2 - (hide annotations)
Fri Feb 14 14:20:42 2003 UTC (21 years, 4 months ago) by joko
Branch: MAIN
Changes since 1.1: +9 -3 lines
+ decreased default log-level to debug

1 joko 1.1 ## ------------------------------------------------------------------------
2 joko 1.2 ## $Id: Logger.pm,v 1.1 2002/12/22 14:17:38 joko Exp $
3 joko 1.1 ## ------------------------------------------------------------------------
4 joko 1.2 ## $Log: Logger.pm,v $
5     ## Revision 1.1 2002/12/22 14:17:38 joko
6     ## + initial check-in
7     ##
8 joko 1.1 ## Revision 1.1 2002/12/19 01:14:48 cvsjoko
9     ## + initial check-in
10     ##
11     ## ------------------------------------------------------------------------
12    
13    
14     package DesignPattern::Object::Logger;
15    
16     use strict;
17     use warnings;
18    
19     use Data::Dumper;
20    
21     # TODO: review, revise and rewire this!
22     my $logger = Log::Dispatch::Config->instance;
23    
24     sub __init {
25     my $self = shift;
26     my $action = shift;
27     my $message = shift;
28     #my $options = shift; # ??? or: $self->{options} already...?
29    
30     # set passed-in arguments
31     $self->{action} = $action;
32     $self->{message} = $message;
33    
34     # set default arguments
35     $self->{classname} = ref $self;
36     $self->{caller} = caller;
37    
38     # set default values
39     $self->{action} ||= '';
40     $self->{options}->{tag} ||= '';
41 joko 1.2
42     #$self->{level} ||= 'info';
43     $self->{level} ||= 'debug';
44    
45 joko 1.1 }
46    
47     sub __out {
48     my $self = shift;
49     my $message = shift;
50    
51     # if message given here, append to message stored inside object
52     $self->{message} .= ' - ' . $message if $message;
53    
54     # TODO: refactor this:
55     # - push '$self->__get_prefix()' to additional log-entry-metadata, don't show it on/in any console/logfile output
56     #$logger->log( level => $self->{level}, message => $self->__get_prefix_long() . $message );
57     #$logger->log( level => $self->{level}, message => $message );
58     #$logger->warning( __PACKAGE__ . "->_skip: '$caller' (mixed into '$classname'): ($options->{tag}) $message.");
59     $logger->log( level => $self->{level}, message => $self->__get_prefix_short() . $self->{message} );
60     }
61    
62    
63     sub __handle_options {
64     my $self = shift;
65     #my $options = shift; # ??? or: $self->{options} already...?
66     }
67    
68     sub __get_prefix_long {
69     my $self = shift;
70     return __PACKAGE__ . "->$self->{action}: '$self->{caller}' (mixed into '$self->{classname}'): ($self->{options}->{tag}) - ";
71     }
72    
73     sub __get_prefix_short {
74     my $self = shift;
75     my $tag_append = '';
76     $tag_append = "$self->{options}->{tag} - " if $self->{options}->{tag};
77     return $self->{classname} . "->$self->{action}: $tag_append";
78     }
79    
80    
81    
82     sub log {
83     my $self = shift;
84     my $message = shift;
85     $self->{level} = shift; # TODO: implement propagation of this into Log::Dispatch-object '$logger'!
86     $self->{options} = shift; # TODO: implement additional behaviours: e.g. { exit => 1 } would exit after tracedump
87    
88     $self->__init('log', $message);
89     $self->__out();
90    
91     }
92    
93     sub skip {
94     my $self = shift;
95     my $message = shift;
96     my $condition = shift;
97     $self->{level} = shift; # TODO: implement propagation of this into Log::Dispatch-object '$logger'!
98     $self->{options} = shift; # TODO: implement additional behaviours: e.g. { exit => 1 } would exit after tracedump
99    
100     my $classname = ref $self;
101     my $caller = caller;
102    
103     $self->{options}->{tag} ||= '';
104    
105     if ($condition) {
106     # V1:
107     #$logger->warning( __PACKAGE__ . "->_skip: '$caller' (mixed into '$classname'): ($options->{tag}) $message.");
108     # V2:
109     $self->__init('skip', $message);
110     $self->__out();
111     return 1;
112     }
113     }
114    
115     sub trace {
116     my $self = shift;
117     my $message = shift;
118     my $data = shift;
119     my $condition = shift;
120     $self->{level} = shift; # TODO: implement propagation of this into Log::Dispatch-object '$logger'!
121     $self->{options} = shift; # TODO: implement additional behaviours: e.g. { exit => 1 } would exit after tracedump
122    
123     my $classname = ref $self;
124     my $caller = caller;
125    
126     $self->{options}->{tag} ||= '';
127    
128     # don't do _any_ tracing if disabled
129     return if $self->{TRACE_DISABLED};
130    
131     # overwrite condition with local configured want-TRACE
132     $condition ||= $self->{TRACE};
133    
134     # dump data
135     my $result = 0;
136     if ($condition) {
137     $message .= " - " . Dumper($data);
138    
139     # V1:
140     # $self->__init('trace');
141     # $logger->info( __PACKAGE__ . "->trace: '$caller' (mixed into '$classname'): ($options->{tag}) $message.");
142    
143     # V2:
144     $self->__init('trace', $message);
145     $self->__out();
146    
147     $result = 1;
148     } else {
149     $result = 0;
150     }
151    
152     # handle additional options
153     if ($self->{TRACE_OPTIONS}) {
154     exit if $self->{options}->{exit};
155     }
156    
157     return $result;
158     }
159    
160     1;

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