#ifndef GledCore_ZLog_H
#define GledCore_ZLog_H
#include <Glasses/ZGlass.h>
#include <Gled/GCondition.h>
#include <Gled/GTime.h>
#include <fstream>
#include <stdarg.h>
class GThread;
class ZLog : public ZGlass
{
MAC_RNR_FRIENDS(ZLog);
public:
enum Level_e
{
L_Fatal, L_Error, L_Warning, L_Message, L_Info, L_Debug
};
class Helper
{
ZLog *m_log;
GTime m_time;
TString m_time_string;
TString m_prefix;
Int_t m_level;
public:
Helper(ZLog* log, const TString& pfx="");
Helper(ZLog* log, Int_t lvl, const TString& pfx="");
Helper(ZLog* log, const GTime& when, const TString& pfx="");
Helper(ZLog* log, const GTime& when, Int_t lvl, const TString& pfx="");
void SetTime(const GTime& time);
void Put(const TString& message);
void Put(Int_t level, const TString& message);
void Form(const char* fmt, ...);
void Form(Int_t level, const char* fmt, ...);
};
struct Message
{
GTime m_when;
TString m_prefix;
TString m_message;
Int_t m_level;
};
private:
void _init();
protected:
TString mFileName;
Level_e mLevel;
Int_t mDebugLevel;
Bool_t bLogActive;
GCondition mLoggerCond;
GThread *mLoggerThread;
ofstream mStream;
static void tl_LogLoop(ZLog* log);
void LogLoop();
public:
ZLog(const Text_t* n="ZLog", const Text_t* t=0);
virtual ~ZLog();
void StartLogging();
void StopLogging();
void RotateLog();
void Put(Int_t level, const TString& prefix, const TString& message);
void Put(const GTime& time, Int_t level, const TString& prefix, const TString& message);
void Put(const TString& time_string, Int_t level, const TString& prefix, const TString& message);
void Form(Int_t level, const TString& prefix, const char* fmt, ...);
void Form(const GTime& time, Int_t level, const TString& prefix, const char* fmt, ...);
void Form(const TString& time_string, Int_t level, const TString& prefix, const char* fmt, ...);
void FormVA(const GTime& time, Int_t level, const TString& prefix, const char* fmt, va_list args);
void FormVA(const TString& time_string, Int_t level, const TString& prefix, const char* fmt, va_list args);
#include "ZLog.h7"
ClassDef(ZLog, 1);
};
#endif