Nov 6, 2013 at 2:40am UTC
so i wrote the debugging part of my library and i was just wondering any improvements i could make to it?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
#include <iostream>
#include <string>
#include <cstdlib>
using std:: cout;
using std:: cerr;
using std:: endl;
using std::string;
using std:: exit;
namespace Debug
{
bool Log(int Line, string File)
{
static int Current = 1;
cout<< File <<": Log (" << Current++ <<") @ Line: " << Line << endl;
return true ;
}
void Error(int Line, string Message, bool Fatal = false )
{
if (!Fatal) CacheError("error on line " + string(Line) + ": " + Error);
else
{
CacheError("fatal error on line " + string(Line) + ": " + Error);
cerr<< CacheError(true );
exit(-1);
}
}
string CacheError(string Message = "" , bool Flush = false )
{
static string Log = "" ;
if (Flush) return Log;
else Log += Message + "\n" ;
}
}
with the exception of Log::Log (which i will call when i need to do some minor testing and dont feel like powering on the debugger) Error and as a result CacheError will only get called when an exception is caught
edit: i had the wrong namespace name
Last edited on Nov 6, 2013 at 2:41am UTC
Nov 6, 2013 at 2:43am UTC
There is a difference between logging and debugging. You shouldn't have to write code to enable debugging, your debugger should do that for you.
Nov 6, 2013 at 2:45am UTC
im not using an ide and i dont like gdb so i would have to use the debugger i have. i use the logger to find the bugs and then fix them
Nov 6, 2013 at 2:51am UTC
Have you seen StackWalker on CodeProject? Really awesome. I use it at work to find the sources of exceptions (because of various reasons, I can't simply break on all exceptions when they're thrown, so the debugger is no help on this).
Nov 6, 2013 at 2:55am UTC
ill look at it. is it only windows (because i know code Projects is very windows heavy)
Nov 6, 2013 at 3:56am UTC
i could be wrong but i was looking at the source for the class and saw a bunch of windows.h data types
Nov 6, 2013 at 4:16am UTC
What did you think helios meant by "yes"?
Nov 6, 2013 at 4:17am UTC
Which is why I said that as far as I know it's only for Windows.
Nov 6, 2013 at 4:18am UTC
i incorrectly remembered what i asked him. for some reason i thought i asked if it was cross platform