/*
 * LSC_Logger.h
 *
 *  Created on: 2014-4-10
 *      Author: sj
 */

#ifndef LSC_LOGGER_H_
#define LSC_LOGGER_H_

#include <ace/Log_Msg.h>
#include <ace/streams.h>
#include <ace/SOCK_Dgram.h>
#include <ace/Singleton.h>
#include <ace/Recursive_Thread_Mutex.h>

#include <string>
using namespace std;

#undef  ACE_NTRACE
#define ACE_NTRACE 0

class LSC_ProcessExitLog : public ACE_Cleanup {
public:
	void cleanup (void *param = 0);
};

class LSC_Logger {
public:
	/// A do nothing constructor.
	LSC_Logger();

	/// Virtual destruction
	virtual ~LSC_Logger();

	int open(string process_name,string log_leave);
	int set_log_leave(string log_leave);
	ACE_Log_Priority get_log_leave();

private:
	ACE_Log_Priority curr_log_leave;
};

typedef ACE_Singleton<LSC_Logger, ACE_Recursive_Thread_Mutex> LSC_LOGGER;


#define DEBUG_PREFIX        ACE_TEXT ("DEBUG   %P %t %D %N:%l# ")
#define INFO_PREFIX         ACE_TEXT ("INFO    %P %t %D %N:%l# ")
#define NOTICE_PREFIX       ACE_TEXT ("NOTICE  %P %t %D %N:%l# ")
#define WARNING_PREFIX      ACE_TEXT ("WARNING %P %t %D %N:%l# ")
#define ERROR_PREFIX        ACE_TEXT ("ERROR   %P %t %D %N:%l# ")
#define CRITICAL_PREFIX     ACE_TEXT ("CRITICAL%P %t %D %N:%l# ")
#define ALERT_PREFIX        ACE_TEXT ("ALERT   %P %t %D %N:%l# ")
#define EMERGENCY_PREFIX    ACE_TEXT ("EMERGENC%P %t %D %N:%l# ")

#define LOGD(FMT, ...) \
	do {\
		ACE_DEBUG((LM_DEBUG, DEBUG_PREFIX ACE_TEXT(FMT), ## __VA_ARGS__));\
    } while(0);

#define LOGI(FMT, ...) \
	do {\
		ACE_DEBUG((LM_INFO, INFO_PREFIX ACE_TEXT(FMT), ## __VA_ARGS__));\
    } while(0);


#define LOGN(FMT, ...) \
	do {\
		ACE_DEBUG((LM_NOTICE, NOTICE_PREFIX ACE_TEXT(FMT), ## __VA_ARGS__));\
    } while(0);

#define LOGW(FMT, ...) \
	do {\
		ACE_DEBUG((LM_WARNING, WARNING_PREFIX ACE_TEXT(FMT), ## __VA_ARGS__));\
    } while(0);

#define LOGE(FMT, ...) \
	do {\
		ACE_DEBUG((LM_ERROR, ERROR_PREFIX ACE_TEXT(FMT), ## __VA_ARGS__));\
    } while(0);

#define LSC_CRITICAL(FMT, ...)  \
	do {\
		ACE_DEBUG((LM_CRITICAL, CRITICAL_PREFIX ACE_TEXT(FMT), ## __VA_ARGS__));\
    } while(0);

#define LSC_ALERT(FMT, ...) \
	do {\
		ACE_DEBUG((LM_ALERT, ALERT_PREFIX ACE_TEXT(FMT), ## __VA_ARGS__));\
	} while(0);

#define LSC_EMERGENCY(FMT, ...)  \
	do {\
		ACE_DEBUG((LM_EMERGENCY, EMERGENCY_PREFIX ACE_TEXT(FMT), ## __VA_ARGS__));\
	} while(0);

#define LSC_TRACE(FMT, ...) \
	do {\
		ACE_TRACE(FMT, ## __VA_ARGS__);\
	} while(0);

#define LOG_HEX(FMT, ...) \
	do {\
		ACE_HEX_DUMP(FMT, ##__VA_ARGS__);\
	} while(0);

#endif /* LSC_LOGGER_H_ */
