40 #include "TheBESKeys.h" 41 #include "BESInternalFatalError.h" 49 BESLog *BESLog::_instance = 0;
67 _flushed(1), _file_buffer(0), _suspended(0), _verbose(false)
75 string err = (string)
"BES Fatal: unable to determine log file name." 76 +
" The key BES.LogName has multiple values";
80 if (_file_name ==
"") {
81 string err = (string)
"BES Fatal: unable to determine log file name." 82 +
" Please set BES.LogName in your initialization file";
86 _file_buffer =
new ofstream(_file_name.c_str(), ios::out | ios::app);
87 if (!(*_file_buffer)) {
88 string err = (string)
"BES Fatal; cannot open log file " + _file_name +
".";
95 if (verbose ==
"YES" || verbose ==
"Yes" || verbose ==
"yes") {
106 _file_buffer->close();
119 const time_t sctime = time(NULL);
120 const struct tm *sttime = localtime(&sctime);
122 strftime(zone_name,
sizeof(zone_name),
"%Z", sttime);
123 char *b = asctime(sttime);
124 (*_file_buffer) <<
"[" << zone_name <<
" ";
125 for (
register int j = 0; b[j] !=
'\n'; j++)
126 (*_file_buffer) << b[j];
127 pid_t thepid = getpid();
128 (*_file_buffer) <<
" id: " << thepid <<
"] ";
142 (*_file_buffer) << s;
155 (*_file_buffer) << s;
169 (*_file_buffer) << val;
171 (*_file_buffer) <<
"NULL";
187 (*_file_buffer) << val;
189 (*_file_buffer) <<
"NULL";
202 (*_file_buffer) << val;
215 (*_file_buffer) << val;
228 (*_file_buffer) << val;
241 (*_file_buffer) << val;
254 (*_file_buffer) << val;
269 (*_file_buffer) << val;
283 if (!_suspended) (*_file_buffer) << val;
296 strm << BESIndent::LMarg <<
"BESLog::dump - (" << (
void *)
this <<
")" << endl;
298 strm << BESIndent::LMarg <<
"log file: " << _file_name << endl;
299 if (_file_buffer && *_file_buffer) {
300 strm << BESIndent::LMarg <<
"log is valid" << endl;
303 strm << BESIndent::LMarg <<
"log is NOT valid" << endl;
305 strm << BESIndent::LMarg <<
"is verbose: " << _verbose << endl;
306 strm << BESIndent::LMarg <<
"is flushed: " << _flushed << endl;
307 strm << BESIndent::LMarg <<
"is suspended: " << _suspended << endl;
308 BESIndent::UnIndent();
314 if (_instance == 0) {
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.
virtual void dump(std::ostream &strm) const
dumps information about this object
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 get_value(const string &s, string &val, bool &found)
Retrieve the value of a given key, if set.
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.
std::ios &(* p_ios_manipulator)(std::ios &)
Defines a data type p_ios_manipulator "pointer to function that takes ios& and returns ios&"...
static BESKeys * TheKeys()