std::ostream * get_log_ostream( const std::string & name) { LogStreamMap &file_stream_map = get_file_stream_map(); LogStreamMap::iterator it = file_stream_map.find(name); return it == file_stream_map.end() ? 0 : (*it).second->m_ostream; }
const std::string & get_log_path( const std::string & name) { static std::string not_found = ""; LogStreamMap &file_stream_map = get_file_stream_map(); LogStreamMap::iterator it = file_stream_map.find(name); return it == file_stream_map.end() ? not_found : (*it).second->m_path; }
void close_log_file( const std::string & name) { LogStreamMap &file_stream_map = get_file_stream_map(); LogStreamMap::iterator it = file_stream_map.find(name); if (it != file_stream_map.end()) { delete (*it).second; file_stream_map.erase(it); } }
void create_log_file( const std::string & name, const std::string & path) { LogStreamMap &file_stream_map = get_file_stream_map(); close_log_file(name); std::ofstream *file_stream = new std::ofstream(path.c_str()); file_stream_map[name] = new LogStream(path, file_stream, file_stream); }
void unregister_log_ostream( std::ostream & os) { LogStreamMap &file_stream_map = get_file_stream_map(); for (LogStreamMap::iterator it = file_stream_map.begin(); it != file_stream_map.end(); ++it) { if ((*it).second->m_ostream == &os) { delete (*it).second; file_stream_map.erase(it); break; } } OStreamTeeStreambufMap &ostream_tee_streambuf_map = get_ostream_tee_streambuf_map(); for (OStreamTeeStreambufMap::iterator it = ostream_tee_streambuf_map.begin(); it != ostream_tee_streambuf_map.end(); ++it) (*it).second->m_teeStreambuf->remove(&os); }
void register_log_ostream( std::ostream & os, const std::string & name) { LogStreamMap &file_stream_map = get_file_stream_map(); LogStreamMap::iterator it = file_stream_map.find(name); if (it != file_stream_map.end()) { std::ostringstream s; s << "Log ostream " << name << " has already been registered"; //Do we really want to throw if a stream is registered multiple times? //I don't think so... commenting this out. //throw std::runtime_error(s.str()); } else { file_stream_map[name] = new LogStream(name, &os, 0); } }
void create_log_file( const std::string & name, const std::string & path) { LogStreamMap &file_stream_map = get_file_stream_map(); close_log_file(name); std::ofstream *file_stream = new std::ofstream(path.c_str()); if(!file_stream->good()) { delete file_stream; std::ostringstream s; s << "Cannot open output log file '" << path << "' directory does not exist or is write protected."; throw std::runtime_error(s.str()); } file_stream_map[name] = new LogStream(path, file_stream, file_stream); }