Beispiel #1
0
//---------------------------------------------------------------------------------
void ofxLogger::_log(ofLogLevel logLevel, const string& message, Poco::Logger* theLogger)
{
	string timestamp;

	// build the header
	if(bHeader)
	{
		Poco::LocalDateTime now;

		if(bDate && bTime)
		{
			timestamp += Poco::DateTimeFormatter::format(now, s_dateAndTimeFormat)+" ";
		}
		else if(bDate)
		{
			timestamp += Poco::DateTimeFormatter::format(now, s_dateFormat)+" ";
		}
		else if(bTime)
		{
			timestamp += Poco::DateTimeFormatter::format(now, s_timeFormat)+" ";	
		}

		if(bFrameNum)
		{
			timestamp += ofToString(ofGetFrameNum())+" ";
		}

		if(bMillis)
		{
			timestamp += ofToString(ofGetElapsedTimeMillis())+" ";
		}
	}

	// log the message
	//
	// Each log call is wrapped in a try / catch in case the logger is called
	// when it has already been destroyed. This can happen if it is used in
	// another destructor as the destruction order is not predictabale.
	//
	switch(logLevel)
	{
		case OF_LOG_SILENT:
			break;

		case OF_LOG_VERBOSE:
			try
			{
				theLogger->trace(timestamp+"OF_VERBOSE: "+message);
			}
			catch(...)
			{
				_logDestroyed("OF_VERBOSE: "+message);
			}
			break;

		case OF_LOG_NOTICE:
			try
			{
				theLogger->notice(timestamp+message);
			}
			catch(...)
			{
				_logDestroyed(message);
			}
			break;

		case OF_LOG_WARNING:
			try
			{
				theLogger->warning(timestamp+"OF_WARNING: "+message);
			}
			catch(...)
			{
				_logDestroyed("OF_WARNING: "+message);
			}
			break;

		case OF_LOG_ERROR:
			try
			{
				theLogger->error(timestamp+"OF_ERROR: "+message);
			}
			catch(...)
			{
				_logDestroyed("OF_ERROR: "+message);
			}
			break;

		case OF_LOG_FATAL_ERROR:
			try
			{
				theLogger->fatal(timestamp+"OF_FATAL_ERROR: "+message);
			}
			catch(...)
			{
				_logDestroyed("OF_FATAL_ERROR: "+message);
			}
			break;
	}
}
Beispiel #2
0
//---------------------------------------------------------------------------------
void ofLogger::_log(ofLogLevel logLevel, const string& message, Poco::Logger* theLogger){
	
	string timestamp;
	
	// build the header
	if(bHeader){
	
		Poco::LocalDateTime now;
		
		if(bDate && bTime){
			timestamp += Poco::DateTimeFormatter::format(now, s_dateAndTimeFormat)+" ";
		}
		else if(bDate){
			timestamp += Poco::DateTimeFormatter::format(now, s_dateFormat)+" ";
		}
		else if(bTime){
			timestamp += Poco::DateTimeFormatter::format(now, s_timeFormat)+" ";	
		}
		
		if(bFrameNum){
			timestamp += ofToString(ofGetFrameNum())+" ";
		}
		
		if(bMillis){
			timestamp += ofToString(ofGetElapsedTimeMillis())+" ";
		}
	}
	
	// log
	switch(logLevel){
		case OF_LOG_SILENT:
			break;
			
		case OF_LOG_VERBOSE:
			try{
				theLogger->trace(timestamp+"OF_VERBOSE: "+message);
			}
			catch(...){
				_logDestroyed("OF_VERBOSE: "+message);
			}
			break;
			
		case OF_LOG_DEBUG:
			try{
				theLogger->debug(timestamp+"OF_DEBUG: "+message);
			}
			catch(...){
				_logDestroyed("OF_DEBUG: "+message);
			}
			break;
			
		case OF_LOG_NOTICE:
			try{
				theLogger->notice(timestamp+message);
			}
			catch(...){
				_logDestroyed(message);
			}
			break;

		case OF_LOG_WARNING:
			try{
				theLogger->warning(timestamp+"OF_WARNING: "+message);
			}
			catch(...){
				_logDestroyed("OF_WARNING: "+message);
			}
			break;

		case OF_LOG_ERROR:
			try{
				theLogger->error(timestamp+"OF_ERROR: "+message);
			}
			catch(...){
				_logDestroyed("OF_ERROR: "+message);
			}
			break;
			
		case OF_LOG_FATAL_ERROR:
			try{
				theLogger->fatal(timestamp+"OF_FATAL_ERROR: "+message);
			}
			catch(...){
				_logDestroyed("OF_FATAL_ERROR: "+message);
			}
			break;
	}
}