Move DEBUG() from Utils.h into new ZNCDebug.h

Signed-off-by: Uli Schlachter <psychon@znc.in>
This commit is contained in:
Uli Schlachter
2011-04-03 10:41:27 +02:00
parent 0e0ab34773
commit ac5c021c93
9 changed files with 81 additions and 50 deletions
+1 -1
View File
@@ -31,7 +31,7 @@ INSTALL_DATA := @INSTALL_DATA@
LIB_SRCS := ZNCString.cpp Csocket.cpp znc.cpp User.cpp IRCSock.cpp Client.cpp DCCBounce.cpp \
DCCSock.cpp Chan.cpp Nick.cpp Server.cpp Modules.cpp MD5.cpp Buffer.cpp Utils.cpp \
FileUtils.cpp HTTPSock.cpp Template.cpp ClientCommand.cpp Socket.cpp SHA256.cpp \
WebModules.cpp Listener.cpp Config.cpp
WebModules.cpp Listener.cpp Config.cpp ZNCDebug.cpp
BIN_SRCS := main.cpp
LIB_OBJS := $(patsubst %cpp,%o,$(LIB_SRCS))
BIN_OBJS := $(patsubst %cpp,%o,$(BIN_SRCS))
+1 -1
View File
@@ -11,7 +11,7 @@
#include "zncconfig.h"
#include "WebModules.h"
#include "Utils.h"
#include "main.h"
#include <set>
#include <queue>
+6 -13
View File
@@ -9,6 +9,7 @@
#include "Utils.h"
#include "MD5.h"
#include "main.h"
#include "ZNCDebug.h"
#include <errno.h>
#ifdef HAVE_LIBSSL
#include <openssl/ssl.h>
@@ -24,14 +25,6 @@
using std::stringstream;
bool CUtils::stdoutIsTTY = true;
bool CUtils::debug =
#ifdef _DEBUG
true;
#else
false;
#endif
CUtils::CUtils() {}
CUtils::~CUtils() {}
@@ -271,7 +264,7 @@ bool CUtils::GetInput(const CString& sPrompt, CString& sRet, const CString& sDef
}
void CUtils::PrintError(const CString& sMessage) {
if (stdoutIsTTY)
if (CDebug::StdoutIsTTY())
fprintf(stdout, "\033[1m\033[34m[\033[31m ** \033[34m]\033[39m\033[22m %s\n", sMessage.c_str());
else
fprintf(stdout, "%s\n", sMessage.c_str());
@@ -279,7 +272,7 @@ void CUtils::PrintError(const CString& sMessage) {
}
void CUtils::PrintPrompt(const CString& sMessage) {
if (stdoutIsTTY)
if (CDebug::StdoutIsTTY())
fprintf(stdout, "\033[1m\033[34m[\033[33m ?? \033[34m]\033[39m\033[22m %s: ", sMessage.c_str());
else
fprintf(stdout, "[ ?? ] %s: ", sMessage.c_str());
@@ -287,7 +280,7 @@ void CUtils::PrintPrompt(const CString& sMessage) {
}
void CUtils::PrintMessage(const CString& sMessage, bool bStrong) {
if (stdoutIsTTY) {
if (CDebug::StdoutIsTTY()) {
if (bStrong)
fprintf(stdout, "\033[1m\033[34m[\033[33m ** \033[34m]\033[39m\033[22m \033[1m%s\033[22m\n",
sMessage.c_str());
@@ -301,7 +294,7 @@ void CUtils::PrintMessage(const CString& sMessage, bool bStrong) {
}
void CUtils::PrintAction(const CString& sMessage) {
if (stdoutIsTTY)
if (CDebug::StdoutIsTTY())
fprintf(stdout, "\033[1m\033[34m[\033[32m \033[34m]\033[39m\033[22m %s... ", sMessage.c_str());
else
fprintf(stdout, "%s... ", sMessage.c_str());
@@ -309,7 +302,7 @@ void CUtils::PrintAction(const CString& sMessage) {
}
void CUtils::PrintStatus(bool bSuccess, const CString& sMessage) {
if (stdoutIsTTY) {
if (CDebug::StdoutIsTTY()) {
if (!sMessage.empty()) {
if (bSuccess) {
fprintf(stdout, "%s", sMessage.c_str());
-26
View File
@@ -19,30 +19,10 @@
#include <sys/time.h>
#include <unistd.h>
#include <vector>
#include <iostream>
using std::map;
using std::vector;
using std::pair;
using std::cout;
using std::endl;
/** Output a debug info if debugging is enabled.
* If ZNC was compiled with <code>--enable-debug</code> or was started with
* <code>--debug</code>, the given argument will be sent to stdout.
*
* You can use all the features of C++ streams:
* @code
* DEBUG("I had " << errors << " errors");
* @endcode
*
* @param f The expression you want to display.
*/
#define DEBUG(f) do { \
if (CUtils::Debug()) { \
cout << f << endl; \
} \
} while (0)
static inline void SetFdCloseOnExec(int fd)
{
@@ -62,10 +42,6 @@ public:
static CString GetIP(unsigned long addr);
static unsigned long GetLongIP(const CString& sIP);
static void SetStdoutIsTTY(bool b) { stdoutIsTTY = b; }
static bool StdoutIsTTY() { return stdoutIsTTY; }
static void SetDebug(bool b) { debug = b; }
static bool Debug() { return debug; }
static void PrintError(const CString& sMessage);
static void PrintMessage(const CString& sMessage, bool bStrong = false);
@@ -99,8 +75,6 @@ public:
private:
protected:
static bool stdoutIsTTY;
static bool debug;
};
class CException {
+17
View File
@@ -0,0 +1,17 @@
/*
* Copyright (C) 2004-2011 See the AUTHORS file for details.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 as published
* by the Free Software Foundation.
*/
#include "ZNCDebug.h"
bool CDebug::stdoutIsTTY = true;
bool CDebug::debug =
#ifdef _DEBUG
true;
#else
false;
#endif
+46
View File
@@ -0,0 +1,46 @@
/*
* Copyright (C) 2004-2011 See the AUTHORS file for details.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 as published
* by the Free Software Foundation.
*/
#ifndef ZNCDEBUG_H
#define ZNCDEBUG_H
#include <iostream>
using std::cout;
using std::endl;
/** Output a debug info if debugging is enabled.
* If ZNC was compiled with <code>--enable-debug</code> or was started with
* <code>--debug</code>, the given argument will be sent to stdout.
*
* You can use all the features of C++ streams:
* @code
* DEBUG("I had " << errors << " errors");
* @endcode
*
* @param f The expression you want to display.
*/
#define DEBUG(f) do { \
if (CDebug::Debug()) { \
cout << f << endl; \
} \
} while (0)
class CDebug {
public:
static void SetStdoutIsTTY(bool b) { stdoutIsTTY = b; }
static bool StdoutIsTTY() { return stdoutIsTTY; }
static void SetDebug(bool b) { debug = b; }
static bool Debug() { return debug; }
protected:
static bool stdoutIsTTY;
static bool debug;
};
#endif // !ZNCDEBUG_H
+2 -1
View File
@@ -13,7 +13,8 @@
// This header file is just for Csocket
#include "Utils.h"
#include "ZNCDebug.h"
#include "ZNCString.h"
#define CS_STRING CString
#define _NO_CSOCKET_NS
+6 -6
View File
@@ -117,7 +117,7 @@ int main(int argc, char** argv) {
CString sDataDir = "";
seedPRNG();
CUtils::SetStdoutIsTTY(isatty(1));
CDebug::SetStdoutIsTTY(isatty(1));
int iArg, iOptIndex = -1;
bool bMakeConf = false;
@@ -142,7 +142,7 @@ int main(int argc, char** argv) {
cout << CZNC::GetTag() << endl;
return 0;
case 'n':
CUtils::SetStdoutIsTTY(false);
CDebug::SetStdoutIsTTY(false);
break;
case 'r':
bAllowRoot = true;
@@ -166,7 +166,7 @@ int main(int argc, char** argv) {
break;
case 'D':
bForeground = true;
CUtils::SetDebug(true);
CDebug::SetDebug(true);
break;
case '?':
default:
@@ -285,7 +285,7 @@ int main(int argc, char** argv) {
close(1); open("/dev/null", O_WRONLY);
close(2); open("/dev/null", O_WRONLY);
CUtils::SetStdoutIsTTY(false);
CDebug::SetStdoutIsTTY(false);
// We are the child. There is no way we can be a process group
// leader, thus setsid() must succeed.
@@ -334,11 +334,11 @@ int main(int argc, char** argv) {
NULL
};
int pos = 3;
if (CUtils::Debug())
if (CDebug::Debug())
args[pos++] = strdup("--debug");
else if (bForeground)
args[pos++] = strdup("--foreground");
if (!CUtils::StdoutIsTTY())
if (!CDebug::StdoutIsTTY())
args[pos++] = strdup("--no-color");
if (bAllowRoot)
args[pos++] = strdup("--allow-root");
+2 -2
View File
@@ -677,7 +677,7 @@ bool CZNC::WriteNewConfig(const CString& sConfigFile) {
const CModInfo& Info = *it;
CString sName = Info.GetName();
if (CUtils::StdoutIsTTY()) {
if (CDebug::StdoutIsTTY()) {
if (CUtils::GetBoolInput("Load global module <\033[1m" + sName + "\033[22m>?", false))
vsLines.push_back("LoadModule = " + sName);
} else {
@@ -783,7 +783,7 @@ bool CZNC::WriteNewConfig(const CString& sConfigFile) {
const CModInfo& Info = *it;
CString sName = Info.GetName();
if (CUtils::StdoutIsTTY()) {
if (CDebug::StdoutIsTTY()) {
if (CUtils::GetBoolInput("Load module <\033[1m" + sName + "\033[22m>?", false))
vsLines.push_back("\tLoadModule = " + sName);
} else {