My Project
 All Classes Files Functions Variables Enumerations Enumerator Friends Macros Pages
LogFile.h
Go to the documentation of this file.
1 #ifndef GCP_UTIL_LOGFILE_H
2 #define GCP_UTIL_LOGFILE_H
3 
11 #include <string>
12 #include <sstream>
13 
14 #include "gcp/util/common/TimeVal.h"
15 #include "gcp/util/common/LogFile.h"
16 
17 namespace gcp {
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, bool fullTime=false);
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  bool dataPrefix_;
112 
113  // The buffer into which we will accumulate data to be written
114  // to a file
115 
116  std::ostringstream lineBuffer_;
117 
121  void initBuffer();
122 
126  void putLine(bool fullTime=false);
127 
131  void write(std::string line);
132 
133 
134  }; // End class LogFile
135 
136  } // End namespace util
137 } // End namespace gcp
138 
139 
140 
141 
142 #endif // End #ifndef GCP_UTIL_LOGFILE_H
void close()
Definition: LogFile.cc:91
void setPrefix(const std::string &prefix)
Definition: LogFile.cc:58
LogFile()
Definition: LogFile.cc:19
void setDatePrefix()
Definition: LogFile.cc:67
void open()
Definition: LogFile.cc:104
void setDirectory(const std::string &dir)
Definition: LogFile.cc:50
LogFile & logFile()
virtual ~LogFile()
Definition: LogFile.cc:39
Definition: LogFile.h:20
void prepend(std::string message)
Definition: LogFile.cc:233
void flush()
Definition: LogFile.cc:75
std::string newFileName()
Definition: LogFile.cc:153
bool fileExists(std::string fileName)
Definition: LogFile.cc:137
void append(std::string message, bool fullTime=false)
Definition: LogFile.cc:215