#if !defined(_TRACER_H)
#define _TRACER_H

#include "PubHeader.h"
#include "LogFile.h"

#define _TRACER_ON_

////////////////////////////
#ifdef _TRACER_ON_

#define TRACE_FLUSH()           Tracer::inst()->Flush()
#define TRACE0a_(sz,bAddLR)     Tracer::inst()->TRACE_(sz,bAddLR)
#define TRACE0_(sz)             Tracer::inst()->TRACE_(sz)
#define TRACE1_(sz,p1)          Tracer::inst()->TRACE_M(sz,p1)
#define TRACE2_(sz,p1,p2)       Tracer::inst()->TRACE_M(sz,p1,p2)
#define TRACE3_(sz,p1,p2,p3)    Tracer::inst()->TRACE_M(sz,p1,p2,p3)
#define TRACE4_(sz,p1,p2,p3,p4) Tracer::inst()->TRACE_M(sz,p1,p2,p3,p4)

#else

#define TRACE_FLUSH()          
#define TRACE0_(sz)        
#define TRACE1_(sz,p1)     
#define TRACE2_(sz,p1,p2)  
#define TRACE3_(sz,p1,p2,p3)
#define TRACE4_(sz,p1,p2,p3,p4)

#endif

//////////////////////////////////////////////////////////////
#ifdef _DLL_PROJECT
class CLASS_EXPORT Tracer
#else
class Tracer
#endif
{
public:
    Tracer();	
   ~Tracer();	
    
    static Tracer *inst(void);
    
    bool open (void* pParent,char* szLogFileTitle=NULL);
    void close(void);

    void setTraceFlag(bool bLogOn,bool bPrintOn);
    
    void TRACE_M(const char* pszFormat, ...);
    void TRACE_(char* szInfo,bool bAddLR=true);
    void Flush(); // SAVE DATA IN BUFFER TO LOG FILE
    
    virtual void EnterLock() { };
    virtual void LeaveLock() { };
    
protected:
    void*        m_pParent;
    CLogFileEx*	 m_pLogFile;
    bool         m_bLogOn;      // default: false
    bool         m_bPrintOn;    // default: true

    virtual void Print_(const char* szInfo);
    
private:
    static Tracer	*instance_;	    //!< Singleton instance pointer.
};


#endif
