#ifndef __TMrbLogger_h__
#define __TMrbLogger_h__
namespace std {} using namespace std;
#include <cstdlib>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <fstream>
#include "TObject.h"
#include "TNamed.h"
#include "TSystem.h"
#include "TObjArray.h"
#include "TDatime.h"
#include "RQ_OBJECT.h"
class TMrbLogMessage: public TObject {
public:
enum EMrbMsgType { kMrbMsgMessage = BIT(0),
kMrbMsgError = BIT(1),
kMrbMsgWarning = BIT(2),
kMrbMsgAny = kMrbMsgMessage | kMrbMsgError | kMrbMsgWarning
};
public:
TMrbLogMessage() {};
TMrbLogMessage(EMrbMsgType Type, const Char_t * Color,
const Char_t * ClassName, const Char_t * Method, const Char_t * Text, Bool_t Indent = kFALSE);
~TMrbLogMessage() {};
inline UInt_t GetDatime() const { return(fDatime.Get()); };
inline EMrbMsgType GetType() const { return(fType); };
inline const Char_t * GetColor() const { return(fColor.Data()); };
inline const Char_t * GetClassName() const { return(fClassName.Data()); };
inline const Char_t * GetMethod() const { return(fMethod.Data()); };
inline const Char_t * GetText() const { return(fText.Data()); };
const Char_t * Get(TString & FmtMsg,
const Char_t * ProgName,
Bool_t WithDate = kFALSE,
Bool_t WithColors = kTRUE) const;
inline void Help() { gSystem->Exec(Form("mrbHelp %s", this->ClassName())); };
protected:
Bool_t fIndent;
TDatime fDatime;
EMrbMsgType fType;
TString fColor;
TString fClassName;
TString fMethod;
TString fText;
ClassDef(TMrbLogMessage, 1)
};
class TMrbLogger: public TNamed {
RQ_OBJECT("TMrbLogger")
public:
enum EMrbMsgRoute { kMrbMsgCout = BIT(0),
kMrbMsgCerr = BIT(1),
kMrbMsgLog = BIT(2)
};
enum EMrbMsgFileMode { kMrbMsgFileNew,
kMrbMsgFileAppend
};
public:
TMrbLogger(const Char_t * LogFile = "marabou.log", const Char_t * ProgName = "");
~TMrbLogger() { Reset(); };
Bool_t Flush(const Char_t * ClassNameL = "", const Char_t * Method = "", const Char_t * Color = NULL, Bool_t Indent = kFALSE);
Bool_t Open(const Char_t * LogFile = "marabou.log", const Char_t * Option = "APPEND");
Bool_t Close();
void SetProgName(const Char_t * ProgName);
inline const Char_t * GetProgName() const { return(fProgName.Data()); };
Int_t GetNofEntries(UInt_t Type = TMrbLogMessage::kMrbMsgAny) const;
inline Int_t GetEntries(TObjArray & MsgArr, Int_t Start = 0) const { return(GetEntriesByType(MsgArr, Start, TMrbLogMessage::kMrbMsgAny)); };
inline Int_t GetMessages(TObjArray & MsgArr, Int_t Start = 0) const { return(GetEntriesByType(MsgArr, Start, TMrbLogMessage::kMrbMsgMessage)); };
inline Int_t GetErrors(TObjArray & MsgArr, Int_t Start = 0) const { return(GetEntriesByType(MsgArr, Start, TMrbLogMessage::kMrbMsgError)); };
inline Int_t GetWarnings(TObjArray & MsgArr, Int_t Start = 0) const { return(GetEntriesByType(MsgArr, Start, TMrbLogMessage::kMrbMsgWarning)); };
inline Int_t GetEntriesSinceLastCall(TObjArray & MsgArr) const { return(GetEntries(MsgArr, fIndexOfLastPrinted)); };
inline Int_t GetMessagesSinceLastCall(TObjArray & MsgArr) const { return(GetMessages(MsgArr, fIndexOfLastPrinted)); };
inline Int_t GetErrorsSinceLastCall(TObjArray & MsgArr) const { return(GetErrors(MsgArr, fIndexOfLastPrinted)); };
inline Int_t GetWarningsSinceLastCall(TObjArray & MsgArr) const { return(GetWarnings(MsgArr, fIndexOfLastPrinted)); };
Int_t GetEntriesByType(TObjArray & MsgArr, Int_t Start = 0, UInt_t Type = TMrbLogMessage::kMrbMsgAny) const;
TMrbLogMessage * GetLast(const Char_t * Option = "*") const;
TMrbLogMessage * GetLast(UInt_t Type) const;
inline UInt_t Enable(UInt_t Bits) { fEnabled |= Bits; return(fEnabled); };
inline UInt_t Disable(UInt_t Bits) { fEnabled &= ~Bits; return(fEnabled); };
void Print(Option_t * Option) const { TObject::Print(Option); }
void Print(Int_t Tail = 0, const Char_t * Option = "*") const;
void Print(Int_t Tail, UInt_t Type) const;
void PrintSinceLastCall(const Char_t * Option = "Error");
void PrintSinceLastCall(UInt_t Type);
inline void Reset() {
fIndexOfLastPrinted = 0;
};
inline Int_t GetIndexOfLastPrinted() const { return(fIndexOfLastPrinted); };
const Char_t * Prefix(const Char_t * Identifier = "*", const Char_t * ProgName = NULL);
inline Bool_t Out(const Char_t * Msg, const Char_t * ClassNameL = "", const Char_t * Method = "", const Char_t * Color = NULL) {
return(this->OutputMessage(TMrbLogMessage::kMrbMsgMessage, Msg, ClassNameL, Method, Color));
};
inline Bool_t Err(const Char_t * Msg, const Char_t * ClassNameL = "", const Char_t * Method = "", const Char_t * Color = NULL) {
return(this->OutputMessage(TMrbLogMessage::kMrbMsgError, Msg, ClassNameL, Method, Color));
};
inline Bool_t Wrn(const Char_t * Msg, const Char_t * ClassNameL = "", const Char_t * Method = "", const Char_t * Color = NULL) {
return(this->OutputMessage(TMrbLogMessage::kMrbMsgWarning, Msg, ClassNameL, Method, Color));
};
inline ostringstream & Out() { return(*fOut); };
inline ostringstream & Err() { return(*fErr); };
inline ostringstream & Wrn() { return(*fWrn); };
inline ofstream & Log() { return(*fLog); };
inline void Help() { gSystem->Exec(Form("mrbHelp %s", this->ClassName())); };
protected:
Bool_t OutputMessage(TMrbLogMessage::EMrbMsgType MsgType, const Char_t * Msg,
const Char_t * ClassNameL = "", const Char_t * Method = "", const Char_t * Color = NULL, Bool_t Indent = kFALSE);
protected:
TString fLogFile;
TString fProgName;
TString fPrefix;
UInt_t fEnabled;
ofstream * fLog;
ostringstream * fOut;
ostringstream * fErr;
ostringstream * fWrn;
Int_t fIndexOfLastPrinted;
TObjArray fLofMessages;
ClassDef(TMrbLogger, 1)
};
#endif