45 #include "BESInternalError.h"
50 ostream *BESDebug::_debug_strm = NULL;
51 bool BESDebug::_debug_strm_created =
false;
52 map<string, bool> BESDebug::_debug_map;
59 string get_debug_log_line_prefix()
63 const time_t sctime = time(NULL);
64 const struct tm *sttime = localtime(&sctime);
66 strftime(zone_name,
sizeof(zone_name),
"%Z", sttime);
70 strm <<
"[" << zone_name <<
" ";
71 for (
size_t j = 0; b[j] !=
'\n' && j<32; j++)
76 pid_t thepid = getpid();
77 strm <<
"[pid:" << thepid <<
"]";
80 strm <<
"[thread:" << pthread_self() <<
"]";
100 string err =
"Empty debug options";
103 string::size_type comma = 0;
104 comma = values.find(
',');
105 if (comma == string::npos) {
106 string err =
"Missing comma in debug options: " + values;
110 bool created =
false;
111 string s_strm = values.substr(0, comma);
112 if (s_strm ==
"cerr") {
115 else if (s_strm ==
"LOG") {
116 strm = BESLog::TheLog()->get_log_ostream();
119 strm =
new ofstream(s_strm.c_str(), ios::out);
120 if (strm && strm->fail()) {
123 string err =
"Unable to open the debug file: " + s_strm;
131 string::size_type new_comma = 0;
132 while ((new_comma = values.find(
',', comma + 1)) != string::npos) {
133 string flagName = values.substr(comma + 1, new_comma - comma - 1);
134 if (flagName[0] ==
'-') {
135 string newflag = flagName.substr(1, flagName.length() - 1);
143 string flagName = values.substr(comma + 1, values.length() - comma - 1);
144 if (flagName[0] ==
'-') {
145 string newflag = flagName.substr(1, flagName.length() - 1);
163 strm <<
"Debug help:" << endl <<
" Set on the command line with " <<
"-d \"file_name|cerr,[-]context1,...,[-]context\"" << endl
164 <<
" context with dash (-) in front will be turned off" << endl <<
" context of all will turn on debugging for all contexts" << endl << endl
165 <<
"Possible context(s):" << endl;
167 if (_debug_map.size()) {
168 BESDebug::debug_citer i = _debug_map.begin();
169 BESDebug::debug_citer e = _debug_map.end();
170 for (; i != e; i++) {
171 strm <<
" " << (*i).first <<
": ";
173 strm <<
"on" << endl;
175 strm <<
"off" << endl;
179 strm <<
" none specified" << endl;
183 bool BESDebug::IsContextName(
const string &name)
185 return _debug_map.count(name) > 0;
199 if (_debug_map.size()) {
200 BESDebug::debug_citer i = _debug_map.begin();
201 BESDebug::debug_citer e = _debug_map.end();
202 for (; i != e; i++) {
203 if (!(*i).second) oss <<
"-";
204 oss << (*i).first <<
",";
206 string retval = oss.str();
207 return retval.erase(retval.length() - 1);
static void SetStrm(std::ostream *strm, bool created)
set the debug output stream to the specified stream
static void SetUp(const std::string &values)
Sets up debugging for the bes.
static void Help(std::ostream &strm)
Writes help information for so that developers know what can be set for debugging.
static std::string GetOptionsString()
static void Set(const std::string &flagName, bool value)
set the debug context to the specified value
exception thrown if internal error encountered