From 73f478b15a61946b2c78843b968ba69b95551c09 Mon Sep 17 00:00:00 2001 From: Maxim Mamontov Date: Thu, 2 Aug 2012 15:31:53 +0300 Subject: [PATCH 1/1] Introduced logger for plugins. --- projects/rscriptd/rscriptd.conf | 8 ++-- .../stargazer/plugins/authorization/ao/ao.cpp | 3 +- .../stargazer/plugins/authorization/ao/ao.h | 2 + .../authorization/inetaccess/inetaccess.cpp | 44 +++++++++---------- .../authorization/inetaccess/inetaccess.h | 5 ++- .../stargazer/plugins/capture/cap_nf/Makefile | 3 +- .../plugins/capture/cap_nf/cap_nf.cpp | 3 +- .../stargazer/plugins/capture/cap_nf/cap_nf.h | 2 + .../plugins/capture/divert_freebsd/Makefile | 3 +- .../capture/divert_freebsd/divert_cap.cpp | 3 +- .../capture/divert_freebsd/divert_cap.h | 3 ++ .../plugins/capture/ether_freebsd/Makefile | 3 +- .../capture/ether_freebsd/ether_cap.cpp | 3 +- .../plugins/capture/ether_freebsd/ether_cap.h | 3 ++ .../plugins/capture/ether_linux/Makefile | 3 +- .../plugins/capture/ether_linux/ether_cap.cpp | 3 +- .../plugins/capture/ether_linux/ether_cap.h | 3 ++ .../plugins/capture/ipq_linux/Makefile | 3 +- .../plugins/capture/ipq_linux/ipq_cap.cpp | 3 +- .../plugins/capture/ipq_linux/ipq_cap.h | 3 ++ .../configuration/rpcconfig/rpcconfig.cpp | 3 +- .../configuration/rpcconfig/rpcconfig.h | 4 +- .../configuration/sgconfig/configproto.cpp | 8 ++-- .../configuration/sgconfig/configproto.h | 4 +- .../plugins/configuration/sgconfig/rsconf.cpp | 12 ++--- .../configuration/sgconfig/stgconfig.cpp | 3 +- .../configuration/sgconfig/stgconfig.h | 2 + .../stargazer/plugins/other/ping/ping.cpp | 3 +- projects/stargazer/plugins/other/ping/ping.h | 3 ++ .../stargazer/plugins/other/radius/radius.cpp | 3 +- .../stargazer/plugins/other/radius/radius.h | 2 + .../plugins/other/rscript/rscript.cpp | 3 +- .../stargazer/plugins/other/rscript/rscript.h | 3 ++ .../stargazer/plugins/other/smux/smux.cpp | 3 +- projects/stargazer/plugins/other/smux/smux.h | 3 ++ .../plugins/store/files/file_store.cpp | 3 +- .../plugins/store/files/file_store.h | 3 ++ .../plugins/store/firebird/firebird_store.cpp | 3 +- .../plugins/store/firebird/firebird_store.h | 8 ++-- .../stargazer/plugins/store/mysql/Makefile | 3 +- .../plugins/store/mysql/mysql_store.cpp | 3 +- .../plugins/store/mysql/mysql_store.h | 3 ++ .../plugins/store/postgresql/Makefile | 3 +- .../store/postgresql/postgresql_store.cpp | 3 +- .../store/postgresql/postgresql_store.h | 3 ++ stglibs/logger.lib/include/stg/logger.h | 15 +++++++ stglibs/logger.lib/logger.cpp | 31 +++++++++++++ 47 files changed, 179 insertions(+), 67 deletions(-) diff --git a/projects/rscriptd/rscriptd.conf b/projects/rscriptd/rscriptd.conf index d668d46a..fc0fb99f 100644 --- a/projects/rscriptd/rscriptd.conf +++ b/projects/rscriptd/rscriptd.conf @@ -1,8 +1,8 @@ -LogFileName=/var/log/rscriptd.log +LogFileName=./rscriptd.log ExecutersNum=1 -ConfigDir=/etc/rscriptd +ConfigDir=./ Password=123456 Port=9999 UserTimeout=60 -ScriptOnConnect=/etc/rscriptd/OnConnect -ScriptOnDisconnect=/etc/rscriptd/OnDisconnect +ScriptOnConnect=./OnConnect +ScriptOnDisconnect=./OnDisconnect diff --git a/projects/stargazer/plugins/authorization/ao/ao.cpp b/projects/stargazer/plugins/authorization/ao/ao.cpp index cef272c0..e3bc192a 100644 --- a/projects/stargazer/plugins/authorization/ao/ao.cpp +++ b/projects/stargazer/plugins/authorization/ao/ao.cpp @@ -80,7 +80,8 @@ AUTH_AO::AUTH_AO() BeforeChgIPNotifierList(), AfterChgIPNotifierList(), onAddUserNotifier(*this), - onDelUserNotifier(*this) + onDelUserNotifier(*this), + logger(GetPluginLogger(GetStgLogger(), "auth_ao")) { } //----------------------------------------------------------------------------- diff --git a/projects/stargazer/plugins/authorization/ao/ao.h b/projects/stargazer/plugins/authorization/ao/ao.h index 205ebf5a..879c937c 100644 --- a/projects/stargazer/plugins/authorization/ao/ao.h +++ b/projects/stargazer/plugins/authorization/ao/ao.h @@ -37,6 +37,7 @@ #include "stg/notifer.h" #include "stg/user_ips.h" #include "stg/user.h" +#include "stg/logger.h" extern "C" PLUGIN * GetPlugin(); @@ -148,6 +149,7 @@ private: AUTH_AO & auth; } onDelUserNotifier; + PLUGIN_LOGGER logger; friend class CHG_BEFORE_NOTIFIER; friend class CHG_AFTER_NOTIFIER; diff --git a/projects/stargazer/plugins/authorization/inetaccess/inetaccess.cpp b/projects/stargazer/plugins/authorization/inetaccess/inetaccess.cpp index a6d2073a..89ddd09c 100644 --- a/projects/stargazer/plugins/authorization/inetaccess/inetaccess.cpp +++ b/projects/stargazer/plugins/authorization/inetaccess/inetaccess.cpp @@ -321,9 +321,9 @@ AUTH_IA::AUTH_IA() fin6(), fin8(), packetTypes(), - WriteServLog(GetStgLogger()), enabledDirs(0xFFffFFff), - onDelUserNotifier(*this) + onDelUserNotifier(*this), + logger(GetPluginLogger(GetStgLogger(), "auth_ia")) { InitEncrypt(&ctxS, "pr7Hhen"); @@ -594,9 +594,9 @@ uint16_t sport = htons(outerAddr.sin_port); USER_PTR user; if (users->FindByName(login, &user)) { - WriteServLog("User's connect failed: user '%s' not found. IP %s", - login, - inet_ntostring(sip).c_str()); + logger("User's connect failed: user '%s' not found. IP %s", + login, + inet_ntostring(sip).c_str()); printfd(__FILE__, "User '%s' NOT found!\n", login); SendError(sip, sport, protoVer, "îÅÐÒÁ×ÉÌØÎÙÊ ÌÏÇÉÎ!"); return -1; @@ -620,8 +620,8 @@ if (!user->GetProperty().ips.Get().IsIPInIPS(sip)) { printfd(__FILE__, "User %s. IP address is incorrect. IP %s\n", user->GetLogin().c_str(), inet_ntostring(sip).c_str()); - WriteServLog("User %s. IP address is incorrect. IP %s", - user->GetLogin().c_str(), inet_ntostring(sip).c_str()); + logger("User %s. IP address is incorrect. IP %s", + user->GetLogin().c_str(), inet_ntostring(sip).c_str()); SendError(sip, sport, protoVer, "ðÏÌØÚÏ×ÁÔÅÌØ ÎÅ ÏÐÏÚÎÁÎ! ðÒÏ×ÅÒØÔÅ IP ÁÄÒÅÓ."); return 0; } @@ -758,10 +758,10 @@ if (it == ip2user.end()) userPtr->GetLogin().c_str(), inet_ntostring(sip).c_str(), login.c_str()); - WriteServLog("IP address already in use by user '%s'. IP %s, login: '%s'", - userPtr->GetLogin().c_str(), - inet_ntostring(sip).c_str(), - login.c_str()); + logger("IP address already in use by user '%s'. IP %s, login: '%s'", + userPtr->GetLogin().c_str(), + inet_ntostring(sip).c_str(), + login.c_str()); SendError(sip, sport, protoVer, "÷ÁÛ IP ÁÄÒÅÓ ÕÖÅ ÉÓÐÏÌØÚÕÅÔÓÑ!"); return 0; } @@ -783,10 +783,10 @@ else if (user->GetID() != it->second.user->GetID()) it->second.user->GetLogin().c_str(), inet_ntostring(sip).c_str(), user->GetLogin().c_str()); - WriteServLog("IP address already in use by user '%s'. IP %s, login: '%s'", - it->second.user->GetLogin().c_str(), - inet_ntostring(sip).c_str(), - user->GetLogin().c_str()); + logger("IP address already in use by user '%s'. IP %s, login: '%s'", + it->second.user->GetLogin().c_str(), + inet_ntostring(sip).c_str(), + user->GetLogin().c_str()); SendError(sip, sport, protoVer, "÷ÁÛ IP ÁÄÒÅÓ ÕÖÅ ÉÓÐÏÌØÚÕÅÔÓÑ!"); return 0; } @@ -811,9 +811,9 @@ if (pi == packetTypes.end()) { SendError(sip, sport, protoVer, "îÅÐÒÁ×ÉÌØÎÙÊ ÌÏÇÉÎ ÉÌÉ ÐÁÒÏÌØ!"); printfd(__FILE__, "Login or password is wrong!\n"); - WriteServLog("User's connect failed. User: '%s', ip %s. Wrong login or password", - login.c_str(), - inet_ntostring(sip).c_str()); + logger("User's connect failed. User: '%s', ip %s. Wrong login or password", + login.c_str(), + inet_ntostring(sip).c_str()); ip2user.erase(it); return 0; } @@ -823,10 +823,10 @@ if (user->IsAuthorizedBy(this) && user->GetCurrIP() != sip) printfd(__FILE__, "Login %s already in use from ip %s. IP %s\n", login.c_str(), inet_ntostring(user->GetCurrIP()).c_str(), inet_ntostring(sip).c_str()); - WriteServLog("Login %s already in use from ip %s. IP %s", - login.c_str(), - inet_ntostring(user->GetCurrIP()).c_str(), - inet_ntostring(sip).c_str()); + logger("Login %s already in use from ip %s. IP %s", + login.c_str(), + inet_ntostring(user->GetCurrIP()).c_str(), + inet_ntostring(sip).c_str()); SendError(sip, sport, protoVer, "÷ÁÛ ÌÏÇÉÎ ÕÖÅ ÉÓÐÏÌØÚÕÅÔÓÑ!"); ip2user.erase(it); return 0; diff --git a/projects/stargazer/plugins/authorization/inetaccess/inetaccess.h b/projects/stargazer/plugins/authorization/inetaccess/inetaccess.h index d0f6b5ac..08fd6512 100644 --- a/projects/stargazer/plugins/authorization/inetaccess/inetaccess.h +++ b/projects/stargazer/plugins/authorization/inetaccess/inetaccess.h @@ -49,6 +49,7 @@ #include "stg/blowfish.h" #include "stg/logger.h" #include "stg/utime.h" +#include "stg/logger.h" extern "C" PLUGIN * GetPlugin(); @@ -358,12 +359,12 @@ private: std::map packetTypes; - STG_LOGGER & WriteServLog; - uint32_t enabledDirs; DEL_USER_NOTIFIER onDelUserNotifier; + PLUGIN_LOGGER logger; + friend class UnauthorizeUser; }; //----------------------------------------------------------------------------- diff --git a/projects/stargazer/plugins/capture/cap_nf/Makefile b/projects/stargazer/plugins/capture/cap_nf/Makefile index 481862dd..f9412802 100644 --- a/projects/stargazer/plugins/capture/cap_nf/Makefile +++ b/projects/stargazer/plugins/capture/cap_nf/Makefile @@ -10,7 +10,8 @@ SRCS = ./cap_nf.cpp LIBS += $(LIB_THREAD) -STGLIBS = common +STGLIBS = common \ + logger include ../../Makefile.in diff --git a/projects/stargazer/plugins/capture/cap_nf/cap_nf.cpp b/projects/stargazer/plugins/capture/cap_nf/cap_nf.cpp index 51ba4954..8c84885f 100644 --- a/projects/stargazer/plugins/capture/cap_nf/cap_nf.cpp +++ b/projects/stargazer/plugins/capture/cap_nf/cap_nf.cpp @@ -65,7 +65,8 @@ NF_CAP::NF_CAP() portU(0), sockTCP(-1), sockUDP(-1), - errorStr() + errorStr(), + logger(GetPluginLogger(GetStgLogger(), "cap_nf")) { } diff --git a/projects/stargazer/plugins/capture/cap_nf/cap_nf.h b/projects/stargazer/plugins/capture/cap_nf/cap_nf.h index 43d6e098..bf45cfea 100644 --- a/projects/stargazer/plugins/capture/cap_nf/cap_nf.h +++ b/projects/stargazer/plugins/capture/cap_nf/cap_nf.h @@ -37,6 +37,7 @@ $Author: faust $ #include "stg/os_int.h" #include "stg/plugin.h" #include "stg/module_settings.h" +#include "stg/logger.h" #define VERSION "CAP_NF v. 0.4" #define START_POS 40 @@ -122,6 +123,7 @@ private: int sockTCP; int sockUDP; mutable std::string errorStr; + PLUGIN_LOGGER logger; static void * RunUDP(void *); static void * RunTCP(void *); diff --git a/projects/stargazer/plugins/capture/divert_freebsd/Makefile b/projects/stargazer/plugins/capture/divert_freebsd/Makefile index 48e24826..555ec8b1 100644 --- a/projects/stargazer/plugins/capture/divert_freebsd/Makefile +++ b/projects/stargazer/plugins/capture/divert_freebsd/Makefile @@ -10,7 +10,8 @@ SRCS = ./divert_cap.cpp LIBS += $(LIB_THREAD) -STGLIBS = common +STGLIBS = common \ + logger include ../../Makefile.in diff --git a/projects/stargazer/plugins/capture/divert_freebsd/divert_cap.cpp b/projects/stargazer/plugins/capture/divert_freebsd/divert_cap.cpp index 5cf5358f..c50b4974 100644 --- a/projects/stargazer/plugins/capture/divert_freebsd/divert_cap.cpp +++ b/projects/stargazer/plugins/capture/divert_freebsd/divert_cap.cpp @@ -86,7 +86,8 @@ DIVERT_CAP::DIVERT_CAP() thread(), nonstop(false), isRunning(false), - traffCnt(NULL) + traffCnt(NULL), + logger(GetPluginLogger(GetStgLogger(), "cap_divert")) { } //----------------------------------------------------------------------------- diff --git a/projects/stargazer/plugins/capture/divert_freebsd/divert_cap.h b/projects/stargazer/plugins/capture/divert_freebsd/divert_cap.h index 912b5a14..25fd29c2 100644 --- a/projects/stargazer/plugins/capture/divert_freebsd/divert_cap.h +++ b/projects/stargazer/plugins/capture/divert_freebsd/divert_cap.h @@ -33,6 +33,7 @@ $Date: 2009/06/23 11:32:27 $ #include "stg/plugin.h" #include "stg/module_settings.h" +#include "stg/logger.h" class USERS; class TARIFFS; @@ -87,6 +88,8 @@ private: bool isRunning; TRAFFCOUNTER * traffCnt; + + PLUGIN_LOGGER logger; }; //----------------------------------------------------------------------------- diff --git a/projects/stargazer/plugins/capture/ether_freebsd/Makefile b/projects/stargazer/plugins/capture/ether_freebsd/Makefile index d1087896..aeb77636 100644 --- a/projects/stargazer/plugins/capture/ether_freebsd/Makefile +++ b/projects/stargazer/plugins/capture/ether_freebsd/Makefile @@ -10,7 +10,8 @@ SRCS = ./ether_cap.cpp LIBS += $(LIB_THREAD) -STGLIBS = common +STGLIBS = common \ + logger include ../../Makefile.in diff --git a/projects/stargazer/plugins/capture/ether_freebsd/ether_cap.cpp b/projects/stargazer/plugins/capture/ether_freebsd/ether_cap.cpp index 24705111..4e9fa0ff 100644 --- a/projects/stargazer/plugins/capture/ether_freebsd/ether_cap.cpp +++ b/projects/stargazer/plugins/capture/ether_freebsd/ether_cap.cpp @@ -125,7 +125,8 @@ BPF_CAP::BPF_CAP() isRunning(false), capSock(-1), settings(), - traffCnt(NULL) + traffCnt(NULL), + logger(GetPluginLogger(GetStgLogger(), "cap_ether")) { } //----------------------------------------------------------------------------- diff --git a/projects/stargazer/plugins/capture/ether_freebsd/ether_cap.h b/projects/stargazer/plugins/capture/ether_freebsd/ether_cap.h index ad9ff9f1..0a00cb04 100644 --- a/projects/stargazer/plugins/capture/ether_freebsd/ether_cap.h +++ b/projects/stargazer/plugins/capture/ether_freebsd/ether_cap.h @@ -35,6 +35,7 @@ #include "stg/os_int.h" #include "stg/plugin.h" #include "stg/module_settings.h" +#include "stg/logger.h" extern "C" PLUGIN * GetPlugin(); @@ -135,6 +136,8 @@ private: MODULE_SETTINGS settings; TRAFFCOUNTER * traffCnt; + + PLUGIN_LOGGER logger; }; //----------------------------------------------------------------------------- diff --git a/projects/stargazer/plugins/capture/ether_linux/Makefile b/projects/stargazer/plugins/capture/ether_linux/Makefile index 873ba6f0..c89ea653 100644 --- a/projects/stargazer/plugins/capture/ether_linux/Makefile +++ b/projects/stargazer/plugins/capture/ether_linux/Makefile @@ -10,7 +10,8 @@ SRCS = ./ether_cap.cpp LIBS += $(LIB_THREAD) -STGLIBS = common +STGLIBS = common \ + logger include ../../Makefile.in diff --git a/projects/stargazer/plugins/capture/ether_linux/ether_cap.cpp b/projects/stargazer/plugins/capture/ether_linux/ether_cap.cpp index 093aea72..f620c802 100644 --- a/projects/stargazer/plugins/capture/ether_linux/ether_cap.cpp +++ b/projects/stargazer/plugins/capture/ether_linux/ether_cap.cpp @@ -78,7 +78,8 @@ ETHER_CAP::ETHER_CAP() nonstop(false), isRunning(false), capSock(-1), - traffCnt(NULL) + traffCnt(NULL), + logger(GetPluginLogger(GetStgLogger(), "cap_ether")) { } //----------------------------------------------------------------------------- diff --git a/projects/stargazer/plugins/capture/ether_linux/ether_cap.h b/projects/stargazer/plugins/capture/ether_linux/ether_cap.h index 44c4ae7e..c8de5522 100644 --- a/projects/stargazer/plugins/capture/ether_linux/ether_cap.h +++ b/projects/stargazer/plugins/capture/ether_linux/ether_cap.h @@ -32,6 +32,7 @@ #include "stg/plugin.h" #include "stg/module_settings.h" +#include "stg/logger.h" class USERS; class TARIFFS; @@ -79,6 +80,8 @@ private: int capSock; TRAFFCOUNTER * traffCnt; + + PLUGIN_LOGGER logger; }; //----------------------------------------------------------------------------- diff --git a/projects/stargazer/plugins/capture/ipq_linux/Makefile b/projects/stargazer/plugins/capture/ipq_linux/Makefile index 548f589c..48dc3449 100644 --- a/projects/stargazer/plugins/capture/ipq_linux/Makefile +++ b/projects/stargazer/plugins/capture/ipq_linux/Makefile @@ -11,7 +11,8 @@ SRCS = ./ipq_cap.cpp \ LIBS += $(LIB_THREAD) -STGLIBS = common +STGLIBS = common \ + logger include ../../Makefile.in diff --git a/projects/stargazer/plugins/capture/ipq_linux/ipq_cap.cpp b/projects/stargazer/plugins/capture/ipq_linux/ipq_cap.cpp index 1dc22b4c..6cf5b0f9 100644 --- a/projects/stargazer/plugins/capture/ipq_linux/ipq_cap.cpp +++ b/projects/stargazer/plugins/capture/ipq_linux/ipq_cap.cpp @@ -63,7 +63,8 @@ IPQ_CAP::IPQ_CAP() isRunning(false), capSock(-1), traffCnt(NULL), - buf() + buf(), + logger(GetPluginLogger(GetStgLogger(), "cap_ipq")) { memset(buf, 0, BUFSIZE); } diff --git a/projects/stargazer/plugins/capture/ipq_linux/ipq_cap.h b/projects/stargazer/plugins/capture/ipq_linux/ipq_cap.h index 7c78da89..8b524d93 100644 --- a/projects/stargazer/plugins/capture/ipq_linux/ipq_cap.h +++ b/projects/stargazer/plugins/capture/ipq_linux/ipq_cap.h @@ -26,6 +26,7 @@ #include "stg/plugin.h" #include "stg/module_settings.h" #include "stg/os_int.h" +#include "stg/logger.h" #define BUFSIZE (256) #define PAYLOAD_LEN (96) @@ -76,6 +77,8 @@ private: TRAFFCOUNTER * traffCnt; unsigned char buf[BUFSIZE]; + + PLUGIN_LOGGER logger; }; #endif diff --git a/projects/stargazer/plugins/configuration/rpcconfig/rpcconfig.cpp b/projects/stargazer/plugins/configuration/rpcconfig/rpcconfig.cpp index 56a188f1..682c5268 100644 --- a/projects/stargazer/plugins/configuration/rpcconfig/rpcconfig.cpp +++ b/projects/stargazer/plugins/configuration/rpcconfig/rpcconfig.cpp @@ -96,7 +96,8 @@ RPC_CONFIG::RPC_CONFIG() tid(), cookies(), dayFee(0), - dirNames() + dirNames(), + logger(GetPluginLogger(GetStgLogger(), "conf_rpc")) { } diff --git a/projects/stargazer/plugins/configuration/rpcconfig/rpcconfig.h b/projects/stargazer/plugins/configuration/rpcconfig/rpcconfig.h index 8525f889..a58773a1 100644 --- a/projects/stargazer/plugins/configuration/rpcconfig/rpcconfig.h +++ b/projects/stargazer/plugins/configuration/rpcconfig/rpcconfig.h @@ -16,6 +16,7 @@ #include "stg/plugin.h" #include "stg/admin_conf.h" #include "stg/module_settings.h" +#include "stg/logger.h" #define RPC_CONFIG_VERSION "Stargazer RPC v. 0.2" @@ -55,7 +56,7 @@ struct ADMIN_INFO PRIV priviledges; }; -class RPC_CONFIG :public PLUGIN +class RPC_CONFIG : public PLUGIN { public: RPC_CONFIG(); @@ -111,6 +112,7 @@ private: ADMIN_INFO> cookies; size_t dayFee; std::vector dirNames; + PLUGIN_LOGGER logger; }; #endif diff --git a/projects/stargazer/plugins/configuration/sgconfig/configproto.cpp b/projects/stargazer/plugins/configuration/sgconfig/configproto.cpp index 07c319a0..0addee63 100644 --- a/projects/stargazer/plugins/configuration/sgconfig/configproto.cpp +++ b/projects/stargazer/plugins/configuration/sgconfig/configproto.cpp @@ -86,7 +86,7 @@ else } } //----------------------------------------------------------------------------- -CONFIGPROTO::CONFIGPROTO() +CONFIGPROTO::CONFIGPROTO(PLUGIN_LOGGER & l) : answerList(), requestList(), adminIP(0), @@ -96,7 +96,7 @@ CONFIGPROTO::CONFIGPROTO() nonstop(true), state(0), currAdmin(NULL), - WriteServLog(GetStgLogger()), + logger(l), listenSocket(-1), parserGetServInfo(), parserGetUsers(), @@ -144,7 +144,7 @@ xmlParser = XML_ParserCreate(NULL); if (!xmlParser) { - WriteServLog("Couldn't allocate memory for parser."); + logger("Couldn't allocate memory for parser."); exit(1); } @@ -187,7 +187,7 @@ while(nonstop) if (XML_Parse(xmlParser, (*n).c_str(), len, done) == XML_STATUS_ERROR) { - WriteServLog("Invalid configuration request"); + logger("Invalid configuration request"); printfd(__FILE__, "Parse error at line %d:\n%s\n", XML_GetCurrentLineNumber(xmlParser), XML_ErrorString(XML_GetErrorCode(xmlParser))); diff --git a/projects/stargazer/plugins/configuration/sgconfig/configproto.h b/projects/stargazer/plugins/configuration/sgconfig/configproto.h index 15809c3c..20e38d9d 100644 --- a/projects/stargazer/plugins/configuration/sgconfig/configproto.h +++ b/projects/stargazer/plugins/configuration/sgconfig/configproto.h @@ -52,7 +52,7 @@ //----------------------------------------------------------------------------- class CONFIGPROTO { public: - CONFIGPROTO(); + CONFIGPROTO(PLUGIN_LOGGER & l); ~CONFIGPROTO(); void SetPort(uint16_t port); @@ -93,7 +93,7 @@ private: bool nonstop; int state; ADMIN * currAdmin; - STG_LOGGER & WriteServLog; + PLUGIN_LOGGER & logger; int listenSocket; diff --git a/projects/stargazer/plugins/configuration/sgconfig/rsconf.cpp b/projects/stargazer/plugins/configuration/sgconfig/rsconf.cpp index c0b7b325..5e699848 100644 --- a/projects/stargazer/plugins/configuration/sgconfig/rsconf.cpp +++ b/projects/stargazer/plugins/configuration/sgconfig/rsconf.cpp @@ -278,7 +278,7 @@ if (err) { if (send(sock, ERR_HEADER, sizeof(ERR_HEADER) - 1, 0) < 0) { - WriteServLog("send ERR_HEADER error in SendHdrAnswer."); + logger("send ERR_HEADER error in SendHdrAnswer."); return -1; } } @@ -286,7 +286,7 @@ else { if (send(sock, OK_HEADER, sizeof(OK_HEADER) - 1, 0) < 0) { - WriteServLog("send OK_HEADER error in SendHdrAnswer."); + logger("send OK_HEADER error in SendHdrAnswer."); return -1; } } @@ -337,7 +337,7 @@ int CONFIGPROTO::SendLoginAnswer(int sock) { if (send(sock, OK_LOGIN, sizeof(OK_LOGIN) - 1, 0) < 0) { - WriteServLog("Send OK_LOGIN error in SendLoginAnswer."); + logger("Send OK_LOGIN error in SendLoginAnswer."); return -1; } return 0; @@ -408,7 +408,7 @@ if (err) { if (send(sock, ERR_LOGINS, sizeof(ERR_LOGINS) - 1, 0) < 0) { - WriteServLog("send ERR_LOGIN error in SendLoginAnswer."); + logger("send ERR_LOGIN error in SendLoginAnswer."); return -1; } } @@ -416,7 +416,7 @@ else { if (send(sock, OK_LOGINS, sizeof(OK_LOGINS) - 1, 0) < 0) { - WriteServLog("send OK_LOGINS error in SendLoginSAnswer."); + logger("send OK_LOGINS error in SendLoginSAnswer."); return -1; } } @@ -537,6 +537,6 @@ answerList.push_back(s); //----------------------------------------------------------------------------- void CONFIGPROTO::WriteLogAccessFailed(uint32_t ip) { -WriteServLog("Admin's connect failed. IP %s", inet_ntostring(ip).c_str()); +logger("Admin's connect failed. IP %s", inet_ntostring(ip).c_str()); } //----------------------------------------------------------------------------- diff --git a/projects/stargazer/plugins/configuration/sgconfig/stgconfig.cpp b/projects/stargazer/plugins/configuration/sgconfig/stgconfig.cpp index ea71a117..78c45d72 100644 --- a/projects/stargazer/plugins/configuration/sgconfig/stgconfig.cpp +++ b/projects/stargazer/plugins/configuration/sgconfig/stgconfig.cpp @@ -61,7 +61,8 @@ STG_CONFIG::STG_CONFIG() thread(), nonstop(false), isRunning(false), - config(), + logger(GetPluginLogger(GetStgLogger(), "conf_sg")), + config(logger), users(NULL), admins(NULL), tariffs(NULL), diff --git a/projects/stargazer/plugins/configuration/sgconfig/stgconfig.h b/projects/stargazer/plugins/configuration/sgconfig/stgconfig.h index cdce9668..7e3ae69b 100644 --- a/projects/stargazer/plugins/configuration/sgconfig/stgconfig.h +++ b/projects/stargazer/plugins/configuration/sgconfig/stgconfig.h @@ -7,6 +7,7 @@ #include "stg/plugin.h" #include "stg/store.h" +#include "stg/logger.h" #include "configproto.h" extern "C" PLUGIN * GetPlugin(); @@ -59,6 +60,7 @@ private: pthread_t thread; bool nonstop; bool isRunning; + PLUGIN_LOGGER logger; CONFIGPROTO config; USERS * users; ADMINS * admins; diff --git a/projects/stargazer/plugins/other/ping/ping.cpp b/projects/stargazer/plugins/other/ping/ping.cpp index f0868e12..00bb362d 100644 --- a/projects/stargazer/plugins/other/ping/ping.cpp +++ b/projects/stargazer/plugins/other/ping/ping.cpp @@ -74,7 +74,8 @@ PING::PING() ChgCurrIPNotifierList(), ChgIPNotifierList(), onAddUserNotifier(*this), - onDelUserNotifier(*this) + onDelUserNotifier(*this), + logger(GetPluginLogger(GetStgLogger(), "ping")) { pthread_mutex_init(&mutex, NULL); } diff --git a/projects/stargazer/plugins/other/ping/ping.h b/projects/stargazer/plugins/other/ping/ping.h index 6c31eb95..421b83da 100644 --- a/projects/stargazer/plugins/other/ping/ping.h +++ b/projects/stargazer/plugins/other/ping/ping.h @@ -19,6 +19,7 @@ #include "stg/user_ips.h" #include "stg/pinger.h" #include "stg/users.h" +#include "stg/logger.h" extern "C" PLUGIN * GetPlugin(); @@ -148,6 +149,8 @@ private: ADD_USER_NONIFIER_PING onAddUserNotifier; DEL_USER_NONIFIER_PING onDelUserNotifier; + + PLUGIN_LOGGER logger; }; //----------------------------------------------------------------------------- diff --git a/projects/stargazer/plugins/other/radius/radius.cpp b/projects/stargazer/plugins/other/radius/radius.cpp index 480e6f16..6fb4d2f9 100644 --- a/projects/stargazer/plugins/other/radius/radius.cpp +++ b/projects/stargazer/plugins/other/radius/radius.cpp @@ -136,7 +136,8 @@ RADIUS::RADIUS() thread(), mutex(), sock(-1), - packet() + packet(), + logger(GetPluginLogger(GetStgLogger(), "radius")) { InitEncrypt(&ctx, ""); } diff --git a/projects/stargazer/plugins/other/radius/radius.h b/projects/stargazer/plugins/other/radius/radius.h index 92cfcab2..8281b1ae 100644 --- a/projects/stargazer/plugins/other/radius/radius.h +++ b/projects/stargazer/plugins/other/radius/radius.h @@ -47,6 +47,7 @@ #include "stg/users.h" #include "stg/blowfish.h" #include "stg/rad_packets.h" +#include "stg/logger.h" extern "C" PLUGIN * GetPlugin(); @@ -172,6 +173,7 @@ private: RAD_PACKET packet; + PLUGIN_LOGGER logger; }; //----------------------------------------------------------------------------- diff --git a/projects/stargazer/plugins/other/rscript/rscript.cpp b/projects/stargazer/plugins/other/rscript/rscript.cpp index 9e560a5d..4ce51d65 100644 --- a/projects/stargazer/plugins/other/rscript/rscript.cpp +++ b/projects/stargazer/plugins/other/rscript/rscript.cpp @@ -181,7 +181,8 @@ REMOTE_SCRIPT::REMOTE_SCRIPT() mutex(), sock(0), onAddUserNotifier(*this), - onDelUserNotifier(*this) + onDelUserNotifier(*this), + logger(GetPluginLogger(GetStgLogger(), "rscript")) { pthread_mutex_init(&mutex, NULL); } diff --git a/projects/stargazer/plugins/other/rscript/rscript.h b/projects/stargazer/plugins/other/rscript/rscript.h index 794c4c2b..6ee10c82 100644 --- a/projects/stargazer/plugins/other/rscript/rscript.h +++ b/projects/stargazer/plugins/other/rscript/rscript.h @@ -47,6 +47,7 @@ #include "stg/users.h" #include "stg/blowfish.h" #include "stg/rs_packets.h" +#include "stg/logger.h" #include "nrmap_parser.h" extern "C" PLUGIN * GetPlugin(); @@ -227,6 +228,8 @@ private: RS_ADD_USER_NONIFIER onAddUserNotifier; RS_DEL_USER_NONIFIER onDelUserNotifier; + PLUGIN_LOGGER logger; + friend class UpdateRouter; friend class DisconnectUser; }; diff --git a/projects/stargazer/plugins/other/smux/smux.cpp b/projects/stargazer/plugins/other/smux/smux.cpp index 551a28f1..c1352de2 100644 --- a/projects/stargazer/plugins/other/smux/smux.cpp +++ b/projects/stargazer/plugins/other/smux/smux.cpp @@ -111,7 +111,8 @@ SMUX::SMUX() notifiers(), addUserNotifier(*this), delUserNotifier(*this), - addDelTariffNotifier(*this) + addDelTariffNotifier(*this), + logger(GetPluginLogger(GetStgLogger(), "smux")) { pthread_mutex_init(&mutex, NULL); diff --git a/projects/stargazer/plugins/other/smux/smux.h b/projects/stargazer/plugins/other/smux/smux.h index adeb50af..cc722511 100644 --- a/projects/stargazer/plugins/other/smux/smux.h +++ b/projects/stargazer/plugins/other/smux/smux.h @@ -15,6 +15,7 @@ #include "stg/module_settings.h" #include "stg/notifer.h" #include "stg/noncopyable.h" +#include "stg/logger.h" #include "sensors.h" #include "tables.h" @@ -179,6 +180,8 @@ private: ADD_USER_NOTIFIER addUserNotifier; DEL_USER_NOTIFIER delUserNotifier; ADD_DEL_TARIFF_NOTIFIER addDelTariffNotifier; + + PLUGIN_LOGGER logger; }; //----------------------------------------------------------------------------- diff --git a/projects/stargazer/plugins/store/files/file_store.cpp b/projects/stargazer/plugins/store/files/file_store.cpp index 0149f07c..334824d9 100644 --- a/projects/stargazer/plugins/store/files/file_store.cpp +++ b/projects/stargazer/plugins/store/files/file_store.cpp @@ -341,7 +341,8 @@ FILES_STORE::FILES_STORE() version("file_store v.1.04"), storeSettings(), settings(), - mutex() + mutex(), + logger(GetPluginLogger(GetStgLogger(), "store_files")) { pthread_mutexattr_t attr; pthread_mutexattr_init(&attr); diff --git a/projects/stargazer/plugins/store/files/file_store.h b/projects/stargazer/plugins/store/files/file_store.h index 91fb7fa8..2316398f 100644 --- a/projects/stargazer/plugins/store/files/file_store.h +++ b/projects/stargazer/plugins/store/files/file_store.h @@ -37,6 +37,7 @@ #include "stg/store.h" #include "stg/conffiles.h" #include "stg/user_traff.h" +#include "stg/logger.h" //----------------------------------------------------------------------------- extern "C" STORE * GetStore(); @@ -203,6 +204,8 @@ private: FILES_STORE_SETTINGS storeSettings; MODULE_SETTINGS settings; mutable pthread_mutex_t mutex; + + PLUGIN_LOGGER logger; }; //----------------------------------------------------------------------------- diff --git a/projects/stargazer/plugins/store/firebird/firebird_store.cpp b/projects/stargazer/plugins/store/firebird/firebird_store.cpp index 3085981f..e5c7b0b1 100644 --- a/projects/stargazer/plugins/store/firebird/firebird_store.cpp +++ b/projects/stargazer/plugins/store/firebird/firebird_store.cpp @@ -56,7 +56,8 @@ FIREBIRD_STORE::FIREBIRD_STORE() db(), mutex(), til(IBPP::ilConcurrency), - tlr(IBPP::lrWait) + tlr(IBPP::lrWait), + logger(GetPluginLogger(GetStgLogger(), "store_firebird")) { pthread_mutex_init(&mutex, NULL); } diff --git a/projects/stargazer/plugins/store/firebird/firebird_store.h b/projects/stargazer/plugins/store/firebird/firebird_store.h index 58054cba..38ff457d 100644 --- a/projects/stargazer/plugins/store/firebird/firebird_store.h +++ b/projects/stargazer/plugins/store/firebird/firebird_store.h @@ -37,6 +37,7 @@ #include "stg/store.h" #include "stg/locker.h" #include "stg/ibpp.h" +#include "stg/logger.h" struct ToLower { char operator() (char c) const { return std::tolower(c); } @@ -121,12 +122,13 @@ private: std::string version; mutable std::string strError; - mutable std::string db_server, db_database, db_user, db_password; + std::string db_server, db_database, db_user, db_password; MODULE_SETTINGS settings; mutable IBPP::Database db; mutable pthread_mutex_t mutex; - mutable IBPP::TIL til; - mutable IBPP::TLR tlr; + IBPP::TIL til; + IBPP::TLR tlr; + PLUGIN_LOGGER logger; int SaveStat(const USER_STAT & stat, const std::string & login, int year = 0, int month = 0) const; }; diff --git a/projects/stargazer/plugins/store/mysql/Makefile b/projects/stargazer/plugins/store/mysql/Makefile index 57c52a6b..25a29798 100644 --- a/projects/stargazer/plugins/store/mysql/Makefile +++ b/projects/stargazer/plugins/store/mysql/Makefile @@ -9,7 +9,8 @@ PROG = mod_store_mysql.so SRCS = ./mysql_store.cpp STGLIBS = common \ - crypto + crypto \ + logger MYSQL_CFLAGS = $(shell mysql_config --cflags) MYSQL_LDFLAGS = $(shell mysql_config --libs_r) diff --git a/projects/stargazer/plugins/store/mysql/mysql_store.cpp b/projects/stargazer/plugins/store/mysql/mysql_store.cpp index 9d8f9c83..8e04f5a5 100644 --- a/projects/stargazer/plugins/store/mysql/mysql_store.cpp +++ b/projects/stargazer/plugins/store/mysql/mysql_store.cpp @@ -157,7 +157,8 @@ MYSQL_STORE::MYSQL_STORE() : errorStr(), version("mysql_store v.0.67"), storeSettings(), - settings() + settings(), + logger(GetPluginLogger(GetStgLogger(), "store_mysql")) { }; //----------------------------------------------------------------------------- diff --git a/projects/stargazer/plugins/store/mysql/mysql_store.h b/projects/stargazer/plugins/store/mysql/mysql_store.h index d0d4f70d..25cf5a3d 100644 --- a/projects/stargazer/plugins/store/mysql/mysql_store.h +++ b/projects/stargazer/plugins/store/mysql/mysql_store.h @@ -14,6 +14,7 @@ #include "stg/module_settings.h" #include "stg/store.h" #include "stg/user_traff.h" +#include "stg/logger.h" using namespace std; //----------------------------------------------------------------------------- @@ -141,6 +142,8 @@ private: string version; MYSQL_STORE_SETTINGS storeSettings; MODULE_SETTINGS settings; + + PLUGIN_LOGGER logger; }; //----------------------------------------------------------------------------- diff --git a/projects/stargazer/plugins/store/postgresql/Makefile b/projects/stargazer/plugins/store/postgresql/Makefile index b59e45cd..0bd8f629 100644 --- a/projects/stargazer/plugins/store/postgresql/Makefile +++ b/projects/stargazer/plugins/store/postgresql/Makefile @@ -17,7 +17,8 @@ SRCS = ./postgresql_store.cpp \ STGLIBS = common \ crypto \ - locker + locker \ + logger PG_CFLAGS = $(shell pg_config --includedir) PG_LDFLAGS = $(shell pg_config --libdir) diff --git a/projects/stargazer/plugins/store/postgresql/postgresql_store.cpp b/projects/stargazer/plugins/store/postgresql/postgresql_store.cpp index 073fccab..7c79baff 100644 --- a/projects/stargazer/plugins/store/postgresql/postgresql_store.cpp +++ b/projects/stargazer/plugins/store/postgresql/postgresql_store.cpp @@ -70,7 +70,8 @@ POSTGRESQL_STORE::POSTGRESQL_STORE() mutex(), version(0), retries(3), - connection(NULL) + connection(NULL), + logger(GetPluginLogger(GetStgLogger(), "store_postgresql")) { pthread_mutex_init(&mutex, NULL); } diff --git a/projects/stargazer/plugins/store/postgresql/postgresql_store.h b/projects/stargazer/plugins/store/postgresql/postgresql_store.h index edba0359..a30d3852 100644 --- a/projects/stargazer/plugins/store/postgresql/postgresql_store.h +++ b/projects/stargazer/plugins/store/postgresql/postgresql_store.h @@ -36,6 +36,7 @@ #include #include "stg/store.h" +#include "stg/logger.h" // Minimal DB version is 5 // Recommended DB version is 6 (support FreeMb logging on disconnects) @@ -158,6 +159,8 @@ private: int retries; PGconn * connection; + + PLUGIN_LOGGER logger; }; extern const volatile time_t stgTime; diff --git a/stglibs/logger.lib/include/stg/logger.h b/stglibs/logger.lib/include/stg/logger.h index 9fe14878..2c9c93fc 100644 --- a/stglibs/logger.lib/include/stg/logger.h +++ b/stglibs/logger.lib/include/stg/logger.h @@ -26,6 +26,7 @@ private: class STG_LOGGER { friend STG_LOGGER & GetStgLogger(); +friend class PLUGIN_LOGGER; public: ~STG_LOGGER(); @@ -43,5 +44,19 @@ private: pthread_mutex_t mutex; }; //----------------------------------------------------------------------------- +class PLUGIN_LOGGER : private STG_LOGGER +{ +friend PLUGIN_LOGGER GetPluginLogger(const STG_LOGGER & logger, const std::string & pluginName); + +public: + PLUGIN_LOGGER(const PLUGIN_LOGGER & rhs); + void operator()(const char * fmt, ...); + +private: + PLUGIN_LOGGER(const STG_LOGGER & logger, const std::string & pn); + std::string pluginName; +}; + +PLUGIN_LOGGER GetPluginLogger(const STG_LOGGER & logger, const std::string & pluginName); #endif //STG_LOGGER_H diff --git a/stglibs/logger.lib/logger.cpp b/stglibs/logger.lib/logger.cpp index d8558199..3bbd3367 100644 --- a/stglibs/logger.lib/logger.cpp +++ b/stglibs/logger.lib/logger.cpp @@ -93,3 +93,34 @@ snprintf(s, 32, "%d-%s%d-%s%d %s%d:%s%d:%s%d", return s; } //----------------------------------------------------------------------------- +PLUGIN_LOGGER::PLUGIN_LOGGER(const STG_LOGGER & logger, const std::string & pn) + : STG_LOGGER(), + pluginName(pn) +{ + SetLogFileName(logger.fileName); +} +//----------------------------------------------------------------------------- +PLUGIN_LOGGER::PLUGIN_LOGGER(const PLUGIN_LOGGER & rhs) + : STG_LOGGER(), + pluginName(rhs.pluginName) +{ + SetLogFileName(fileName); +} +//----------------------------------------------------------------------------- +void PLUGIN_LOGGER::operator()(const char * fmt, ...) +{ +char buff[2029]; + +va_list vl; +va_start(vl, fmt); +vsnprintf(buff, sizeof(buff), fmt, vl); +va_end(vl); + +STG_LOGGER::operator()("[%s] %s", pluginName.c_str(), buff); +} +//----------------------------------------------------------------------------- +PLUGIN_LOGGER GetPluginLogger(const STG_LOGGER & logger, const std::string & pluginName) +{ +return PLUGIN_LOGGER(logger, pluginName); +} +//----------------------------------------------------------------------------- -- 2.44.2