runs, prints right in reciever

This commit is contained in:
2018-10-30 13:35:20 +01:00
parent 92fc837eb4
commit dfa8cf7381
32 changed files with 1058 additions and 1138 deletions

View File

@ -36,8 +36,9 @@
inline std::string NowTime();
enum TLogLevel {logERROR, logWARNING, logINFO, logDEBUG, logDEBUG1, logDEBUG2, logDEBUG3, logDEBUG4, logDEBUG5};
// 1 normal debug, 3 function names, 5 fifodebug
enum TLogLevel {logERROR, logWARNING, logINFOBLUE, logINFOGREEN, logINFORED, logINFO,
logDEBUG, logDEBUG1, logDEBUG2, logDEBUG3, logDEBUG4, logDEBUG5};
template <typename T> class Log{
public:
@ -63,20 +64,11 @@ public:
static void Output(const std::string& msg, TLogLevel level);
};
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__)
# if defined (BUILDING_FILELOG_DLL)
# define FILELOG_DECLSPEC __declspec (dllexport)
# elif defined (USING_FILELOG_DLL)
# define FILELOG_DECLSPEC __declspec (dllimport)
# else
# define FILELOG_DECLSPEC
# endif // BUILDING_DBSIMPLE_DLL
#else
# define FILELOG_DECLSPEC
#endif // _WIN32
#define FILELOG_DECLSPEC
class FILELOG_DECLSPEC FILELog : public Log<Output2FILE> {};
//typedef Log<Output2FILE> FILELog;
#define FILE_LOG(level) \
if (level > FILELOG_MAX_LEVEL) ; \
@ -84,29 +76,6 @@ class FILELOG_DECLSPEC FILELog : public Log<Output2FILE> {};
else FILELog().Get(level)
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__)
#include <windows.h>
inline std::string NowTime()
{
const int MAX_LEN = 200;
char buffer[MAX_LEN];
if (GetTimeFormatA(LOCALE_USER_DEFAULT, 0, 0,
"HH':'mm':'ss", buffer, MAX_LEN) == 0)
return "Error in NowTime()";
char result[100] = {0};
static DWORD first = GetTickCount();
sprintf(result, "%s.%03ld", buffer, (long)(GetTickCount() - first) % 1000);
return result;
}
#else
#include <sys/time.h>
inline std::string NowTime()
@ -127,8 +96,6 @@ inline std::string NowTime()
return result;
}
#endif //WIN32
template <typename T> Log<T>::Log():lev(logDEBUG){}
@ -138,7 +105,7 @@ template <typename T> std::ostringstream& Log<T>::Get(TLogLevel level)
os << "- " << NowTime();
os << " " << ToString(level) << ": ";
if (level > logDEBUG)
os << std::string(level - logDEBUG, '\t');
os << std::string(level - logDEBUG, ' ');
return os;
}
@ -156,7 +123,9 @@ template <typename T> TLogLevel& Log<T>::ReportingLevel()
template <typename T> std::string Log<T>::ToString(TLogLevel level)
{
static const char* const buffer[] = {"ERROR", "WARNING", "INFO", "DEBUG", "DEBUG1", "DEBUG2", "DEBUG3", "DEBUG4","DEBUG5"};
static const char* const buffer[] = {
"ERROR", "WARNING", "INFO", "INFO", "INFO", "INFO",
"DEBUG", "DEBUG1", "DEBUG2", "DEBUG3", "DEBUG4","DEBUG5"};
return buffer[level];
}
@ -211,21 +180,10 @@ inline void Output2FILE::Output(const std::string& msg, TLogLevel level)
case logERROR: cprintf(RED BOLD,"%s",msg.c_str()); break;
case logWARNING: cprintf(YELLOW BOLD,"%s",msg.c_str()); break;
case logINFO: cprintf(RESET,"%s",msg.c_str()); break;
case logINFOBLUE: cprintf(BLUE,"%s",msg.c_str()); break;
case logINFORED: cprintf(RED,"%s",msg.c_str()); break;
case logINFOGREEN: cprintf(GREEN,"%s",msg.c_str()); break;
default: fprintf(pStream,"%s",msg.c_str()); out = false; break;
}
fflush(out ? stdout : pStream);
}
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__)
# if defined (BUILDING_FILELOG_DLL)
# define FILELOG_DECLSPEC __declspec (dllexport)
# elif defined (USING_FILELOG_DLL)
# define FILELOG_DECLSPEC __declspec (dllimport)
# else
# define FILELOG_DECLSPEC
# endif // BUILDING_DBSIMPLE_DLL
#else
# define FILELOG_DECLSPEC
#endif // _WIN32