FEI Version of the Day
fei_LogFile.cpp
00001 /*--------------------------------------------------------------------*/
00002 /*    Copyright 2005 Sandia Corporation.                              */
00003 /*    Under the terms of Contract DE-AC04-94AL85000, there is a       */
00004 /*    non-exclusive license for use of this work by or on behalf      */
00005 /*    of the U.S. Government.  Export of this program may require     */
00006 /*    a license from the United States Government.                    */
00007 /*--------------------------------------------------------------------*/
00008 
00009 #include "fei_LogFile.hpp"
00010 #include "fei_iostream.hpp"
00011 #include "fei_fstream.hpp"
00012 #include "fei_sstream.hpp"
00013 #include <string>
00014 
00015 fei::LogFile::LogFile()
00016  : output_stream_(0),
00017    counter_(0)
00018 {
00019 }
00020 
00021 fei::LogFile::~LogFile()
00022 {
00023   counter_ = 0;
00024   closeOutputStream();
00025 }
00026 
00027 void fei::LogFile::openOutputStream(const char* path,
00028                                     int nprocs,
00029                                     int localproc)
00030 {
00031   closeOutputStream();
00032 
00033   std::string pathstr("./");
00034   if (path != NULL) {
00035     pathstr = path;
00036   }
00037 
00038   if (pathstr[pathstr.size()] != '/') {
00039     pathstr = pathstr+"/";
00040   }
00041 
00042   FEI_OSTRINGSTREAM osstr;
00043   osstr << pathstr << "fei_log."<<counter_<<"."<<nprocs<<"."<<localproc;
00044   std::string filename = osstr.str();
00045 
00046   ++counter_;
00047 
00048   output_stream_ = new FEI_OFSTREAM(filename.c_str(), IOS_OUT);
00049 
00050   if (output_stream_ == NULL || output_stream_->bad()) {
00051     fei::console_out() << "couldn't open debug output file: " << filename << FEI_ENDL;
00052     delete output_stream_;
00053     output_stream_ = 0;
00054   }
00055 }
00056 
00057 FEI_OSTREAM* fei::LogFile::getOutputStream()
00058 {
00059   return( output_stream_ );
00060 }
00061 
00062 void fei::LogFile::closeOutputStream()
00063 {
00064   delete output_stream_;
00065   output_stream_ = 0;
00066 }
00067 
00068 fei::LogFile& fei::LogFile::getLogFile()
00069 {
00070   static fei::LogFile log_file;
00071   return(log_file);
00072 }
00073 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends