43 #include "BESInternalError.h" 48 ostream *BESDebug::_debug_strm = NULL;
49 bool BESDebug::_debug_strm_created =
false;
50 map<string, bool> BESDebug::_debug_map;
68 string err =
"Empty debug options";
71 string::size_type comma = 0;
72 comma = values.find(
',');
73 if (comma == string::npos)
75 string err =
"Missing comma in debug options: " + values;
80 string s_strm = values.substr(0, comma);
85 else if (s_strm ==
"LOG")
87 strm = BESLog::TheLog()->get_log_ostream();
91 strm =
new ofstream(s_strm.c_str(), ios::out);
96 string err =
"Unable to open the debug file: " + s_strm;
104 string::size_type new_comma = 0;
105 while ((new_comma = values.find(
',', comma + 1)) != string::npos)
107 string flagName = values.substr(comma + 1, new_comma - comma - 1);
108 if (flagName[0] ==
'-')
110 string newflag = flagName.substr(1, flagName.length() - 1);
119 string flagName = values.substr(comma + 1, values.length() - comma - 1);
120 if (flagName[0] ==
'-')
122 string newflag = flagName.substr(1, flagName.length() - 1);
138 const time_t sctime = time(NULL);
139 const struct tm *sttime = localtime(&sctime);
141 strftime(zone_name,
sizeof(zone_name),
"%Z", sttime);
142 char *b = asctime(sttime);
143 strm << zone_name <<
" ";
144 for (
register int j = 0; b[j] !=
'\n'; j++)
146 pid_t thepid = getpid();
147 strm <<
" id: " << thepid;
161 strm <<
"Debug help:" << endl <<
" Set on the command line with " <<
"-d \"file_name|cerr,[-]context1,...,[-]context\"" << endl
162 <<
" context with dash (-) in front will be turned off" << endl <<
" context of all will turn on debugging for all contexts" << endl << endl
163 <<
"Possible context(s):" << endl;
165 if (_debug_map.size())
167 BESDebug::debug_citer i = _debug_map.begin();
168 BESDebug::debug_citer e = _debug_map.end();
171 strm <<
" " << (*i).first <<
": ";
173 strm <<
"on" << endl;
175 strm <<
"off" << endl;
180 strm <<
" none specified" << endl;
184 bool BESDebug::IsContextName(
const string &name)
186 return _debug_map.count(name) > 0;
198 ostringstream oss(
"");
200 if (_debug_map.size())
202 BESDebug::debug_citer i = _debug_map.begin();
203 BESDebug::debug_citer e = _debug_map.end();
208 oss << (*i).first <<
",";
210 string retval = oss.str();
211 return retval.erase(retval.length()-1);
exception thrown if inernal error encountered
static std::string GetPidStr()
return the pid as a string
static void SetUp(const std::string &values)
Sets up debugging for the bes.
static void Set(const std::string &flagName, bool value)
set the debug context to the specified value
static std::string GetOptionsString()
static void Help(std::ostream &strm)
Writes help information for so that developers know what can be set for debugging.
static void SetStrm(std::ostream *strm, bool created)
set the debug output stream to the specified stream