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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.3 - (show annotations)
Tue Feb 18 15:56:33 2003 UTC (21 years, 3 months ago) by joko
Branch: MAIN
CVS Tags: HEAD
Changes since 1.2: +4 -1 lines
FILE REMOVED
- moved to Log::Dispatch::Config::Object

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

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