Commit 937301dc authored by Pavel Vainerman's avatar Pavel Vainerman

[debug-logs]: cleanup

parent b4e2b120
......@@ -13,21 +13,13 @@
#ifndef LYXDEBUG_H
#define LYXDEBUG_H
//#ifdef __GNUG__
//#pragma interface
//#endif
#if __GNUC__ > 2
#define MODERN_STL_STREAMS
#endif
#include <iosfwd>
#include <string>
//#include <lstrings.h>
//#ifndef _
// #define _(n) n
//#endif
/** Ideally this should have been a namespace, but since we try to be
......@@ -111,10 +103,7 @@ void operator|=(Debug::type& d1, Debug::type d2) noexcept
d1 = static_cast<Debug::type>(d1 | d2);
}
#include "DebugStream.h"
std::ostream& operator<<(std::ostream& o, Debug::type t) noexcept;
//extern DebugStream ulog;
#include "DebugStream.h"
#endif
......@@ -15,43 +15,12 @@
#ifndef DEBUGSTREAM_H
#define DEBUGSTREAM_H
//#ifdef __GNUG__
//#pragma interface
//#endif
#include <iostream>
#include <string>
#include <sigc++/sigc++.h>
#include <vector>
#include "Debug.h"
#ifdef TEST_DEBUGSTREAM
#include <string>
struct Debug
{
enum type
{
NONE = 0,
INFO = (1 << 0), // 1
WARN = (1 << 1), // 2
CRIT = (1 << 2) // 4
};
static const type ANY = type(INFO | WARN | CRIT);
static Debug::type value(std::string const& val)
{
if (val == "NONE") return Debug::NONE;
if (val == "INFO") return Debug::INFO;
if (val == "WARN") return Debug::WARN;
if (val == "CRIT") return Debug::CRIT;
return Debug::NONE;
}
};
#endif
/** DebugStream is a ostream intended for debug output.
It has also support for a logfile. Debug output is output to cerr
and if the logfile is set, to the logfile.
......
......@@ -8,10 +8,6 @@
* ====================================================== */
// (c) 2002 adapted for UniSet by Lav, GNU LGPL license
#ifdef __GNUG__
#pragma implementation
#endif
#include <iomanip>
#include <sstream>
......
......@@ -7,13 +7,6 @@
// (c) 2002 adapted for UniSet by Lav, GNU LGPL license
//#define TEST_DEBUGSTREAM
#ifdef __GNUG__
#pragma implementation
#endif
//#include "DebugStream.h"
#include "Debug.h"
#include "Mutex.h"
......@@ -340,99 +333,3 @@ std::vector<DebugStream::Label> DebugStream::getLabels() noexcept
return labels;
}
//--------------------------------------------------------------------------
//--------------------------------------------------------------------------
#ifdef TEST_DEBUGSTREAM
// Example debug stream
DebugStream debugstream;
int main(int, char**)
{
/**
I have been running some tests on this to see how much overhead
this kind of permanent debug code has. My conclusion is: not
much. In all, but the most time critical code, this will have
close to no impact at all.
In the tests that I have run the use of
if (debugstream.debugging(DebugStream::INFO))
debugstream << "some debug\n";
has close to no overhead when the debug level is not
DebugStream::INFO.
The overhead for
debugstream.debug(DebugStream::INFO) << "some debug\n";
is also very small when the debug level is not
DebugStream::INFO. However the overhead for this will increase
if complex debugging information is output.
The overhead when the debug level is DebugStream::INFO can be
significant, but since we then are running in debug mode it is
of no concern.
Why should we use this instead of the class Error that we already
have? First of all it uses C++ iostream and constructs, secondly
it will be a lot easier to output the debug info that we need
without a lot of manual conversions, thirdly we can now use
iomanipulators and the complete iostream formatting functions.
pluss it will work for all types that have a operator<<
defined, and can be used in functors that take a ostream & as
parameter. And there should be less need for temporary objects.
And one nice bonus is that we get a log file almost for
free.
Some of the names are of course open to modifications. I will try
to use the names we already use in LyX.
*/
// Just a few simple debugs to show how it can work.
debugstream << "Debug level set to Debug::NONE\n";
if (debugstream.debugging())
{
debugstream << "Something must be debugged\n";
}
debugstream.debug(Debug::WARN) << "more debug(WARN)\n";
debugstream.debug(Debug::INFO) << "even more debug(INFO)\n";
debugstream.debug(Debug::CRIT) << "even more debug(CRIT)\n";
debugstream.level(Debug::value("INFO"));
debugstream << "Setting debug level to Debug::INFO\n";
if (debugstream.debugging())
{
debugstream << "Something must be debugged\n";
}
debugstream.debug(Debug::WARN) << "more debug(WARN)\n";
debugstream.debug(Debug::INFO) << "even more debug(INFO)\n";
debugstream.debug(Debug::CRIT) << "even more debug(CRIT)\n";
debugstream.addLevel(Debug::type(Debug::CRIT |
Debug::WARN));
debugstream << "Adding Debug::CRIT and Debug::WARN\n";
debugstream[Debug::WARN] << "more debug(WARN)\n";
debugstream[Debug::INFO] << "even more debug(INFO)\n";
debugstream[Debug::CRIT] << "even more debug(CRIT)\n";
debugstream.delLevel(Debug::INFO);
debugstream << "Removing Debug::INFO\n";
debugstream[Debug::WARN] << "more debug(WARN)\n";
debugstream[Debug::INFO] << "even more debug(INFO)\n";
debugstream[Debug::CRIT] << "even more debug(CRIT)\n";
debugstream.logFile("logfile");
debugstream << "Setting logfile to \"logfile\"\n";
debugstream << "Value: " << 123 << " " << "12\n";
int i = 0;
int* p = new int;
// note: the (void*) is needed on g++ 2.7.x since it does not
// support partial specialization. In egcs this should not be
// needed.
debugstream << "automatic " << &i
<< ", free store " << p << endl;
delete p;
/*
for (int j = 0; j < 200000; ++j) {
DebugStream tmp;
tmp << "Test" << endl;
}
*/
}
#endif
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