40 #include "TheBESKeys.h"
41 #include "BESInternalFatalError.h"
47 #define ISO8601_TIME_IN_LOGS
51 BESLog *BESLog::d_instance = 0;
52 const string BESLog::mark = string(
"|&|");
73 d_flushed(1), d_file_buffer(0), d_suspended(0), d_verbose(false), d_use_local_time(false)
81 cerr <<
"BESInternalFatalError! Message: " << bife.
get_message() <<
" File: " << bife.
get_file() <<
" Line: " << bife.
get_line() << endl;
85 string err =
"Caught unknown exception! Unable to determine log file name. BES fatal error!";
92 string local_time =
"no";
95 if (local_time ==
"YES" || local_time ==
"Yes" || local_time ==
"yes") {
96 d_use_local_time =
true;
101 string err =
"BES Fatal: Unable to read the value of BES.LogTimeUTC";
106 if (d_file_name ==
"") {
107 string err =
"BES Fatal: unable to determine log file name. Please set BES.LogName in your initialization file";
112 d_file_buffer =
new ofstream(d_file_name.c_str(), ios::out | ios::app);
113 if (!(*d_file_buffer)) {
114 string err =
"BES Fatal; cannot open log file " + d_file_name +
".";
122 if (verbose ==
"YES" || verbose ==
"Yes" || verbose ==
"yes") {
133 d_file_buffer->close();
134 delete d_file_buffer;
147 #ifdef ISO8601_TIME_IN_LOGS
150 char buf[
sizeof "YYYY-MM-DDTHH:MM:SSzone"];
159 if (!d_use_local_time)
160 status = strftime(buf,
sizeof buf,
"%FT%T%Z", gmtime(&now));
162 status = strftime(buf,
sizeof buf,
"%FT%T%Z", localtime(&now));
164 (*d_file_buffer) << buf;
167 const time_t sctime = time(NULL);
168 const struct tm *sttime = localtime(&sctime);
170 strftime(zone_name,
sizeof(zone_name),
"%Z", sttime);
171 char *b = asctime(sttime);
173 (*d_file_buffer) << zone_name <<
" ";
174 for (
register int j = 0; b[j] !=
'\n'; j++)
175 (*d_file_buffer) << b[j];
178 (*d_file_buffer) << mark << getpid() << mark;
193 (*d_file_buffer) << s;
206 (*d_file_buffer) << s;
220 (*d_file_buffer) << val;
222 (*d_file_buffer) <<
"NULL";
238 (*d_file_buffer) << val;
240 (*d_file_buffer) <<
"NULL";
253 (*d_file_buffer) << val;
262 (*d_file_buffer) << val;
276 (*d_file_buffer) << val;
289 (*d_file_buffer) << val;
302 (*d_file_buffer) << val;
315 (*d_file_buffer) << val;
330 (*d_file_buffer) << val;
336 void BESLog::flush_me(){
337 (*d_file_buffer) << flush;
349 if (!d_suspended) (*d_file_buffer) << val;
362 strm << BESIndent::LMarg <<
"BESLog::dump - (" << (
void *)
this <<
")" << endl;
364 strm << BESIndent::LMarg <<
"log file: " << d_file_name << endl;
365 if (d_file_buffer && *d_file_buffer) {
366 strm << BESIndent::LMarg <<
"log is valid" << endl;
369 strm << BESIndent::LMarg <<
"log is NOT valid" << endl;
371 strm << BESIndent::LMarg <<
"is verbose: " << d_verbose << endl;
372 strm << BESIndent::LMarg <<
"is flushed: " << d_flushed << endl;
373 strm << BESIndent::LMarg <<
"is suspended: " << d_suspended << endl;
374 BESIndent::UnIndent();
380 if (d_instance == 0) {