// Author: Juan Carlos De Abreu (jcabreur@gmail.com)
//
// This file define a class to report to a log events, errors, warnings, etc.

#ifndef BASE_LOG_MANAGEMENT_H__
#define BASE_LOG_MANAGEMENT_H__

#include "../global.h"
#include "../Util/string.h"
//#include "../Includes/Basic.h"
#include "Singleton.h"

BEGIN_TEG_NAMESPACE();

// Defines of the diferents output 
#define LOG_FILE_OUTPUT			0x00000001
#define LOG_STANDARD_OUTPUT		0x00000002
#define LOG_USER_OUTPUT			0x00000004		// Console inside the application

// 0 - no debugging wanted
// 1 - very basic debug output
// 2 - comprehensive debug output
// 3 - all output, and a transcript of all message
#ifdef _DEBUG
//	#define SYSTEM_DEBUG_LEVEL 2
//	#define SYSTEM_DEBUG_LEVEL 3
#else
//	#define SYSTEM_DEBUG_LEVEL 1
//	#define SYSTEM_DEBUG_LEVEL 0
#endif 

#define SYSTEM_DEBUG_LEVEL 3

#if SYSTEM_DEBUG_LEVEL == 3
	// Enable all macros
//	#define PRINT_LOG_L1()
//	#define PRINT_LOG_L2()
//	#define PRINT_LOG_L3()

#elif SYSTEM_DEBUG_LEVEL == 2
	// Enable levels 1..2 macros
#elif SYSTEM_DEBUG_LEVEL == 1
	// Enable level 1 macro
#else 
	// Disable all macros
#endif

// Define the type of event in the log
#define TYPE_EVENT _T("Event")
#define TYPE_ERROR _T("Error")
#define TYPE_DEBUG	_T("Debug")
#define TYPE_WARNING _T("Warning")
#define TYPE_COMMENT _T("Comment")
#define TYPE_UNKNOWN _T("Unknown")
#define TYPE_MESSAGE _T("App Message")

// Define to activate the messages of the log ... ()
//#define LOG_ENABLE

// Define the log output
#define LOG_OUTPUT	LOG_FILE_OUTPUT //LOG_STANDARD_OUTPUT

// Macro to print a message in the log
#ifdef LOG_ENABLE
	#define SHOW_LOG() DebugApplication::LogManagement::GetInstance().ShowLog()
	#define PRINT_LOG(lineType, msg, ...) \
		DebugApplication::LogManagement::GetInstance().WriteLog2( \
			lineType, \
			__FILE__, \
			__FUNCTION__, \
			__LINE__, \
			msg, \
			__VA_ARGS__ \
		)
#else
	#define SHOW_LOG()						// Do anything ...
	#define PRINT_LOG(lineType, msg, ...)	// Do anything ...
#endif

// Definition of the namespace of the
namespace DebugApplication {

// Definition of the structure of Debug Management
class LogManagement : public Singleton<LogManagement> {
 public:
  // LogManagement constructor and destructor.
  LogManagement();
  ~LogManagement();

  // Method's
  void ShowLog();										// Method to show the Log
  void InitializeLog();								// Method to Initialize the Log
  void WriteLog(const _TCHAR* message, ...);			// Method to write a message in the Log
  void SetLogPathName(const _TCHAR* lpszPathName);	// Method to set the Log pathName

  void WriteLog2(std::tstring strEntryType, std::tstring strSourceFile,
      std::tstring strFunction, int iSourceLine, const _TCHAR*message, ...);

 protected: 
  // Attributes
  int nEvents; // Number of events in registered in the log.
  std::tstring m_lpszPathName;						// Log file pathName

 private:
  DISALLOW_COPY_AND_ASSIGN(LogManagement);
};

};	// namespace

END_TEG_NAMESPACE();

#endif  // BASE_LOG_MANAGEMENT_H__
