U E D R , A S I H C RSS

ACE/Callback Example

No older revisions available

No older revisions available



* callback.h
~cpp 
#include "ace/streams.h"
#include "ace/Log_Msg.h"
#include "ace/Log_Msg_Callback.h"
#include "ace/Log_Record.h"
#include "ace/SString.h"

class Callback : public ACE_Log_Msg_Callback
{
public:
	void log(ACE_Log_Record &log_record)
	{
		/*log_record.print(ACE_TEXT(""), 0, cerr);
		log_record.print(ACE_TEXT(""), ACE_Log_Msg::VERBOSE, cerr);*/

		//ver2
		cerr << "Log Message Received: " << endl;

		unsigned long msg_severity = log_record.type();
		ACE_Log_Priority prio = ACE_static_cast(ACE_Log_Priority, msg_severity);
		const ACE_TCHAR *prio_name = ACE_Log_Record::priority_name(prio);

		cerr << "\nType:		"
			<< ACE_TEXT_ALWAYS_CHAR(prio_name)
			<< endl;

		cerr << "\tlength:		" << log_record.length() << endl;

		const time_t epoch = log_record.time_stamp().sec();
		/*cerr << "\tTime_Stamp:	"
			<< ACE_TEXT_ALWAYS_CHAR(ACE_OS::ctime(&epoch))
			<< flush;*/

		cerr << "\tPid:		" << log_record.pid() << endl;

		ACE_CString data(">> ");
		data += ACE_TEXT_ALWAYS_CHAR(log_record.msg_data());

		cerr << "\tMsgData:		" << data.c_str() << endl;
	}
};
  • main.cpp

~cpp 
#define ACE_NTRACE 0
#include "ace/Log_Msg.h"
#include "ace/streams.h"
#include "callback.h"

int ACE_TMAIN(int, ACE_TCHAR *argv[])
{
	Callback *callback = new Callback;

	ACE_LOG_MSG->set_flags(ACE_Log_Msg::MSG_CALLBACK);
	ACE_LOG_MSG->clr_flags(ACE_Log_Msg::STDERR);
	ACE_LOG_MSG->msg_callback(callback);

	ACE_TRACE(ACE_TEXT("main"));

	ACE_DEBUG((LM_DEBUG, ACE_TEXT("%IHi Mom\n")));
	ACE_DEBUG((LM_INFO, ACE_TEXT("%IGoodnight\n")));

	return 0;
}

Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2021-02-07 05:22:20
Processing time 0.0424 sec