#ifndef GLTB_LOGGING_H #define GLTB_LOGGING_H #include #include #include #include namespace gltb { #ifdef WIN32 #define THREAD __declspec(thread) #else #define THREAD __thread #endif enum Channel { Console = 0, SysLog, File, Callback, #ifdef WIN32 DebugString #endif }; enum Marker { EndL = 0, Flush, }; enum LogLevel { LogNone = 0, LogCritical, LogError, LogWarning, LogInfo, LogDebug, LogDetail }; class Config { public: Config(); Config(LogLevel level,bool enabled,bool prefix); LogLevel level; bool enabled; bool prefix; }; class LogCallback { public: virtual ~LogCallback() {}; virtual void log(LogLevel level,const std::string &line) = 0; }; class Stream { private: typedef struct _PerThread { std::stringstream *streamPtr; LogLevel lineLevel; bool newLine; } PerThread; std::map channels; std::list callbackList; std::ofstream fileStream; PerThread *perThread(void); public: Stream(); ~Stream(); bool setFileChannel(std::string fileName); bool setFileChannel(const char *fileNamePtr); void addCallbackChannel(LogCallback *callbackPtr); void removeCallbackChannel(LogCallback *callbackPtr); bool outChannel(Channel channel,LogLevel level,bool enable,bool prefix); void endLine(void); void flush(void); Stream &operator<<(Marker marker); Stream &operator<<(LogLevel level); Stream &operator<<(long long integerOut); Stream &operator<<(unsigned long long unsignedIntegerOut); Stream &operator<<(long integerOut); Stream &operator<<(unsigned long unsignedIntegerOut); Stream &operator<<(int integerOut); Stream &operator<<(unsigned int unsignedIntegerOut); Stream &operator<<(float doubleOut); Stream &operator<<(double doubleOut); Stream &operator<<(std::string stringOut); static Stream &log(void); static void detachThread(void); static void detachProcess(void); }; extern void dumpBinary(Stream &stream, LogLevel lineLevel, void *binaryPtr, int length); extern std::string logLevelToString(LogLevel level); extern LogLevel stringToLogLevel(std::string str); extern std::string channelToString(Channel channel); extern Channel stringToChannel(std::string channelName); } #endif