kNCurses/Debug.hpp

52 lines
1.1 KiB
C++

/**
* @brief Writes messages to `debug.log` if `NDEBUG` is not defined.
* @author Christian Burger (christian@krikkel.de)
*/
#ifndef __DEBUG_H__
#define __DEBUG_H__
#ifndef NDEBUG
#include <fstream>
#include <string>
#include <ctime>
namespace krikkel
{
using std::fstream;
using std::string;
using std::endl;
using std::strftime;
using std::localtime;
using std::time;
class Debug
{
private:
fstream logFile;
static const int MAX_NUMBER_OF_SYSCALLS = 1024;
static const char * syscalls[MAX_NUMBER_OF_SYSCALLS];
Debug();
string getTimestamp();
string getUname();
public:
void log(string message, string fileName, int lineNo
, string functionName);
static Debug *getInstance();
};
}
#define __debug_log(message) krikkel::Debug::getInstance()\
->log(message, __FILE__, __LINE__, __func__)
#else
/// @todo check what's the business with this "((void)0)" instead of empty macro
#define __debug_log(message)
#endif /* NDEBUG */
#endif // __DEBUG_H__