FEI  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
fei_LogFile.cpp
1 /*--------------------------------------------------------------------*/
2 /* Copyright 2005 Sandia Corporation. */
3 /* Under the terms of Contract DE-AC04-94AL85000, there is a */
4 /* non-exclusive license for use of this work by or on behalf */
5 /* of the U.S. Government. Export of this program may require */
6 /* a license from the United States Government. */
7 /*--------------------------------------------------------------------*/
8 
9 #include "fei_LogFile.hpp"
10 #include "fei_iostream.hpp"
11 #include "fei_fstream.hpp"
12 #include "fei_sstream.hpp"
13 #include <string>
14 
15 fei::LogFile::LogFile()
16  : output_stream_(0),
17  counter_(0)
18 {
19 }
20 
22 {
23  counter_ = 0;
25 }
26 
27 void fei::LogFile::openOutputStream(const char* path,
28  int nprocs,
29  int localproc)
30 {
31  closeOutputStream();
32 
33  std::string pathstr("./");
34  if (path != NULL) {
35  pathstr = path;
36  }
37 
38  if (pathstr[pathstr.size()] != '/') {
39  pathstr = pathstr+"/";
40  }
41 
42  FEI_OSTRINGSTREAM osstr;
43  osstr << pathstr << "fei_log."<<counter_<<"."<<nprocs<<"."<<localproc;
44  std::string filename = osstr.str();
45 
46  ++counter_;
47 
48  output_stream_ = new FEI_OFSTREAM(filename.c_str(), IOS_OUT);
49 
50  if (output_stream_ == NULL || output_stream_->bad()) {
51  fei::console_out() << "couldn't open debug output file: " << filename << FEI_ENDL;
52  delete output_stream_;
53  output_stream_ = 0;
54  }
55 }
56 
57 FEI_OSTREAM* fei::LogFile::getOutputStream()
58 {
59  return( output_stream_ );
60 }
61 
63 {
64  delete output_stream_;
65  output_stream_ = 0;
66 }
67 
69 {
70  static fei::LogFile log_file;
71  return(log_file);
72 }
73 
void openOutputStream(const char *path=NULL, int nprocs=1, int localproc=0)
Definition: fei_LogFile.cpp:27
FEI_OSTREAM * getOutputStream()
Definition: fei_LogFile.cpp:57
virtual ~LogFile()
Definition: fei_LogFile.cpp:21
void closeOutputStream()
Definition: fei_LogFile.cpp:62
std::ostream & console_out()
static LogFile & getLogFile()
Definition: fei_LogFile.cpp:68