/** Filter the log with regular expression string. * @param [in] filename log file name * @param [in] rgEprStr regular expression string * @param [out] filtered_log filtered log string */ void log_analysis_tool::run_filter() { formatter = create_formatter();//formatter used to color the keywords // open the file to be analysed fstream fs; fs.open(filename); if(!fs.is_open()) cout<<"can not find "<<filename<<endl; // processing the file with keyword char file_block_buffer[FILE_BUFFER_LENGTH+1]; bool keep_reading_file = true; while(keep_reading_file) { fs.read(file_block_buffer, FILE_BUFFER_LENGTH); file_block_buffer[fs.gcount()] = '\0'; if (fs.gcount() != FILE_BUFFER_LENGTH)// last block from the file { keep_reading_file = false; file_block_buffer[fs.gcount()] = '\n'; file_block_buffer[fs.gcount()+1] = '\0'; } int mbNum = - analyse_block_buffer(file_block_buffer); fs.seekg(mbNum, fs.cur); } fs.close(); }
void TestLogger::add_stdout(arc::uint16 verbosity, OutFormat format) { // safety to ensure two std outs are not defined if(m_using_stdout) { throw arc::test::ex::TestRuntimeError( "A standard out test logger has already been defined. " "Currently only one standard out test logger is supported." ); } m_using_stdout = true; // create formatter create_formatter(&std::cout, verbosity, format, true); }
void TestLogger::add_file_output( const arc::str::UTF8String& path, arc::uint16 verbosity, OutFormat format) { // open a file stream std::ofstream* file_stream = new std::ofstream(path.get_raw()); // did the stream open ok? if(!file_stream->good()) { file_stream->close(); arc::str::UTF8String error_message; error_message << "Failed to open path for logging: " << path; throw arc::test::ex::TestRuntimeError(error_message); } // store the file name and stream m_file_streams[path] = file_stream; // create a formatter create_formatter(file_stream, verbosity, format); }