CARMA C++
LogFile.h
Go to the documentation of this file.
1 #ifndef SZA_UTIL_LOGFILE_H
2 #define SZA_UTIL_LOGFILE_H
3 
11 #include <string>
12 #include <sstream>
13 
14 #include "carma/szautil/TimeVal.h"
15 #include "carma/szautil/LogFile.h"
16 
17 namespace sza {
18  namespace util {
19 
20  class LogFile {
21 
22  public:
23 
27  LogFile();
28 
32  virtual ~LogFile();
33 
38  void setDirectory(const std::string& dir);
39 
43  void setPrefix(const std::string& prefix);
44 
48  void setDatePrefix();
49 
53  void open();
54 
58  void close();
59 
60  void flush();
61 
65  bool fileExists(std::string fileName);
66 
67  /*
68  * Create a unique file name based on the prefix and files
69  * already in the log directory
70  */
71  std::string newFileName();
72 
76  void prepend(std::string message);
77 
81  void append(std::string message);
82 
86  LogFile& logFile();
87 
88  private:
89 
90  // Define a maximum version number for log files
91 
92  static const int MAX_VERSION;
93 
94  // A prefix to name log files
95 
96  std::string prefix_;
97  bool datePrefix_;
98 
99  // The directory in which to write log files
100 
101  std::string directory_;
102 
103  // The file descriptor associated with our log file
104 
105  FILE* file_;
106 
107  // A message to prepend to any line we write to the log file
108 
109  std::string prependStr_;
110 
111  // The buffer into which we will accumulate data to be written
112  // to a file
113 
114  std::ostringstream lineBuffer_;
115 
119  void initBuffer();
120 
124  void putLine();
125 
129  void write(std::string line);
130 
131 
132  }; // End class LogFile
133 
134  } // End namespace util
135 } // End namespace sza
136 
137 
138 
139 #endif // End #ifndef SZA_UTIL_LOGFILE_H
Tagged: Fri Nov 14 12:39:38 UTC 2003.
Tagged: Mon May 10 17:23:41 PDT 2004.