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 string err =
"BES Fatal: unable to determine log file name. The key BES.LogName has multiple values";
88 string local_time =
"no";
91 if (local_time ==
"YES" || local_time ==
"Yes" || local_time ==
"yes") {
92 d_use_local_time =
true;
97 string err =
"BES Fatal: Unable to read the value of BES.LogTimeUTC";
102 if (d_file_name ==
"") {
103 string err =
"BES Fatal: unable to determine log file name. Please set BES.LogName in your initialization file";
108 d_file_buffer =
new ofstream(d_file_name.c_str(), ios::out | ios::app);
109 if (!(*d_file_buffer)) {
110 string err =
"BES Fatal; cannot open log file " + d_file_name +
".";
118 if (verbose ==
"YES" || verbose ==
"Yes" || verbose ==
"yes") {
129 d_file_buffer->close();
130 delete d_file_buffer;
143 #ifdef ISO8601_TIME_IN_LOGS 146 char buf[
sizeof "YYYY-MM-DDTHH:MM:SSzone"];
155 if (!d_use_local_time)
156 status = strftime(buf,
sizeof buf,
"%FT%T%Z", gmtime(&now));
158 status = strftime(buf,
sizeof buf,
"%FT%T%Z", localtime(&now));
160 (*d_file_buffer) << buf;
163 const time_t sctime = time(NULL);
164 const struct tm *sttime = localtime(&sctime);
166 strftime(zone_name,
sizeof(zone_name),
"%Z", sttime);
167 char *b = asctime(sttime);
169 (*d_file_buffer) << zone_name <<
" ";
170 for (
register int j = 0; b[j] !=
'\n'; j++)
171 (*d_file_buffer) << b[j];
174 (*d_file_buffer) << mark << getpid() << mark;
189 (*d_file_buffer) << s;
202 (*d_file_buffer) << s;
216 (*d_file_buffer) << val;
218 (*d_file_buffer) <<
"NULL";
234 (*d_file_buffer) << val;
236 (*d_file_buffer) <<
"NULL";
249 (*d_file_buffer) << val;
262 (*d_file_buffer) << val;
275 (*d_file_buffer) << val;
288 (*d_file_buffer) << val;
301 (*d_file_buffer) << val;
316 (*d_file_buffer) << val;
322 void BESLog::flush_me(){
323 (*d_file_buffer) << flush;
335 if (!d_suspended) (*d_file_buffer) << val;
348 strm << BESIndent::LMarg <<
"BESLog::dump - (" << (
void *)
this <<
")" << endl;
350 strm << BESIndent::LMarg <<
"log file: " << d_file_name << endl;
351 if (d_file_buffer && *d_file_buffer) {
352 strm << BESIndent::LMarg <<
"log is valid" << endl;
355 strm << BESIndent::LMarg <<
"log is NOT valid" << endl;
357 strm << BESIndent::LMarg <<
"is verbose: " << d_verbose << endl;
358 strm << BESIndent::LMarg <<
"is flushed: " << d_flushed << endl;
359 strm << BESIndent::LMarg <<
"is suspended: " << d_suspended << endl;
360 BESIndent::UnIndent();
366 if (d_instance == 0) {
virtual void dump(std::ostream &strm) const
dumps information about this object
exception thrown if an internal error is found and is fatal to the BES
~BESLog()
Cleans up the logging mechanism.
BESLog & operator<<(std::string &)
Overloaded inserter that writes the specified string.
void get_value(const string &s, string &val, bool &found)
Retrieve the value of a given key, if set.
static TheBESKeys * TheKeys()
std::ostream &(* p_ostream_manipulator)(std::ostream &)
Defines a data type p_std::ostream_manipulator "pointer to function that takes std::ostream& and retu...
void dump_time()
Protected method that dumps the date/time to the log file.
BESLog()
constructor that sets up logging for the application.
Provides a mechanism for applications to log information to an external file.