void ErrLog::_init1() { clog.init_errlog(this); #if defined(_WIN32) && defined(FC_ERRLOG_WIN32_LOCK) InitializeCriticalSection(&_crit); #endif w_reset_strstream(this->clog); }
void ErrLog::log(enum LogPriority prio, const char *format, ...) { if(_magic != ERRORLOG__MAGIC) { std::cerr << "Trying to use uninitialized ErrLog." <<std::endl; ::exit(1); } va_list ap; va_start(ap, format); #if defined(_WIN32) && defined(FC_ERRLOG_WIN32_LOCK) EnterCriticalSection(&_crit); #endif _flush(true); if (prio > _level) { #if defined(_WIN32) && defined(FC_ERRLOG_WIN32_LOCK) LeaveCriticalSection(&_crit); #endif return; } switch(_destination) { case log_to_unix_file: case log_to_open_file: case log_to_stderr: #if HAVE_VPRINTF (void) vfprintf(_file,format, ap); #else #error need vfprintf #endif fputc('\n', _file); fflush(_file); break; case log_to_ether: break; } va_end(ap); // clear the slate for the next use of operator<< w_reset_strstream(this->clog); #if defined(_WIN32) && defined(FC_ERRLOG_WIN32_LOCK) LeaveCriticalSection(&_crit); #endif }
void ErrLog::_flush(bool #if defined(_WIN32) && defined(FC_ERRLOG_WIN32_LOCK) already_in_crit #endif ) { #if defined(_WIN32) && defined(FC_ERRLOG_WIN32_LOCK) if(!already_in_crit) EnterCriticalSection(&_crit); #endif if(_magic != ERRORLOG__MAGIC) { std::cerr << "Fatal error: Trying to use uninitialized ErrLog." <<std::endl; ::exit(1); } this->clog << std::ends ; if (this->clog._prio <= _level) { switch(_destination) { case log_to_unix_file: case log_to_open_file: case log_to_stderr: fprintf(_file, "%s", this->clog.c_str()); // fprintf(_file, "%s\n", this->clog.c_str()); fflush(_file); break; case log_to_ether: break; } } this->clog.flush(); // reset to beginning of buffer w_reset_strstream(this->clog); #if defined(_WIN32) && defined(FC_ERRLOG_WIN32_LOCK) if(!already_in_crit) LeaveCriticalSection(&_crit); #endif }
void sendout() { fprintf(stdout, "%s %s", key?key:"uninitialized", outstream.c_str()); w_reset_strstream(outstream); }