mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-10-01 02:35:48 -04:00
switched to caller providing all needed information instead of saving those on callee side
This commit is contained in:
parent
e28e9720dd
commit
f6c5a05c8e
@ -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<int, int> zoneLevel;
|
||||
static int defaultLevel = RSL_WARNING;
|
||||
//static std::map<int, int> 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<int, int>::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<int, int>::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;
|
||||
}
|
||||
|
||||
|
||||
|
@ -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 <string>
|
||||
|
||||
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);
|
||||
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user