46 using std::ostringstream;
52 ostream *BESDebug::_debug_strm = NULL;
53 bool BESDebug::_debug_strm_created =
false;
54 map<string, bool> BESDebug::_debug_map;
72 string err =
"Empty debug options";
75 string::size_type comma = 0;
76 comma = values.find(
',');
77 if (comma == string::npos)
79 string err =
"Missing comma in debug options: " + values;
84 string s_strm = values.substr(0, comma);
89 else if (s_strm ==
"LOG")
95 strm =
new ofstream(s_strm.c_str(), ios::out);
100 string err =
"Unable to open the debug file: " + s_strm;
108 string::size_type new_comma = 0;
109 while ((new_comma = values.find(
',', comma + 1)) != string::npos)
111 string flagName = values.substr(comma + 1, new_comma - comma - 1);
112 if (flagName[0] ==
'-')
114 string newflag = flagName.substr(1, flagName.length() - 1);
123 string flagName = values.substr(comma + 1, values.length() - comma - 1);
124 if (flagName[0] ==
'-')
126 string newflag = flagName.substr(1, flagName.length() - 1);
142 const time_t sctime = time(NULL);
143 const struct tm *sttime = localtime(&sctime);
145 strftime(zone_name,
sizeof(zone_name),
"%Z", sttime);
146 char *b = asctime(sttime);
147 strm << zone_name <<
" ";
148 for (
register int j = 0; b[j] !=
'\n'; j++)
150 pid_t thepid = getpid();
151 strm <<
" id: " << thepid;
165 strm <<
"Debug help:" << endl <<
" Set on the command line with " <<
"-d \"file_name|cerr,[-]context1,...,[-]contextn\"" << endl
166 <<
" context with dash (-) in front will be turned off" << endl <<
" context of all will turn on debugging for all contexts" << endl << endl
167 <<
"Possible context(s):" << endl;
169 if (_debug_map.size())
175 strm <<
" " << (*i).first <<
": ";
177 strm <<
"on" << endl;
179 strm <<
"off" << endl;
184 strm <<
" none specified" << endl;
190 return _debug_map.count(name) > 0;
202 ostringstream oss(
"");
204 if (_debug_map.size())
212 oss << (*i).first <<
",";
214 string retval = oss.str();
215 return retval.erase(retval.length()-1);
exception thrown if inernal error encountered
static void SetUp(const string &values)
Sets up debugging for the bes.
static void Set(const string &flagName, bool value)
set the debug context to the specified value
static string GetPidStr()
return the pid as a string
static void Help(ostream &strm)
Writes help information for so that developers know what can be set for debugging.
static string GetOptionsString()
This method looks at the current setting of the BESDebug object and builds a string that...
DebugMap::const_iterator debug_citer
ostream * get_log_ostream()
static void SetStrm(ostream *strm, bool created)
set the debug output stream to the specified stream
static bool IsContextName(const string &name)