|
Commandline Parsing and Enabling |
Top Previous Next |
|
In order to make it easier for you to enable commandline configuration of logging functions, JrDebugLogger provides a helper commandline parser function. When invoked it will scan the commandline for specific arguments and. if found, use them to enable or disable debugging; any arguments found will be removed from your argc and argv variables so that your program can parse the rest of the commandline arguments as per normal.
Invoke the commandline parser helper function from your main() function as follows: JrDebug::GrabCommandlineDebugFile(int &argc,char **argv,bool disableifnofile=false, bool donthangeargcv=false)
The function returns true if debugging was enabled through the commandline.
The call will look for parameter(s) of the form '-dbf [filename]' on the commandline (and strip them if found, modifying argc), and then enable debugging and writes output to the file specified (or "jrdebugout.log" by default). Pass a 3rd parameter of true to this function to disable logging if parameter not found, the most common situation. In this way, your program will run without debugging unless -dbf is passed on the commandline:
int main(int argc, char *argv[]) { // automatically enable if -dbc or -dbf parameters on commandline; disable if not JrDebug::GrabCommandlineDebugFile(argc,argv,true); }
Invoke like: demo1.exe -dbf mylogfile.log
Options: -db enable debug logging -dbc enable debug logging to stdout console -dbf [filename] enable debug logging to file -dbb enable brief mode debug logging -dbd disable debug logging
IMPORTANT NOTE:
You can also call a simpler commandline initialization function that doesn't use argc and argv: JrDebug::ParseCommandlineArgString("commandline args as one long string",fullpathofexe|NULL,bool &foundcommandlineargs);
ex: JrDebug::ParseCommandlineArgString("-dbo text;debugout.txt",NULL,false); |