From e28e9720dd5a9c082efb77ed326fab36a1eee7c3 Mon Sep 17 00:00:00 2001 From: sehraf Date: Thu, 16 Jun 2016 21:26:02 +0200 Subject: [PATCH 1/5] removed dead code --- libretroshare/src/util/rsdebug.cc | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/libretroshare/src/util/rsdebug.cc b/libretroshare/src/util/rsdebug.cc index 8dcf2bf3f..312d2a877 100644 --- a/libretroshare/src/util/rsdebug.cc +++ b/libretroshare/src/util/rsdebug.cc @@ -112,6 +112,7 @@ int setDebugCrashMode(const char *cfile) } +#ifdef deadcode // this code is not used by RS /* this is called when we exit normally */ int clearDebugCrashLog() { @@ -135,7 +136,7 @@ int clearDebugCrashLog() return 1; } - +#endif int setDebugFile(const char *fname) @@ -168,13 +169,14 @@ int setOutputLevel(int lvl) return defaultLevel = lvl; } +#ifdef deadcode // this code is not used by RS int setZoneLevel(int lvl, int zone) { RsStackMutex stack(logMtx); /******** LOCKED ****************/ zoneLevel[zone] = lvl; return zone; } - +#endif int getZoneLevel(int zone) { @@ -182,14 +184,17 @@ int getZoneLevel(int zone) return locked_getZoneLevel(zone); } -int locked_getZoneLevel(int zone) +int locked_getZoneLevel(int /*zone*/) { +#ifdef deadcode // this code is not used by RS std::map::iterator it = zoneLevel.find(zone); if (it == zoneLevel.end()) { return defaultLevel; } return it -> second; +#endif + return defaultLevel; } int rslog(unsigned int lvl, int zone, const std::string &msg) From f6c5a05c8e0f7f4d55877c064d33ad7e6bfda0b4 Mon Sep 17 00:00:00 2001 From: sehraf Date: Fri, 17 Jun 2016 11:09:59 +0200 Subject: [PATCH 2/5] switched to caller providing all needed information instead of saving those on callee side --- libretroshare/src/util/rsdebug.cc | 85 ++++++++++++++++--------------- libretroshare/src/util/rsdebug.h | 34 ++++++++++--- 2 files changed, 70 insertions(+), 49 deletions(-) diff --git a/libretroshare/src/util/rsdebug.cc b/libretroshare/src/util/rsdebug.cc index 312d2a877..e2536a7cb 100644 --- a/libretroshare/src/util/rsdebug.cc +++ b/libretroshare/src/util/rsdebug.cc @@ -37,8 +37,8 @@ const int RS_DEBUG_LOGCRASH = 3; /* minimal logfile stored after crashes */ const int RS_DEBUG_LOGC_MAX = 100000; /* max length of crashfile log */ const int RS_DEBUG_LOGC_MIN_SAVE = 100; /* min length of crashfile log */ -static std::map zoneLevel; -static int defaultLevel = RSL_WARNING; +//static std::map zoneLevel; +static RsLog::logLvl defaultLevel = RsLog::Warning; static FILE *ofd = stderr; static int debugMode = RS_DEBUG_STDERR; @@ -49,7 +49,6 @@ static int debugTS = 0; static RsMutex logMtx("logMtx"); int locked_setDebugFile(const char *fname); -int locked_getZoneLevel(int zone); int setDebugCrashMode(const char *cfile) { @@ -138,7 +137,6 @@ int clearDebugCrashLog() } #endif - int setDebugFile(const char *fname) { RsStackMutex stack(logMtx); /******** LOCKED ****************/ @@ -162,45 +160,51 @@ int locked_setDebugFile(const char *fname) } } +//int setOutputLevel(RsLog::logLvl lvl) +//{ +// RsStackMutex stack(logMtx); /******** LOCKED ****************/ +// return defaultLevel = lvl; +//} -int setOutputLevel(int lvl) +//#ifdef deadcode // this code is not used by RS +//int setZoneLevel(int lvl, int zone) +//{ +// RsStackMutex stack(logMtx); /******** LOCKED ****************/ +// zoneLevel[zone] = lvl; +// return zone; +//} +//#endif + +//int getZoneLevel(int zone) +//{ +// RsStackMutex stack(logMtx); /******** LOCKED ****************/ +// return locked_getZoneLevel(zone); +//} + +//int locked_getZoneLevel(int /*zone*/) +//{ +//#ifdef deadcode // this code is not used by RS +// std::map::iterator it = zoneLevel.find(zone); +// if (it == zoneLevel.end()) +// { +// return defaultLevel; +// } +// return it -> second; +//#endif +// return defaultLevel; +//} + +void rslog(const RsLog::logLvl lvl, const RsLog::logInfo *info, const std::string &msg) { + // skipp when log level is set to 'None' + // NB: when default is set to 'None' the later check will always fail -> no need to check it here + if(info->lvl == RsLog::None) + return; + RsStackMutex stack(logMtx); /******** LOCKED ****************/ - return defaultLevel = lvl; -} -#ifdef deadcode // this code is not used by RS -int setZoneLevel(int lvl, int zone) -{ - RsStackMutex stack(logMtx); /******** LOCKED ****************/ - zoneLevel[zone] = lvl; - return zone; -} -#endif - -int getZoneLevel(int zone) -{ - RsStackMutex stack(logMtx); /******** LOCKED ****************/ - return locked_getZoneLevel(zone); -} - -int locked_getZoneLevel(int /*zone*/) -{ -#ifdef deadcode // this code is not used by RS - std::map::iterator it = zoneLevel.find(zone); - if (it == zoneLevel.end()) - { - return defaultLevel; - } - return it -> second; -#endif - return defaultLevel; -} - -int rslog(unsigned int lvl, int zone, const std::string &msg) -{ - RsStackMutex stack(logMtx); /******** LOCKED ****************/ - if ((signed) lvl <= locked_getZoneLevel(zone)) + bool process = info-lvl == RsLog::Default ? (lvl <= defaultLevel) : lvl <= info->lvl; + if(process) { time_t t = time(NULL); @@ -232,11 +236,10 @@ int rslog(unsigned int lvl, int zone, const std::string &msg) std::string timestr2 = timestr.substr(0,timestr.length()-1); /* remove the endl */ fprintf(ofd, "(%s Z: %d, lvl:%u): %s \n", - timestr2.c_str(), zone, lvl, msg.c_str()); + timestr2.c_str(), zone, (unsigned int)info->lvl, msg.c_str()); fflush(ofd); lineCount++; } - return 1; } diff --git a/libretroshare/src/util/rsdebug.h b/libretroshare/src/util/rsdebug.h index 1e2d58b52..1d8f3cae0 100644 --- a/libretroshare/src/util/rsdebug.h +++ b/libretroshare/src/util/rsdebug.h @@ -30,8 +30,6 @@ #ifndef RS_LOG_DEBUG_H #define RS_LOG_DEBUG_H - - #define RSL_NONE -1 #define RSL_ALERT 1 #define RSL_ERROR 3 @@ -40,17 +38,37 @@ #define RSL_DEBUG_BASIC 8 #define RSL_DEBUG_ALL 10 - #include +namespace RsLog { + enum logLvl { + None = -1, + Default = 0, + Alert = 1, + Error = 3, + Warning = 5, + Debug_Alert = 6, + Debug_Basic = 8, + Debug_All = 10 + }; + + // this struct must be provided by the caller (to rslog()) + struct logInfo { + // module name + const std::string name; + // module specific log lvl + logLvl lvl; + }; +} + int setDebugCrashMode(const char *cfile); -int clearDebugCrashLog(); +//int clearDebugCrashLog(); int setDebugFile(const char *fname); -int setOutputLevel(int lvl); -int setZoneLevel(int lvl, int zone); -int getZoneLevel(int zone); -int rslog(unsigned int lvl, int zone, const std::string &msg); +int setOutputLevel(RsLog::logLvl lvl); +//int setZoneLevel(int lvl, int zone); +//int getZoneLevel(int zone); +void rslog(const RsLog::logLvl lvl, const RsLog::logInfo *info, const std::string &msg); From 09afbbed5d6bb312b8e692d4e4b197257cbe7c79 Mon Sep 17 00:00:00 2001 From: sehraf Date: Sat, 18 Jun 2016 13:00:15 +0200 Subject: [PATCH 3/5] switched to new rslog method --- libretroshare/src/pqi/p3linkmgr.cc | 4 ++-- libretroshare/src/pqi/p3netmgr.cc | 3 ++- libretroshare/src/pqi/p3peermgr.cc | 4 +++- libretroshare/src/pqi/pqihandler.cc | 3 ++- libretroshare/src/pqi/pqinetwork.cc | 3 ++- libretroshare/src/pqi/pqiperson.cc | 10 +++++----- libretroshare/src/pqi/pqipersongrp.cc | 3 ++- libretroshare/src/pqi/pqissl.cc | 3 ++- libretroshare/src/pqi/pqissllistener.cc | 3 ++- libretroshare/src/pqi/pqisslpersongrp.cc | 4 ++-- libretroshare/src/pqi/pqisslproxy.cc | 3 ++- libretroshare/src/pqi/pqissludp.cc | 3 ++- libretroshare/src/pqi/pqistore.cc | 3 ++- libretroshare/src/pqi/pqistreamer.cc | 3 ++- libretroshare/src/rsserver/rsinit.cc | 4 ++-- libretroshare/src/services/p3msgservice.cc | 6 +++++- libretroshare/src/tcponudp/tcpstream.cc | 4 ++-- libretroshare/src/util/rsdebug.cc | 18 ++++++++--------- libretroshare/src/util/rsdebug.h | 23 +++++++++++----------- 19 files changed, 62 insertions(+), 45 deletions(-) diff --git a/libretroshare/src/pqi/p3linkmgr.cc b/libretroshare/src/pqi/p3linkmgr.cc index a7be8ecb6..2e58b8f4b 100644 --- a/libretroshare/src/pqi/p3linkmgr.cc +++ b/libretroshare/src/pqi/p3linkmgr.cc @@ -41,8 +41,6 @@ #include "util/rsprint.h" #include "util/rsdebug.h" #include "util/rsstring.h" -const int p3connectzone = 3431; - #include "serialiser/rsconfigitems.h" #include "retroshare/rsiface.h" @@ -52,6 +50,8 @@ const int p3connectzone = 3431; /* Network setup States */ +static struct RsLog::logInfo p3connectzoneInfo = {RsLog::Default, "p3connect"}; +#define p3connectzone &p3connectzoneInfo /**** * #define LINKMGR_DEBUG 1 diff --git a/libretroshare/src/pqi/p3netmgr.cc b/libretroshare/src/pqi/p3netmgr.cc index 501046f51..620175c25 100644 --- a/libretroshare/src/pqi/p3netmgr.cc +++ b/libretroshare/src/pqi/p3netmgr.cc @@ -39,7 +39,8 @@ //#include "util/rsprint.h" //#include "util/rsdebug.h" -const int p3netmgrzone = 7563; +struct RsLog::logInfo p3netmgrzoneInfo = {RsLog::Default, "p3netmgr"}; +#define p3netmgrzone &p3netmgrzoneInfo #include "serialiser/rsconfigitems.h" #include "retroshare/rsiface.h" diff --git a/libretroshare/src/pqi/p3peermgr.cc b/libretroshare/src/pqi/p3peermgr.cc index 4481e7a50..53ac4f12f 100644 --- a/libretroshare/src/pqi/p3peermgr.cc +++ b/libretroshare/src/pqi/p3peermgr.cc @@ -41,7 +41,6 @@ #include "util/rsprint.h" #include "util/rsstring.h" #include "util/rsdebug.h" -const int p3peermgrzone = 9531; #include "serialiser/rsconfigitems.h" @@ -64,6 +63,9 @@ const uint32_t MIN_TIME_BETWEEN_NET_RESET = 5; const uint32_t PEER_IP_CONNECT_STATE_MAX_LIST_SIZE = 4; +static struct RsLog::logInfo p3peermgrzoneInfo = {RsLog::Default, "p3peermgr"}; +#define p3peermgrzone &p3peermgrzoneInfo + /**** * #define PEER_DEBUG 1 ***/ diff --git a/libretroshare/src/pqi/pqihandler.cc b/libretroshare/src/pqi/pqihandler.cc index c9c87826b..718e877c1 100644 --- a/libretroshare/src/pqi/pqihandler.cc +++ b/libretroshare/src/pqi/pqihandler.cc @@ -58,7 +58,8 @@ static double getCurrentTS() } #endif -const int pqihandlerzone = 34283; +struct RsLog::logInfo pqihandlerzoneInfo = {RsLog::Default, "pqihandler"}; +#define pqihandlerzone &pqihandlerzoneInfo static const int PQI_HANDLER_NB_PRIORITY_LEVELS = 10 ; static const float PQI_HANDLER_NB_PRIORITY_RATIO = 2 ; diff --git a/libretroshare/src/pqi/pqinetwork.cc b/libretroshare/src/pqi/pqinetwork.cc index e0cb9af90..4937aef64 100644 --- a/libretroshare/src/pqi/pqinetwork.cc +++ b/libretroshare/src/pqi/pqinetwork.cc @@ -41,7 +41,8 @@ #include "util/rsstring.h" #include "util/rsnet.h" -static const int pqinetzone = 96184; +static struct RsLog::logInfo pqinetzoneInfo = {RsLog::Default, "pqinet"}; +#define pqinetzone &pqinetzoneInfo /***** * #define NET_DEBUG 1 diff --git a/libretroshare/src/pqi/pqiperson.cc b/libretroshare/src/pqi/pqiperson.cc index 5bfe49b8f..ea81c7f8c 100644 --- a/libretroshare/src/pqi/pqiperson.cc +++ b/libretroshare/src/pqi/pqiperson.cc @@ -27,13 +27,13 @@ #include "pqi/pqiperson.h" #include "pqi/pqipersongrp.h" #include "pqi/pqissl.h" - - -const int pqipersonzone = 82371; #include "util/rsdebug.h" #include "util/rsstring.h" #include "retroshare/rspeers.h" +static struct RsLog::logInfo pqipersonzoneInfo = {RsLog::Default, "pqiperson"}; +#define pqipersonzone &pqipersonzoneInfo + /**** * #define PERSON_DEBUG 1 ****/ @@ -67,7 +67,7 @@ int pqiperson::SendItem(RsItem *i,uint32_t& serialized_size) // check if debug output is wanted, to avoid unecessary work // getZoneLevel() locks a global mutex and does a lookup in a map or returns a default value // (not sure if this is a performance problem) - if (PQL_DEBUG_BASIC <= getZoneLevel(pqipersonzone)) + if (PQL_DEBUG_BASIC <= pqipersonzoneInfo.lvl) { std::string out = "pqiperson::SendItem() Active: Sending On\n"; i->print_string(out, 5); // this can be very expensive @@ -80,7 +80,7 @@ int pqiperson::SendItem(RsItem *i,uint32_t& serialized_size) } else { - if (PQL_DEBUG_BASIC <= getZoneLevel(pqipersonzone)) + if (PQL_DEBUG_BASIC <= pqipersonzoneInfo.lvl) { std::string out = "pqiperson::SendItem()"; out += " Not Active: Used to put in ToGo Store\n"; diff --git a/libretroshare/src/pqi/pqipersongrp.cc b/libretroshare/src/pqi/pqipersongrp.cc index 8ccd67442..a30eb2738 100644 --- a/libretroshare/src/pqi/pqipersongrp.cc +++ b/libretroshare/src/pqi/pqipersongrp.cc @@ -31,7 +31,8 @@ #include -const int pqipersongrpzone = 354; +static struct RsLog::logInfo pqipersongrpzoneInfo = {RsLog::Default, "pqipersongrp"}; +#define pqipersongrpzone &pqipersongrpzoneInfo #ifdef WINDOWS_SYS /////////////////////////////////////////////////////////// diff --git a/libretroshare/src/pqi/pqissl.cc b/libretroshare/src/pqi/pqissl.cc index 317963336..031cd2d7f 100644 --- a/libretroshare/src/pqi/pqissl.cc +++ b/libretroshare/src/pqi/pqissl.cc @@ -44,7 +44,8 @@ #include "rsserver/p3face.h" -const int pqisslzone = 37714; +static struct RsLog::logInfo pqisslzoneInfo = {RsLog::Default, "pqisslzone"}; +#define pqisslzone &pqisslzoneInfo /********* #define WAITING_NOT 0 diff --git a/libretroshare/src/pqi/pqissllistener.cc b/libretroshare/src/pqi/pqissllistener.cc index 2f6371801..189eb5dce 100644 --- a/libretroshare/src/pqi/pqissllistener.cc +++ b/libretroshare/src/pqi/pqissllistener.cc @@ -38,7 +38,8 @@ #include "retroshare/rsbanlist.h" #include -const int pqissllistenzone = 49787; +static struct RsLog::logInfo pqissllistenzoneInfo = {RsLog::Default, "p3peermgr"}; +#define pqissllistenzone &pqissllistenzoneInfo /* NB: This #define makes the listener open 0.0.0.0:X port instead * of a specific port - this might help retroshare work on PCs with diff --git a/libretroshare/src/pqi/pqisslpersongrp.cc b/libretroshare/src/pqi/pqisslpersongrp.cc index 898b28bb5..a1173fd93 100644 --- a/libretroshare/src/pqi/pqisslpersongrp.cc +++ b/libretroshare/src/pqi/pqisslpersongrp.cc @@ -29,8 +29,8 @@ #include "pqi/pqisslpersongrp.h" #include "pqi/authssl.h" - -const int pqipersongrpzone = 354; +static struct RsLog::logInfo pqipersongrpzoneInfo = {RsLog::Default, "pqipersongrp"}; +#define pqipersongrpzone &pqipersongrpzoneInfo /**** * #define PQI_DISABLE_UDP 1 diff --git a/libretroshare/src/pqi/pqisslproxy.cc b/libretroshare/src/pqi/pqisslproxy.cc index 9af132b4e..90444bcf9 100755 --- a/libretroshare/src/pqi/pqisslproxy.cc +++ b/libretroshare/src/pqi/pqisslproxy.cc @@ -38,7 +38,8 @@ #include "pqi/p3linkmgr.h" -const int pqisslproxyzone = 3517; +static struct RsLog::logInfo pqisslproxyzoneInfo = {RsLog::Default, "pqisslproxy"}; +#define pqisslproxyzone &pqisslproxyzoneInfo // #define PROXY_DEBUG 1 diff --git a/libretroshare/src/pqi/pqissludp.cc b/libretroshare/src/pqi/pqissludp.cc index 5b097fad3..9519e2af3 100644 --- a/libretroshare/src/pqi/pqissludp.cc +++ b/libretroshare/src/pqi/pqissludp.cc @@ -40,7 +40,8 @@ #include "pqi/p3linkmgr.h" #include -const int pqissludpzone = 3144; +static struct RsLog::logInfo pqissludpzoneInfo = {RsLog::Default, "pqissludp"}; +#define pqissludpzone &pqissludpzoneInfo /* a final timeout, to ensure this never blocks completely * 300 secs to complete udp/tcp/ssl connection. diff --git a/libretroshare/src/pqi/pqistore.cc b/libretroshare/src/pqi/pqistore.cc index 887c931eb..ca6d23820 100644 --- a/libretroshare/src/pqi/pqistore.cc +++ b/libretroshare/src/pqi/pqistore.cc @@ -53,7 +53,8 @@ // #define PQISTORE_DEBUG // -const int pqistorezone = 9511; +static struct RsLog::logInfo pqistorezoneInfo = {RsLog::Default, "pqistore"}; +#define pqistorezone &pqistorezoneInfo pqistore::pqistore(RsSerialiser *rss, const RsPeerId& srcId, BinInterface *bio_in, int bio_flags_in) :PQInterface(RsPeerId()), rsSerialiser(rss), bio_flags(bio_flags_in), diff --git a/libretroshare/src/pqi/pqistreamer.cc b/libretroshare/src/pqi/pqistreamer.cc index 6665a90c3..6e426107f 100644 --- a/libretroshare/src/pqi/pqistreamer.cc +++ b/libretroshare/src/pqi/pqistreamer.cc @@ -37,7 +37,8 @@ #include "serialiser/rsserial.h" -const int pqistreamerzone = 8221; +static struct RsLog::logInfo pqistreamerzoneInfo = {RsLog::Default, "pqistreamer"}; +#define pqistreamerzone &pqistreamerzoneInfo static const int PQISTREAM_ABS_MAX = 100000000; /* 100 MB/sec (actually per loop) */ static const int PQISTREAM_AVG_PERIOD = 5; // update speed estimate every 5 seconds diff --git a/libretroshare/src/rsserver/rsinit.cc b/libretroshare/src/rsserver/rsinit.cc index ab2c30dea..733009932 100644 --- a/libretroshare/src/rsserver/rsinit.cc +++ b/libretroshare/src/rsserver/rsinit.cc @@ -221,7 +221,7 @@ void RsInit::InitRsConfig() /* Setup the Debugging */ // setup debugging for desired zones. - setOutputLevel(PQL_WARNING); // default to Warnings. + setOutputLevel(RsLog::Warning); // default to Warnings. // For Testing purposes. // We can adjust everything under Linux. @@ -418,7 +418,7 @@ int RsInit::InitRetroShare(int argcIgnored, char **argvIgnored, bool strictCheck } #endif - setOutputLevel(rsInitConfig->debugLevel); + setOutputLevel((RsLog::logLvl)rsInitConfig->debugLevel); // // set the default Debug Level... // if (rsInitConfig->haveDebugLevel) diff --git a/libretroshare/src/services/p3msgservice.cc b/libretroshare/src/services/p3msgservice.cc index 063d98c3e..57c13f4e8 100644 --- a/libretroshare/src/services/p3msgservice.cc +++ b/libretroshare/src/services/p3msgservice.cc @@ -67,7 +67,11 @@ using namespace Rs::Msgs; -const int msgservicezone = 54319; +static struct RsLog::logInfo msgservicezoneInfo = { + .lvl = RsLog::Default, + .name = "msgservice" +}; +#define msgservicezone &msgservicezoneInfo static const uint32_t RS_MSG_DISTANT_MESSAGE_HASH_KEEP_TIME = 2*30*86400 ; // keep msg hashes for 2 months to avoid re-sent msgs diff --git a/libretroshare/src/tcponudp/tcpstream.cc b/libretroshare/src/tcponudp/tcpstream.cc index 6e2f3b01b..d789def44 100644 --- a/libretroshare/src/tcponudp/tcpstream.cc +++ b/libretroshare/src/tcponudp/tcpstream.cc @@ -43,8 +43,8 @@ #include "util/rsstring.h" #include "util/rsrandom.h" -const int rstcpstreamzone = 28455; - +static struct RsLog::logInfo rstcpstreamzoneInfo = {RsLog::Default, "rstcpstream"}; +#define rstcpstreamzone &rstcpstreamzoneInfo /* * #define DEBUG_TCP_STREAM 1 diff --git a/libretroshare/src/util/rsdebug.cc b/libretroshare/src/util/rsdebug.cc index e2536a7cb..d8216d009 100644 --- a/libretroshare/src/util/rsdebug.cc +++ b/libretroshare/src/util/rsdebug.cc @@ -160,11 +160,11 @@ int locked_setDebugFile(const char *fname) } } -//int setOutputLevel(RsLog::logLvl lvl) -//{ -// RsStackMutex stack(logMtx); /******** LOCKED ****************/ -// return defaultLevel = lvl; -//} +int setOutputLevel(RsLog::logLvl lvl) +{ + RsStackMutex stack(logMtx); /******** LOCKED ****************/ + return defaultLevel = lvl; +} //#ifdef deadcode // this code is not used by RS //int setZoneLevel(int lvl, int zone) @@ -194,7 +194,7 @@ int locked_setDebugFile(const char *fname) // return defaultLevel; //} -void rslog(const RsLog::logLvl lvl, const RsLog::logInfo *info, const std::string &msg) +void rslog(const RsLog::logLvl lvl, RsLog::logInfo *info, const std::string &msg) { // skipp when log level is set to 'None' // NB: when default is set to 'None' the later check will always fail -> no need to check it here @@ -203,7 +203,7 @@ void rslog(const RsLog::logLvl lvl, const RsLog::logInfo *info, const std::strin RsStackMutex stack(logMtx); /******** LOCKED ****************/ - bool process = info-lvl == RsLog::Default ? (lvl <= defaultLevel) : lvl <= info->lvl; + bool process = info->lvl == RsLog::Default ? (lvl <= defaultLevel) : lvl <= info->lvl; if(process) { time_t t = time(NULL); @@ -235,8 +235,8 @@ void rslog(const RsLog::logLvl lvl, const RsLog::logInfo *info, const std::strin std::string timestr = ctime(&t); std::string timestr2 = timestr.substr(0,timestr.length()-1); /* remove the endl */ - fprintf(ofd, "(%s Z: %d, lvl:%u): %s \n", - timestr2.c_str(), zone, (unsigned int)info->lvl, msg.c_str()); + fprintf(ofd, "(%s Z: %s, lvl: %u): %s \n", + timestr2.c_str(), info->name.c_str(), (unsigned int)info->lvl, msg.c_str()); fflush(ofd); lineCount++; } diff --git a/libretroshare/src/util/rsdebug.h b/libretroshare/src/util/rsdebug.h index 1d8f3cae0..e1bafcda8 100644 --- a/libretroshare/src/util/rsdebug.h +++ b/libretroshare/src/util/rsdebug.h @@ -30,14 +30,6 @@ #ifndef RS_LOG_DEBUG_H #define RS_LOG_DEBUG_H -#define RSL_NONE -1 -#define RSL_ALERT 1 -#define RSL_ERROR 3 -#define RSL_WARNING 5 -#define RSL_DEBUG_ALERT 6 -#define RSL_DEBUG_BASIC 8 -#define RSL_DEBUG_ALL 10 - #include namespace RsLog { @@ -54,13 +46,22 @@ namespace RsLog { // this struct must be provided by the caller (to rslog()) struct logInfo { - // module name - const std::string name; // module specific log lvl logLvl lvl; + // module name + const std::string name; }; } +// current RS code uses these (deprecated) defines +#define RSL_NONE RsLog::None +#define RSL_ALERT RsLog::Alert +#define RSL_ERROR RsLog::Error +#define RSL_WARNING RsLog::Warning +#define RSL_DEBUG_ALERT RsLog::Debug_Alert +#define RSL_DEBUG_BASIC RsLog::Debug_Basic +#define RSL_DEBUG_ALL RsLog::Debug_Basic + int setDebugCrashMode(const char *cfile); //int clearDebugCrashLog(); @@ -68,7 +69,7 @@ int setDebugFile(const char *fname); int setOutputLevel(RsLog::logLvl lvl); //int setZoneLevel(int lvl, int zone); //int getZoneLevel(int zone); -void rslog(const RsLog::logLvl lvl, const RsLog::logInfo *info, const std::string &msg); +void rslog(const RsLog::logLvl lvl, RsLog::logInfo *info, const std::string &msg); From d8235c6caf33b37a970cd519b2d821b046258020 Mon Sep 17 00:00:00 2001 From: sehraf Date: Sat, 18 Jun 2016 13:08:14 +0200 Subject: [PATCH 4/5] removed dead code and cleanup --- libretroshare/src/util/rsdebug.cc | 56 ------------------------------- libretroshare/src/util/rsdebug.h | 24 +++++-------- 2 files changed, 9 insertions(+), 71 deletions(-) diff --git a/libretroshare/src/util/rsdebug.cc b/libretroshare/src/util/rsdebug.cc index d8216d009..ab40c3035 100644 --- a/libretroshare/src/util/rsdebug.cc +++ b/libretroshare/src/util/rsdebug.cc @@ -37,7 +37,6 @@ const int RS_DEBUG_LOGCRASH = 3; /* minimal logfile stored after crashes */ const int RS_DEBUG_LOGC_MAX = 100000; /* max length of crashfile log */ const int RS_DEBUG_LOGC_MIN_SAVE = 100; /* min length of crashfile log */ -//static std::map zoneLevel; static RsLog::logLvl defaultLevel = RsLog::Warning; static FILE *ofd = stderr; @@ -110,33 +109,6 @@ int setDebugCrashMode(const char *cfile) return 1; } - -#ifdef deadcode // this code is not used by RS -/* this is called when we exit normally */ -int clearDebugCrashLog() -{ - RsStackMutex stack(logMtx); /******** LOCKED ****************/ - /* check we are in crashLog Mode */ - if (debugMode != RS_DEBUG_LOGCRASH) - { - fprintf(stderr, "Not in CrashLog Mode - nothing to clear!\n"); - return 1; - } - - fprintf(stderr, "clearDebugCrashLog() Cleaning up\n"); - /* shutdown crashLog Mode */ - fclose(ofd); - ofd = stderr; - debugMode = RS_DEBUG_STDERR; - - /* just open the file, and then close */ - FILE *tmpin = RsDirUtil::rs_fopen(crashfile.c_str(), "w"); - fclose(tmpin); - - return 1; -} -#endif - int setDebugFile(const char *fname) { RsStackMutex stack(logMtx); /******** LOCKED ****************/ @@ -166,34 +138,6 @@ int setOutputLevel(RsLog::logLvl lvl) return defaultLevel = lvl; } -//#ifdef deadcode // this code is not used by RS -//int setZoneLevel(int lvl, int zone) -//{ -// RsStackMutex stack(logMtx); /******** LOCKED ****************/ -// zoneLevel[zone] = lvl; -// return zone; -//} -//#endif - -//int getZoneLevel(int zone) -//{ -// RsStackMutex stack(logMtx); /******** LOCKED ****************/ -// return locked_getZoneLevel(zone); -//} - -//int locked_getZoneLevel(int /*zone*/) -//{ -//#ifdef deadcode // this code is not used by RS -// std::map::iterator it = zoneLevel.find(zone); -// if (it == zoneLevel.end()) -// { -// return defaultLevel; -// } -// return it -> second; -//#endif -// return defaultLevel; -//} - void rslog(const RsLog::logLvl lvl, RsLog::logInfo *info, const std::string &msg) { // skipp when log level is set to 'None' diff --git a/libretroshare/src/util/rsdebug.h b/libretroshare/src/util/rsdebug.h index e1bafcda8..abf39e4b0 100644 --- a/libretroshare/src/util/rsdebug.h +++ b/libretroshare/src/util/rsdebug.h @@ -48,35 +48,29 @@ namespace RsLog { struct logInfo { // module specific log lvl logLvl lvl; - // module name + // module name (displayed in log) const std::string name; }; } -// current RS code uses these (deprecated) defines -#define RSL_NONE RsLog::None -#define RSL_ALERT RsLog::Alert -#define RSL_ERROR RsLog::Error -#define RSL_WARNING RsLog::Warning -#define RSL_DEBUG_ALERT RsLog::Debug_Alert -#define RSL_DEBUG_BASIC RsLog::Debug_Basic -#define RSL_DEBUG_ALL RsLog::Debug_Basic - int setDebugCrashMode(const char *cfile); -//int clearDebugCrashLog(); - int setDebugFile(const char *fname); int setOutputLevel(RsLog::logLvl lvl); -//int setZoneLevel(int lvl, int zone); -//int getZoneLevel(int zone); void rslog(const RsLog::logLvl lvl, RsLog::logInfo *info, const std::string &msg); - /* * retaining old #DEFINES and functions for backward compatibility. */ +#define RSL_NONE RsLog::None +#define RSL_ALERT RsLog::Alert +#define RSL_ERROR RsLog::Error +#define RSL_WARNING RsLog::Warning +#define RSL_DEBUG_ALERT RsLog::Debug_Alert +#define RSL_DEBUG_BASIC RsLog::Debug_Basic +#define RSL_DEBUG_ALL RsLog::Debug_Basic + //int pqioutput(unsigned int lvl, int zone, std::string msg); #define pqioutput rslog From 3cf1968943eb1a30a1f514c986c4a1567d20fc9b Mon Sep 17 00:00:00 2001 From: sehraf Date: Sat, 18 Jun 2016 18:04:18 +0200 Subject: [PATCH 5/5] fixed p3msgservice.cc --- libretroshare/src/services/p3msgservice.cc | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/libretroshare/src/services/p3msgservice.cc b/libretroshare/src/services/p3msgservice.cc index 57c13f4e8..d64c020d6 100644 --- a/libretroshare/src/services/p3msgservice.cc +++ b/libretroshare/src/services/p3msgservice.cc @@ -67,10 +67,7 @@ using namespace Rs::Msgs; -static struct RsLog::logInfo msgservicezoneInfo = { - .lvl = RsLog::Default, - .name = "msgservice" -}; +static struct RsLog::logInfo msgservicezoneInfo = {RsLog::Default, "msgservice"}; #define msgservicezone &msgservicezoneInfo static const uint32_t RS_MSG_DISTANT_MESSAGE_HASH_KEEP_TIME = 2*30*86400 ; // keep msg hashes for 2 months to avoid re-sent msgs