43 #include "BESInternalError.h"
48 ostream *BESDebug::_debug_strm = NULL;
49 bool BESDebug::_debug_strm_created =
false;
50 map<string, bool> BESDebug::_debug_map;
67 string err =
"Empty debug options";
70 string::size_type comma = 0;
71 comma = values.find(
',');
72 if (comma == string::npos) {
73 string err =
"Missing comma in debug options: " + values;
78 string s_strm = values.substr(0, comma);
79 if (s_strm ==
"cerr") {
82 else if (s_strm ==
"LOG") {
83 strm = BESLog::TheLog()->get_log_ostream();
86 strm =
new ofstream(s_strm.c_str(), ios::out);
87 if (strm && !(*strm)) {
90 string err =
"Unable to open the debug file: " + s_strm;
98 string::size_type new_comma = 0;
99 while ((new_comma = values.find(
',', comma + 1)) != string::npos) {
100 string flagName = values.substr(comma + 1, new_comma - comma - 1);
101 if (flagName[0] ==
'-') {
102 string newflag = flagName.substr(1, flagName.length() - 1);
110 string flagName = values.substr(comma + 1, values.length() - comma - 1);
111 if (flagName[0] ==
'-') {
112 string newflag = flagName.substr(1, flagName.length() - 1);
127 const time_t sctime = time(NULL);
128 const struct tm *sttime = localtime(&sctime);
130 strftime(zone_name,
sizeof(zone_name),
"%Z", sttime);
131 char *b = asctime(sttime);
132 strm << zone_name <<
" ";
133 for (
register int j = 0; b[j] !=
'\n'; j++)
135 pid_t thepid = getpid();
136 strm <<
" id: " << thepid;
150 strm <<
"Debug help:" << endl <<
" Set on the command line with " <<
"-d \"file_name|cerr,[-]context1,...,[-]context\"" << endl
151 <<
" context with dash (-) in front will be turned off" << endl <<
" context of all will turn on debugging for all contexts" << endl << endl
152 <<
"Possible context(s):" << endl;
154 if (_debug_map.size()) {
155 BESDebug::debug_citer i = _debug_map.begin();
156 BESDebug::debug_citer e = _debug_map.end();
157 for (; i != e; i++) {
158 strm <<
" " << (*i).first <<
": ";
160 strm <<
"on" << endl;
162 strm <<
"off" << endl;
166 strm <<
" none specified" << endl;
170 bool BESDebug::IsContextName(
const string &name)
172 return _debug_map.count(name) > 0;
186 if (_debug_map.size()) {
187 BESDebug::debug_citer i = _debug_map.begin();
188 BESDebug::debug_citer e = _debug_map.end();
189 for (; i != e; i++) {
190 if (!(*i).second) oss <<
"-";
191 oss << (*i).first <<
",";
193 string retval = oss.str();
194 return retval.erase(retval.length() - 1);