www.pudn.com > zfxcengine-0.1.0.zip > ceLogger.cpp


/* $Id: ceLogger.cpp,v 1.4 2005/07/27 02:09:53 andreaskohn Exp $ */ 
#include  
#include  
#include  
#include  
#ifdef _WIN32 
#  include  
#endif 
 
namespace ZFXCE { 
namespace Logging { 
 
using std::list; 
using std::iterator; 
//using std::va_list; 
//using std::va_start; 
//using std::va_end; 
 
#ifndef _WIN32 
  using std::vsnprintf; 
#else 
#  define vsnprintf _vsnprintf 
#endif 
//////////////////////////////////////////////////////////////////////////////// 
ceLogger::ceLogger(ceLogDomain* domain) : _domain(domain) { 
} 
//////////////////////////////////////////////////////////////////////////////// 
ceLogDomain* ceLogger::getDomain() { 
	return _domain; 
} 
//////////////////////////////////////////////////////////////////////////////// 
void ceLogger::log(ceLogLevel level, string format, va_list args) { 
	if (_domain->isLevelEnabled(level)) { 
		const int MAX_SIZE = 2048; 
 
		char buffer[MAX_SIZE]; 
	 
		vsnprintf(buffer, MAX_SIZE, format.c_str(), args); 
		list streams = _domain->getStreams(level); 
		for (list::iterator it = streams.begin(); it != streams.end(); it++) { 
			(*it)->write(buffer); 
		} 
	} 
} 
//////////////////////////////////////////////////////////////////////////////// 
// Convenience functions 
//////////////////////////////////////////////////////////////////////////////// 
void ceLogger::log(ceLogLevel level, string format, ...) { 
	va_list list; 
	va_start(list, format); 
	log(level, format, list); 
	va_end(list); 
} 
//////////////////////////////////////////////////////////////////////////////// 
void ceLogger::debug(string format, ...) { 
	va_list list; 
	va_start(list, format); 
	log(LOG_DEBUG, format, list); 
	va_end(list); 
} 
//////////////////////////////////////////////////////////////////////////////// 
void ceLogger::info(string format, ...) { 
	va_list list; 
	va_start(list, format); 
	log(LOG_INFO, format, list); 
	va_end(list); 
} 
//////////////////////////////////////////////////////////////////////////////// 
void ceLogger::warn(string format, ...) { 
	va_list list; 
	va_start(list, format); 
	log(LOG_WARN, format, list); 
	va_end(list); 
} 
//////////////////////////////////////////////////////////////////////////////// 
void ceLogger::error(string format, ...) { 
	va_list list; 
	va_start(list, format); 
	log(LOG_ERROR, format, list); 
	va_end(list); 
} 
//////////////////////////////////////////////////////////////////////////////// 
void ceLogger::fatal(string format, ...) { 
	va_list list; 
	va_start(list, format); 
	log(LOG_FATAL, format, list); 
	va_end(list); 
} 
//////////////////////////////////////////////////////////////////////////////// 
} // namespace Logging 
} // namespace ZFXCE