std::ofstream& Logger::LogStart(TLogLevel level){ char buffer[64]; if (logger_os.tellp() >= logger_max_file_size){ logger_os.close(); std::string renamed_file = logger_filename; renamed_file.append(".backup"); if (file_exists(renamed_file.c_str())) remove (renamed_file.c_str()); rename(logger_filename.c_str(), renamed_file.c_str()); remove (logger_filename.c_str()); } if (!file_exists(logger_filename.c_str())){ logger_os.close(); logger_os.open(logger_filename.c_str(), std::ios::out | std::ios::app); if (logger_os.is_open()){ logger_messageLevel = loggger_wantedLevel; }else{ logger_messageLevel = logNone; //prevent from sending data into the not opened stream } } time_t thetime = time(0); tm * ptm = std::localtime(& thetime); strftime(buffer, sizeof(buffer), "%d.%m.%Y %H:%M:%S", ptm);// Format: 15.06.2009 20:20:00 logger_os << "-" << buffer << " " << ToString(level) << ": "; return logger_os; }
void Logger::flush() { if (g_logFile.is_open()) { g_logFile.flush(); } }
/** * This method will be called when a new image message is published * We will write this information to the image folder * We will append the image time to the timestamp of the folder */ void image_stereo_callback(const sensor_msgs::ImageConstPtr& msgL,const sensor_msgs::ImageConstPtr& msgR) { if (!outfile_img.is_open()) { ROS_ERROR("Unable to open image file"); return; } // Create our folder timestamp char filename[128]; std::sprintf(filename, "img_%ld.png", msgL.get()->header.stamp.toNSec()); // Else write the new reading to file outfile_img << msgL.get()->height << " " << msgL.get()->width << " " << msgL.get()->header.stamp.toNSec() << " " << "images_cam0/" << filename << " " << msgR.get()->height << " " << msgR.get()->width << " " << msgR.get()->header.stamp.toNSec() << " " << "images_cam1/" << filename << "\n"; // Convert the image msg to open cv cv_bridge::CvImagePtr cv_ptr_l = cv_bridge::toCvCopy(msgL, "bgr8"); cv::imwrite(folder_images_l+filename, cv_ptr_l->image); cv_bridge::CvImagePtr cv_ptr_r = cv_bridge::toCvCopy(msgR, "bgr8"); cv::imwrite(folder_images_r+filename, cv_ptr_r->image); }
inline void log(const char* type,const char* file,int line,void* Add) { if(fichier_log.is_open()) { fichier_log << type << "\t" << file << "\t" << line << "\t" << Add << std::endl; } }
void Logger::close(){ if (logger_os.is_open()){ logger_os.flush(); logger_os.close(); logger_messageLevel = logNone; } }
int output_mag(std::ofstream& ofile){ // check calling of routine if error checking is activated if(err::check==true){std::cout << "grains::output_mag has been called" << std::endl;} // calculate grain magnetisations grains::mag(); if(vmpi::my_rank==0){ // check file stream is open if(!ofile.is_open()){ terminaltextcolor(RED); std::cerr << "Error - file stream is unopened for grains::output_mag(), exiting!" << std::endl; terminaltextcolor(WHITE); err::vexit(); } unsigned int id=0; // grain id (excluding grains with zero atoms) // calculate mag_m of each grain and normalised direction for(int grain=0;grain<grains::num_grains;grain++){ // check for grains with zero atoms if(grains::grain_size_array[grain]==0){ //std::cerr << "Warning Grain " << grain << " has no constituent atoms!" << std::endl; } else{ ofile << grain << "\t" << id << "\t" << grains::x_mag_array[grain] << "\t" << grains::y_mag_array[grain]; ofile << "\t" << grains::z_mag_array[grain] << "\t" << grains::mag_m_array[grain] << std::endl; id++; } } } return EXIT_SUCCESS; }
void hook_ante_loop(const int nt) { parent_t::hook_ante_loop(nt); if (this->rank != 0) return; //checking what are the MPDATA options of each test simulation (fct / iga / ...) //basing on gnuplot output filename ... std::string gnuplot_name = this->p.gnuplot_output; std::string name; char delimeter('%'); std::istringstream iss(gnuplot_name); getline(iss, name, delimeter); // ... and naming output stats file accordingly if(!ofs.is_open()) ofs.open("stats_"+name+".txt", std::ofstream::out); last_timestep = nt; true_solution.resize(this->mem->advectee().shape()); error_2.resize(this->mem->advectee().shape()); //after one full rotation true solution is equal to the inital state true_solution = this->mem->advectee(); ofs << std::fixed << std::setprecision(8) << std::endl; ofs << "timestep = 0" << std::endl; ofs << "min(solution) = " << min(true_solution) <<std::endl; ofs << "max(solution) = " << max(true_solution) <<std::endl; ofs << " " <<std::endl; }
wesnoth_global_fixture() { reporter.open("boost_test_result.xml"); assert( reporter.is_open() ); boost::unit_test::results_reporter::set_stream(reporter); // lg::set_log_domain_severity("all",3); game_config::path = get_cwd(); // Initialize unit tests SDL_Init(SDL_INIT_TIMER); test_utils::get_fake_display(1024, 768); gui2::init(); static const gui2::event::tmanager gui_event_manager; // Set more report as default if (boost::unit_test::runtime_config::log_level() == boost::unit_test::invalid_log_level) boost::unit_test::unit_test_log.set_threshold_level( boost::unit_test::log_messages ); if (boost::unit_test::runtime_config::report_level() == boost::unit_test::INV_REPORT_LEVEL) boost::unit_test::results_reporter::set_level(boost::unit_test::SHORT_REPORT); boost::unit_test::unit_test_monitor.register_exception_translator<game::error>(&exception_translator_game); boost::unit_test::unit_test_monitor.register_exception_translator<network::error>(&exception_translator_network); boost::unit_test::unit_test_monitor.register_exception_translator<config::error>(&exception_translator_config); }
/// helper method called by setup_problem void ComputeFeatureChannelsApplication::setup_logging(std::ofstream &log_file, const program_options::variables_map &options) { if(log_file.is_open()) { // the logging is already setup return; } // set base logging rules -- BaseApplication::setup_logging(log_file, options); const bool silent_mode = get_option_value<bool>(options, "silent_mode"); if(silent_mode == false) { // set our own stdout rules -- logging::LogRuleSet &rules_for_stdout = logging::get_log().console_log().rule_set(); rules_for_stdout.add_rule(logging::InfoMessage, "ComputeFeatureChannelsApplication"); #if defined(DEBUG) rules_for_stdout.add_rule(logging::DebugMessage, "*"); // we are debugging this application #else rules_for_stdout.add_rule(logging::InfoMessage, "*"); // "production mode" #endif } return; }
void LogMessage(const String& message, LogFlag flag) { time_t cm_time; struct tm *p_time; // get local time. time(&cm_time); p_time = localtime(&cm_time); // output to stderr. if (flag & log_level_) { std::cerr << '[' << std::setw(2) << std::setfill('0') << p_time->tm_hour << ':' << std::setw(2) << std::setfill('0') << p_time->tm_min << ':' << std::setw(2) << std::setfill('0') << p_time->tm_sec << "] " << message << '\n'; } // output to log file. if ( (flag & log_level_file_) && strm_.is_open() ) { strm_ << '[' << std::setw(2) << std::setfill('0') << p_time->tm_hour << ':' << std::setw(2) << std::setfill('0') << p_time->tm_min << ':' << std::setw(2) << std::setfill('0') << p_time->tm_sec << "] " << message << '\n'; } }
void DebugTrace::openFile( const char * filename ) { if( dg_debugfile.good ()&&dg_debugfile.is_open () ) dg_debugfile.close (); dg_debugfile.clear (); dg_debugfile.open( filename, std::ios::trunc&std::ios::out ); //std::cout << filename << dg_debugfile.good () << dg_debugfile.is_open () << std::endl; }
/*-------------------------------------------------------------------- m_dump_matches_to_stream ----------------------------------------------------------------------*/ bool CStereoOdometryEstimator::m_dump_matches_to_stream( std::ofstream & stream, const vector<cv::DMatch> & matches, const vector<size_t> & matches_ids ) { /* FORMAT - # of matches - match id - queryIdx - trainIdx - distance */ if( !stream.is_open() ) return false; size_t num_m = matches.size(), num_m_id = matches_ids.size(); stream.write( (char*)&num_m, sizeof(size_t) ); stream.write( (char*)&num_m_id, sizeof(size_t) ); const bool add_ids = num_m == num_m_id; for( size_t m = 0; m < matches.size(); ++m ) { if( add_ids ) stream.write( (char*)&(matches_ids[m]), sizeof(size_t) ); stream.write( (char*)&(matches[m].queryIdx), sizeof(matches[m].queryIdx) ); stream.write( (char*)&(matches[m].trainIdx), sizeof(matches[m].trainIdx) ); stream.write( (char*)&(matches[m].distance), sizeof(matches[m].distance) ); stream.write( (char*)&(matches[m].imgIdx), sizeof(matches[m].imgIdx) ); } // end-for-matches return true; } // end-m_dump_matches_to_stream
void _LogAppenderBase::checkFileIsOpen() { long int currentTime = context.now.tv_sec * 1000000 + context.now.tv_usec; if (nextCheckTime == 0 || currentTime >= nextCheckTime) { if (access(context.path.c_str(), F_OK) != 0) { if (out.is_open()) { out.close(); } try { open(); } catch (...) { } } nextCheckTime = currentTime + LOG_CHECK_FILE_INTERVAL_USEC; } }
// Simple logging functionality: if the log file isn't already open, it tries to // open it. If it can't, it throws a tantrum. void log(const std::string& str) { if (!logFile.is_open()) { // Try to open the file auto t = std::time(nullptr); auto tm = *std::localtime(&t); char buffer[80]; strftime(buffer, 80, filenameFormat.c_str(), &tm); logFile.open(buffer, std::ofstream::out); if (!logFile.is_open()) { std::cerr << "Unable to open log file."; exit(1); } } // The file is open! logFile << str; }
void open(const path filepath) { html_file.open(filepath.string()); if(!html_file.is_open()) throw std::runtime_error( std::string("cannot open file \"")+filepath.string()+"\" !"); file_opened=true; }
void Logger::finish() { if (g_logFile.is_open()) { g_logFile.flush(); g_logFile.close(); } }
bool open(const char* path) { uint64_t tmp; close(); m_fp.open(path,std::ios::binary | std::ios::trunc); return m_fp.is_open(); }
void Solver::print_file_solution(unsigned int iteration, Solution* sol, std::ofstream &file) { // gnuplot //plot "out.txt" using 1:2 title "óptimos locales" with lines,"out.txt" using 1:3 title "óptimo global" with lines if(file.is_open()) file << iteration << " " << get_cost(sol) << " " << global_best_cost << "\n"; }
// Ensure a filehandle is open void assertFileOpen(std::ofstream& fh, const std::string& fn) { if(!fh.is_open()) { std::cerr << "Error: could not open " << fn << " for write\n"; exit(EXIT_FAILURE); } }
void Logger::setReportingLevel(TLogLevel level){ loggger_wantedLevel = level; if (logger_os.is_open()){ logger_messageLevel = loggger_wantedLevel; }else{ logger_messageLevel = logNone; } }
//------------------------------------ int EasDAQpack :: outToFile(std::ofstream &fptr) { if ((!fptr.is_open()) || (!fptr.good())) return -1; fptr.write(reinterpret_cast <const char *> (this), sizeof(EasDAQpack)); return 0; }
int DLL_API Window_t::Log(std::ofstream &File, std::string Precursor) { if (!File.is_open()) File.open("Log Data.txt", std::ios::app); if (File.is_open()) { File << Precursor << "==================== Image_t =====================" << std::endl; File << Precursor << "this: " << "0x" << this << std::endl; File << Precursor << "WindowHandle: " << "0x" << WindowHandle; File << Precursor << "HScreen: " << "0x" << HScreen; File << Precursor << "Screen: " << "0x" << Screen; File << Precursor << "Event: " << "0x" << &Event; File << Precursor << "KeyState: " << "0x" << KeyState; File << Precursor << "Width: " << Width; File << Precursor << "Height: " << Height; File << Precursor << "BitsPerPixel: " << BitsPerPixel; File << Precursor << "Caption: " << *Caption; File << Precursor << "ID: " << ID; File << Precursor << "Shown: " << Shown; File << Precursor << "MouseFocus: " << MouseFocus; File << Precursor << "KeyboardFocus: " << KeyboardFocus; File << Precursor << "Minimized: " << Minimized; File << Precursor << "HardwareAccelerated: " << HardwareAccelerated; File << Precursor << "Running: " << Running; File << Precursor << "FRAME_SAMPLE_SIZE: " << TimerHandle.FRAME_SAMPLE_SIZE; File << Precursor << "WiCurrentFPSdth: " << TimerHandle.CurrentFPS; for (int i = 0; i < TimerHandle.FRAME_SAMPLE_SIZE; i++) File << Precursor << "LastFPS[" << i << "]: " << TimerHandle.LastFPS[i]; File << Precursor << "LastFrame in ns: " << duration_cast <nanoseconds> (TimerHandle.LastFrame->time_since_epoch()).count(); File << Precursor << "LastFPSDisplay in ns: " << duration_cast <nanoseconds> (TimerHandle.LastFPSDisplay->time_since_epoch()).count(); File << Precursor << "LastBench in ns: " << duration_cast <nanoseconds> (TimerHandle.LastBench->time_since_epoch()).count(); File << Precursor << "LastIdentifier: " << *(TimerHandle.LastIdentifier); File.close(); } else return 1; return 0; }
void SVExclusionList::listOfReadFailures( std::ofstream fsout ) const { if (!fsout.is_open()) return; typedef list<string>::const_iterator LI; for (LI i=readFailList.begin(); i!=readFailList.end(); ++i) { fsout << *i << endl; } }
void carmen_velodyne_dump_handler(char* module, char* variable, char* value) { if (dump_file.is_open()) dump_file.close(); if (!realpath(dump_dirname, dump_path)) { dump_path[0] = '\0'; carmen_warn("\nWarning: Dump directory %s is invalid\n", dump_dirname); } }
void Log::uninit(void) { if(file.is_open() && status) { writeMessage("Log ", "Closed."); file.close(); } }
void _LogAppenderBase::flush() { if (!out.is_open()) { return; } out.flush(); }
void _LogAppenderBase::close() { if (!out.is_open()) { return; } out.close(); }
void setOutputFile(std::string path) { if(_fileOutput.is_open()) { _fileOutput.flush(); _fileOutput.close(); } _fileOutput.open(path, std::ofstream::out | std::ofstream::app); }
bool irs_statistics_t::serialize(std::ofstream& stream) const { if(stream.is_open()) { stream << get_statistics(); return true; } return false; }
inline void openfile (std::ofstream& outfile, const std::string& fileName){ if (!outfile.is_open()) { outfile.open(fileName.c_str()); //outfile.open(fileName.c_str(), std::fstream::app); if (! outfile.good() ){ std::cout << "[WARNING] opening file: " << fileName << " failed!\n" << "Will write to standard output ... \n"; } } }