CLHEP VERSION Reference Documentation
CLHEP Home Page
CLHEP Documentation
CLHEP Bug Reports
Main Page
Namespaces
Classes
Files
File List
File Members
Exceptions
src
ZMexLogger.cc
Go to the documentation of this file.
1
// ----------------------------------------------------------------------
2
//
3
// ZMexLogger.cc - define basic logging behaviors
4
//
5
// History:
6
// 970919 WEB Created based on code review 4 comments on
7
// ZMexLogger behavior desired
8
// 971007 WEB Removed limiting logger; all loggers now
9
// optionally limit by exception severity
10
// 971211 WEB Updated per code walkthrough
11
// 971211 WEB Created from ZMexLogger.icc per code walkthrough
12
// 971215 WEB Removed unused 2nd parm to ZMexLogger constructor
13
// 971219 WEB Use std::flush instead of endl in ...::emit()
14
// 980617 WEB Added namespace support
15
// 990104 WEB Merged with .icc; restructured os data member
16
// ownership
17
// 990802 JVR Added support for augmented exception logging
18
// 010410 MF Added ZMexValidationStyle
19
//
20
// ----------------------------------------------------------------------
21
22
23
#include "
CLHEP/Exceptions/ZMexLogger.h
"
24
#include "
CLHEP/Exceptions/ZMexception.h
"
25
26
27
// ----------------------------------------------------------------------
28
29
30
namespace
zmex {
31
32
33
// ----------------------------------------------------------------------
34
35
36
// -----------------
37
// ZMexLogBehavior::
38
// -----------------
39
40
ZMexLogBehavior::ZMexLogBehavior
() { ; }
41
42
ZMexLogBehavior::~ZMexLogBehavior
() { ; }
43
44
ZMexLogBehavior
*
45
ZMexLogBehavior::clone
()
const
{
return
new
ZMexLogBehavior
( *
this
); }
46
47
ZMexLogResult
ZMexLogBehavior::emit
(
const
ZMexception
& ) {
48
return
ZMexNOTLOGGED
;
49
}
50
51
ZMexLogResult
ZMexLogBehavior::emit
(
52
const
std::string &
53
) {
54
//DEBUG cerr << "ZMexLogBehavior::emit()" << endl;
55
56
// Do nothing with string& (but do it well!):
57
return
ZMexNOTLOGGED
;
58
}
59
60
bool
ZMexLogBehavior::isTimeDesired
()
const
{
return
true
; }
61
bool
ZMexLogBehavior::isFilePathDesired
()
const
{
return
true
; }
62
63
// --------------
64
// ZMexLogNever::
65
// --------------
66
67
ZMexLogNever::ZMexLogNever
()
68
:
ZMexLogBehavior
()
69
{ ; }
70
71
ZMexLogNever::~ZMexLogNever
() { ; }
72
73
ZMexLogNever
*
74
ZMexLogNever::clone
()
const
{
return
new
ZMexLogNever
( *
this
); }
75
76
ZMexLogResult
ZMexLogNever::emit
(
const
ZMexception
& ) {
77
return
ZMexNOTLOGGED
;
//
78
}
79
80
ZMexLogResult
ZMexLogNever::emit
(
81
const
std::string &
82
) {
83
//DEBUG cerr << "ZMexLogNever::emit()" << endl;
84
85
// Do nothing with string& (but do it well!):
86
return
ZMexNOTLOGGED
;
87
}
88
89
90
// ---------------
91
// ZMexLogAlways::
92
// ---------------
93
94
ZMexLogAlways::ZMexLogAlways
( )
95
:
ZMexLogBehavior
()
96
, myOs( std::cerr )
97
{ ; }
98
99
ZMexLogAlways::ZMexLogAlways
( std::ostream & os )
100
:
ZMexLogBehavior
()
101
, myOs( os )
102
{ ; }
103
104
ZMexLogAlways::~ZMexLogAlways
() { ; }
105
106
ZMexLogAlways
*
107
ZMexLogAlways::clone
()
const
{
return
new
ZMexLogAlways
( *
this
); }
108
109
ZMexLogResult
ZMexLogAlways::emit
(
const
ZMexception
& x ) {
110
std::string s = x.
logMessage
();
//
111
if
( s !=
""
)
112
return
emit
( s );
113
114
x.
logObject
();
115
return
ZMexLOGGED
;
116
}
117
118
ZMexLogResult
ZMexLogAlways::emit
(
119
const
std::string & s
120
) {
121
//DEBUG cerr << "ZMexLogAlways::emit( \"" << s << "\" )" << endl;
122
123
// Emit the message, flushing the output right away:
124
myOs << s << std::flush;
125
return
ZMexLOGGED
;
126
}
127
128
// ---------------
129
// ZMexLogTwice::
130
// ---------------
131
132
ZMexLogTwice::ZMexLogTwice
( std::ostream & os1 )
133
:
ZMexLogBehavior
()
134
, myOs1( os1 )
135
, myOs2( std::cerr )
136
{ ; }
137
138
ZMexLogTwice::ZMexLogTwice
( std::ostream & os1, std::ostream & os2 )
139
:
ZMexLogBehavior
()
140
, myOs1( os1 )
141
, myOs2( os2 )
142
{ ; }
143
144
ZMexLogTwice::~ZMexLogTwice
() { ; }
145
146
ZMexLogTwice
*
147
ZMexLogTwice::clone
()
const
{
return
new
ZMexLogTwice
( *
this
); }
148
149
ZMexLogResult
ZMexLogTwice::emit
(
const
ZMexception
& x ) {
150
std::string s = x.
logMessage
();
151
if
(s !=
""
)
152
return
emit
( s );
153
154
std::cerr <<
"WARNING: ZMexLogTwice() does not log in the usual manner for"
;
155
std::cerr <<
" SuperEx's.\n\t Its ostreams may not have received logs.\n"
;
156
x.
logObject
();
157
return
ZMexLOGGED
;
158
}
159
160
ZMexLogResult
ZMexLogTwice::emit
(
161
const
std::string & s
162
) {
163
//DEBUG cerr << "ZMexLogTwice::emit( \"" << s << "\" )" << endl;
164
165
// Emit the message, flushing the output right away:
166
myOs1 << s << std::flush;
167
myOs2 << s << std::flush;
168
return
ZMexLOGGED
;
169
}
170
171
172
// ------------------
173
// ZMexLogViaParent::
174
// ------------------
175
176
ZMexLogViaParent::ZMexLogViaParent
()
177
:
ZMexLogBehavior
()
178
{ ; }
179
180
ZMexLogViaParent::~ZMexLogViaParent
() { ; }
181
182
ZMexLogViaParent
*
183
ZMexLogViaParent::clone
()
const
{
return
new
ZMexLogViaParent
( *
this
); }
184
185
ZMexLogResult
ZMexLogViaParent::emit
(
const
ZMexception
& ) {
186
return
ZMexLOGVIAPARENT
;
//
187
}
188
189
ZMexLogResult
ZMexLogViaParent::emit
(
const
std::string & ) {
190
//DEBUG cerr << "ZMexLogViaParent::emit( \"" << s << "\" )" << endl;
191
192
// Bump logging decisions to someone else's logger:
193
return
ZMexLOGVIAPARENT
;
194
}
195
196
197
// ------------------
198
// ZMexValidationStyle::
199
// ------------------
200
201
ZMexValidationStyle::ZMexValidationStyle
( )
202
:
ZMexLogBehavior
()
203
, myOs( std::cerr )
204
{ ; }
205
206
ZMexValidationStyle::ZMexValidationStyle
( std::ostream & os )
207
:
ZMexLogBehavior
()
208
, myOs( os )
209
{ ; }
210
211
ZMexValidationStyle::~ZMexValidationStyle
() { ; }
212
213
ZMexValidationStyle
*
214
ZMexValidationStyle::clone
()
const
{
return
new
ZMexValidationStyle
( *
this
); }
215
216
ZMexLogResult
ZMexValidationStyle::emit
(
const
ZMexception
& x ) {
217
std::string s = x.
logMessage
();
218
if
( s !=
""
)
219
return
emit
( s );
220
221
x.
logObject
();
222
return
ZMexLOGGED
;
223
}
224
225
ZMexLogResult
ZMexValidationStyle::emit
(
226
const
std::string & s
227
) {
228
//DEBUG cerr << "ZMexValidationStyle::emit( \"" << s << "\" )" << endl;
229
230
// Emit the message, flushing the output right away:
231
myOs << s << std::flush;
232
return
ZMexLOGGED
;
233
}
234
235
bool
ZMexValidationStyle::isTimeDesired
()
const
{
return
false
; }
236
bool
ZMexValidationStyle::isFilePathDesired
()
const
{
return
false
; }
237
238
// ------------
239
// ZMexLogger::
240
// ------------
241
242
ZMexLogger::ZMexLogger
(
243
const
ZMexLogBehavior
& desiredBehavior
244
)
245
:
ZMhandleTo
<
ZMexLogBehavior
>( desiredBehavior )
246
{ ; }
247
// Construct logger with specified behavior.
248
249
ZMexLogger::~ZMexLogger
() { ; }
250
// Destroy logger with its behavior.
251
252
ZMexLogResult
ZMexLogger::emit
(
const
ZMexception
& exc ) {
253
return
rep_
->emit( exc );
254
}
255
// Force the given exception's message into the log.
256
257
ZMexLogResult
ZMexLogger::emit
(
const
std::string & message ) {
258
return
rep_
->emit( message );
259
}
260
// Force the given message into the log.
261
262
ZMexLogBehavior
*
ZMexLogger::control
() {
return
rep_
; }
263
// Grant access to the representation
264
// to permit calling specialized behavior functions.
265
266
267
// ----------------------------------------------------------------------
268
269
270
}
// namespace zmex
Generated on Mon May 6 2013 04:04:12 for CLHEP by
1.8.1.2