From 54546ce8b8ca863eb3f4024094cf012500d68683 Mon Sep 17 00:00:00 2001 From: brain Date: Wed, 9 Aug 2006 13:19:41 +0000 Subject: [PATCH] do_log -> static void InspIRCd::Log() (with vararg and std::string variants) The #define for this still exists, but maybe should be phased out? git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@4809 e03df62e-2008-0410-955e-edbf42e46eb7 --- include/helperfuncs.h | 2 +- include/inspircd.h | 4 +++- include/u_listmode.h | 1 + src/helperfuncs.cpp | 28 +++++++++++++++------------- src/modules/m_cgiirc.cpp | 1 + src/modules/m_operlog.cpp | 2 +- src/modules/m_remove.cpp | 1 + src/modules/m_testcommand.cpp | 1 + src/modules/m_watch.cpp | 1 + 9 files changed, 25 insertions(+), 16 deletions(-) diff --git a/include/helperfuncs.h b/include/helperfuncs.h index e094b1a0e..e5b563051 100644 --- a/include/helperfuncs.h +++ b/include/helperfuncs.h @@ -43,7 +43,7 @@ */ #define STRINGIFY2(x) #x #define STRINGIFY(x) STRINGIFY2(x) -#define log(l, x, args...) do_log(l, __FILE__ ":" STRINGIFY(__LINE__) ": " x, ##args) +#define log(l, x, args...) InspIRCd::Log(l, __FILE__ ":" STRINGIFY(__LINE__) ": " x, ##args) void do_log(int level, const char *text, ...); void readfile(file_cache &F, const char* fname); diff --git a/include/inspircd.h b/include/inspircd.h index 0b2a2830d..91d57f75d 100644 --- a/include/inspircd.h +++ b/include/inspircd.h @@ -43,7 +43,7 @@ */ #define IS_SINGLE(x,y) ( (*x == y) && (*(x+1) == 0) ) -#define DELETE(x) { do_log(DEBUG,"%s:%d: delete()",__FILE__,__LINE__); if (x) { delete x; x = NULL; } else log(DEBUG,"Attempt to delete NULL pointer!"); } +#define DELETE(x) { InspIRCd::Log(DEBUG,"%s:%d: delete()",__FILE__,__LINE__); if (x) { delete x; x = NULL; } else InspIRCd::Log(DEBUG,"Attempt to delete NULL pointer!"); } template inline std::string ConvToStr(const T &in) { @@ -114,6 +114,8 @@ class InspIRCd : public classbase bool UnloadModule(const char* filename); InspIRCd(int argc, char** argv); void DoOneIteration(bool process_module_sockets); + static void Log(int level, const char* text, ...); + static void Log(int level, const std::string &text); int Run(); }; diff --git a/include/u_listmode.h b/include/u_listmode.h index b3958caa2..45b04c158 100644 --- a/include/u_listmode.h +++ b/include/u_listmode.h @@ -9,6 +9,7 @@ #include "channels.h" #include "modules.h" #include "helperfuncs.h" +#include "inspircd.h" /* $ModDesc: Provides support for easily creating listmodes, stores the time set, the user, and a parameter. */ diff --git a/src/helperfuncs.cpp b/src/helperfuncs.cpp index b25370df6..97cb68f33 100644 --- a/src/helperfuncs.cpp +++ b/src/helperfuncs.cpp @@ -65,11 +65,20 @@ static time_t LAST = 0; * Write a line of text `text' to the logfile (and stdout, if in nofork) if the level `level' * is greater than the configured loglevel. */ -void do_log(int level, const char *text, ...) +void InspIRCd::Log(int level, const char* text, ...) { va_list argsPtr; char textbuffer[MAXBUF]; + va_start(argsPtr, text); + vsnprintf(textbuffer, MAXBUF, text, argsPtr); + va_end(argsPtr); + + InspIRCd::Log(level, std::string(textbuffer)); +} + +void InspIRCd::Log(int level, const std::string &text) +{ if (!ServerInstance || !ServerInstance->Config) return; @@ -86,22 +95,15 @@ void do_log(int level, const char *text, ...) LAST = TIME; } - if (ServerInstance->Config->log_file) + if (ServerInstance->Config->log_file && ServerInstance->Config->writelog) { - va_start(argsPtr, text); - vsnprintf(textbuffer, MAXBUF, text, argsPtr); - va_end(argsPtr); - - if (ServerInstance->Config->writelog) - { - fprintf(ServerInstance->Config->log_file,"%s %s\n",TIMESTR,textbuffer); - fflush(ServerInstance->Config->log_file); - } + fprintf(ServerInstance->Config->log_file,"%s %s\n",TIMESTR,text.c_str()); + fflush(ServerInstance->Config->log_file); } - + if (ServerInstance->Config->nofork) { - printf("%s %s\n", TIMESTR, textbuffer); + printf("%s %s\n", TIMESTR, text.c_str()); } } diff --git a/src/modules/m_cgiirc.cpp b/src/modules/m_cgiirc.cpp index 3a1bccaf7..4fcb0be13 100644 --- a/src/modules/m_cgiirc.cpp +++ b/src/modules/m_cgiirc.cpp @@ -25,6 +25,7 @@ #include "modules.h" #include "helperfuncs.h" #include "dns.h" +#include "inspircd.h" /* $ModDesc: Change user's hosts connecting from known CGI:IRC hosts */ diff --git a/src/modules/m_operlog.cpp b/src/modules/m_operlog.cpp index 8188c49b1..4881eefa0 100644 --- a/src/modules/m_operlog.cpp +++ b/src/modules/m_operlog.cpp @@ -20,7 +20,7 @@ using namespace std; #include "channels.h" #include "modules.h" #include "helperfuncs.h" -#include "message.h" +#include "inspircd.h" #include /* $ModDesc: A module which logs all oper commands to the ircd log at default loglevel. */ diff --git a/src/modules/m_remove.cpp b/src/modules/m_remove.cpp index a9c478a89..a5657f604 100644 --- a/src/modules/m_remove.cpp +++ b/src/modules/m_remove.cpp @@ -7,6 +7,7 @@ #include "channels.h" #include "modules.h" #include "helperfuncs.h" +#include "inspircd.h" /* $ModDesc: Provides a /remove command, this is mostly an alternative to /kick, except makes users appear to have parted the channel */ diff --git a/src/modules/m_testcommand.cpp b/src/modules/m_testcommand.cpp index 6f517e8ce..9b3509f8d 100644 --- a/src/modules/m_testcommand.cpp +++ b/src/modules/m_testcommand.cpp @@ -22,6 +22,7 @@ using namespace std; #include "modules.h" #include "helperfuncs.h" #include "dns.h" +#include "inspircd.h" /* $ModDesc: Povides a proof-of-concept test /WOOT command */ diff --git a/src/modules/m_watch.cpp b/src/modules/m_watch.cpp index 888827cfa..2ba9c9afb 100644 --- a/src/modules/m_watch.cpp +++ b/src/modules/m_watch.cpp @@ -24,6 +24,7 @@ using namespace std; #include "modules.h" #include "helperfuncs.h" #include "hashcomp.h" +#include "inspircd.h" /* $ModDesc: Provides support for the /watch command */ -- 2.39.5