Commit cf10a34d authored by miller86's avatar miller86

Making __FILE__/__LINE__ decoration of debug logs optional

git-svn-id: http://visit.ilight.com/svn/visit/trunk/src@27147 18c085ea-50e0-402c-830e-de6fd14e8384
parent 76e4efec
......@@ -59,7 +59,7 @@ namespace DebugStream
extern MISC_API bool Level5();
// Obtain a given level's stream object
extern MISC_API ostream& Stream1();
extern MISC_API ostream& Stream1(char const *__file__=0, int=-1);
extern MISC_API ostream& Stream2();
extern MISC_API ostream& Stream3();
extern MISC_API ostream& Stream4();
......@@ -69,7 +69,7 @@ namespace DebugStream
extern MISC_API int GetLevel();
}
#define debug1 if (!DebugStream::Level1()) ; else (DebugStream::Stream1()) << __FILE__ << ":" << __LINE__ << " "
#define debug1 if (!DebugStream::Level1()) ; else (DebugStream::Stream1((char const *)__FILE__,(int)__LINE__))
#define debug2 if (!DebugStream::Level2()) ; else (DebugStream::Stream2())
#define debug3 if (!DebugStream::Level3()) ; else (DebugStream::Stream3())
#define debug4 if (!DebugStream::Level4()) ; else (DebugStream::Stream4())
......
......@@ -71,7 +71,17 @@ bool DebugStream::Level3() { return debug3_realobj.isenabled(); };
bool DebugStream::Level4() { return debug4_realobj.isenabled(); };
bool DebugStream::Level5() { return debug5_realobj.isenabled(); };
ostream& DebugStream::Stream1() { return *((ostream*) &debug1_realobj); };
ostream& DebugStream::Stream1(char const *__file__, int __line__)
{
if (debug1_realobj.isdecorated() && __file__)
{
*((ostream*) &debug1_realobj) << __file__;
if (debug1_realobj.isdecorated() && __line__ > -1)
*((ostream*) &debug1_realobj) << ":" << __line__;
*((ostream*) &debug1_realobj) << " ";
}
return *((ostream*) &debug1_realobj);
};
ostream& DebugStream::Stream2() { return *((ostream*) &debug2_realobj); };
ostream& DebugStream::Stream3() { return *((ostream*) &debug3_realobj); };
ostream& DebugStream::Stream4() { return *((ostream*) &debug4_realobj); };
......@@ -472,6 +482,7 @@ DebugStreamFull::DebugStreamFull(int level_) : ostream(new DebugStreamBuf)
buf = (DebugStreamBuf*)(rdbuf());
buf->SetLevel(level);
enabled = false;
decorate = false;
}
......@@ -662,7 +673,7 @@ DebugStreamFull::close()
void
DebugStreamFull::Initialize(const char *progname, int debuglevel, bool sigs,
bool clobber, bool buffer_debug)
bool clobber, bool buffer_debug, bool _decorate)
{
switch (debuglevel)
{
......@@ -679,6 +690,7 @@ DebugStreamFull::Initialize(const char *progname, int debuglevel, bool sigs,
default:
break;
}
debug1_realobj.decorate = _decorate;
if (sigs)
{
......
......@@ -96,9 +96,10 @@ class MISC_API DebugStreamFull : public ostream
~DebugStreamFull();
bool isenabled() const { return enabled; };
bool isdecorated() const { return decorate; }
void open(const char *progname, bool, bool);
void close();
static void Initialize(const char *, int, bool=true, bool=false, bool=false);
static void Initialize(const char *, int, bool=true, bool=false, bool=false, bool=false);
private:
class DebugStreamBuf : public streambuf
{
......@@ -134,6 +135,8 @@ class MISC_API DebugStreamFull : public ostream
int level;
// true if enabled
bool enabled;
// true if output should be decorated with __FILE__ and __LINE__
bool decorate;
};
#endif
......@@ -237,6 +237,10 @@ NewHandler(void)
// Tom Fogal, Wed Sep 28 13:40:21 MDT 2011
// Fix a UMR that valgrind complained about.
//
// Mark C. Miller, Thu Sep 10 11:07:15 PDT 2015
// Added logic to manage decoration of level 1 debug logs with __FILE__
// and __LINE__; an extra 'd' in debug level arg will turn on these log
// decorations.
// ****************************************************************************
void
......@@ -254,6 +258,7 @@ VisItInit::Initialize(int &argc, char *argv[], int r, int n, bool strip, bool si
bool usePid = false;
#endif
bool bufferDebug = false;
bool decorateDebug1 = false;
bool clobberVlogs = false;
bool vtk_debug = false;
bool enableTimings = false;
......@@ -306,8 +311,10 @@ VisItInit::Initialize(int &argc, char *argv[], int r, int n, bool strip, bool si
cerr << "Warning: clamping debug level to 0\n";
debuglevel = 0;
}
if (i+1 < argc && *(argv[i+1]+1) == 'b')
if (i+1 < argc && strchr(argv[i+1],'b'))
bufferDebug = true;
if (i+1 < argc && strchr(argv[i+1],'d'))
decorateDebug1 = true;
if(strip)
{
......@@ -420,7 +427,8 @@ VisItInit::Initialize(int &argc, char *argv[], int r, int n, bool strip, bool si
// Initialize the debug streams and also add the command line arguments
// to the debug logs.
DebugStreamFull::Initialize(progname, debuglevel, sigs, clobberVlogs, bufferDebug);
DebugStreamFull::Initialize(progname, debuglevel, sigs, clobberVlogs,
bufferDebug, decorateDebug1);
ostringstream oss;
for(i = 0; i < argc; ++i)
oss << argv[i] << " ";
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment