46 using std::ostringstream ;
51 ostream *BESDebug::_debug_strm = NULL ;
52 bool BESDebug::_debug_strm_created = false ;
53 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 ;
83 bool created = false ;
84 string s_strm = values.substr( 0, comma ) ;
85 if( s_strm ==
"cerr" )
91 strm =
new ofstream( s_strm.c_str(), ios::out ) ;
92 if( strm && !(*strm) )
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 ) ;
139 const time_t sctime = time( NULL ) ;
140 const struct tm *sttime = localtime( &sctime ) ;
142 strftime( zone_name,
sizeof( zone_name ),
"%Z", sttime ) ;
143 char *b = asctime( sttime ) ;
144 strm << zone_name <<
" " ;
145 for(
register int j = 0; b[j] !=
'\n'; j++ )
147 pid_t thepid = getpid() ;
148 strm <<
" id: " << thepid ;
163 strm <<
"Debug help:" << endl
164 <<
" Set on the command line with " 165 <<
"-d \"file_name|cerr,[-]context1,...,[-]contextn\"" << endl
166 <<
" context with dash (-) in front will be turned off" << endl
167 <<
" context of all will turn on debugging for all context" << endl
169 <<
"Possible context:" << endl ;
171 if( _debug_map.size() )
173 BESDebug::_debug_citer i = _debug_map.begin() ;
174 BESDebug::_debug_citer e = _debug_map.end() ;
177 strm <<
" " << (*i).first <<
": " ;
179 strm <<
"on" << endl ;
181 strm <<
"off" << endl ;
186 strm <<
" none specified" << endl ;
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 void SetStrm(ostream *strm, bool created)
set the debug output stream to the specified stream