22 #ifndef _LOGRECORD_HH_
23 #define _LOGRECORD_HH_
28 #include <boost/thread.hpp>
29 #include <boost/archive/iterators/base64_from_binary.hpp>
30 #include <boost/archive/iterators/insert_linebreaks.hpp>
31 #include <boost/archive/iterators/transform_width.hpp>
32 #include <boost/archive/iterators/ostream_iterator.hpp>
33 #include <boost/filesystem.hpp>
41 #define GZ_LOG_VERSION "1.0"
81 public:
bool Init(
const std::string &_subdir);
95 public:
void Add(
const std::string &_name,
const std::string &_filename,
96 boost::function<
bool (std::ostringstream &)> _logCallback);
106 public:
bool Remove(
const std::string &_name);
137 public:
bool Start(
const std::string &_encoding=
"zlib",
138 const std::string &_path=
"");
148 public: std::string
GetFilename(
const std::string &_name =
"")
const;
153 public:
unsigned int GetFileSize(
const std::string &_name =
"")
const;
157 public:
void SetBasePath(
const std::string &_path);
176 public:
void Write(
bool _force =
false);
187 private:
void Update();
190 private:
void RunUpdate();
193 private:
void RunWrite();
196 private:
void ClearLogs();
199 private:
void PublishLogStatus();
203 private:
void OnLogControl(ConstLogControlPtr &_data);
208 private:
void Cleanup();
211 private:
void OnPause(
bool _pause);
222 public: Log(
LogRecord *_parent,
const std::string &_relativeFilename,
223 boost::function<
bool (std::ostringstream &)> _logCB);
226 public:
virtual ~Log();
230 public:
void Start(
const boost::filesystem::path &_path);
236 public:
void Write();
240 public:
unsigned int Update();
243 public:
void ClearBuffer();
252 public: std::string GetRelativeFilename()
const;
256 public: std::string GetCompleteFilename()
const;
262 public: boost::function<bool (std::ostringstream &)> logCB;
265 public: std::string buffer;
268 public: std::ofstream logFile;
271 public: std::string relativeFilename;
274 private: boost::filesystem::path completePath;
280 private:
typedef std::map<std::string, Log*> Log_M;
286 private: Log_M::iterator updateIter;
289 private: Log_M::iterator logsEnd;
292 private: boost::condition_variable startThreadCondition;
295 private: boost::condition_variable updateCondition;
298 private: boost::condition_variable cleanupCondition;
301 private:
bool running;
304 private: boost::thread *writeThread;
307 private: boost::thread *updateThread;
310 private: boost::thread cleanupThread;
313 private:
mutable boost::mutex writeMutex;
316 private:
mutable boost::mutex runWriteMutex;
319 private:
mutable boost::mutex updateMutex;
322 private: boost::mutex controlMutex;
326 private: boost::condition_variable dataAvailableCondition;
329 private: boost::filesystem::path logBasePath;
332 private: boost::filesystem::path logCompletePath;
336 private: std::string logSubDir;
339 private: std::string encoding;
342 private:
bool initialized;
345 private:
bool paused;
348 private:
bool firstUpdate;
351 private:
bool stopThread;
372 private:
bool pauseState;
379 private:
bool readyToStart;