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>
34 #include <boost/function.hpp>
43 #define GZ_LOG_VERSION "1.0"
83 public:
bool Init(
const std::string &_subdir);
97 public:
void Add(
const std::string &_name,
const std::string &_filename,
98 boost::function<
bool (std::ostringstream &)> _logCallback);
108 public:
bool Remove(
const std::string &_name);
114 public:
void Notify();
120 public:
void SetPaused(
bool _paused);
125 public:
bool GetPaused()
const;
130 public:
bool IsReadyToStart()
const;
134 public:
bool GetRunning()
const;
139 public:
bool Start(
const std::string &_encoding=
"zlib",
140 const std::string &_path=
"");
145 public:
const std::string &GetEncoding()
const;
150 public: std::string GetFilename(
const std::string &_name =
"")
const;
155 public:
unsigned int GetFileSize(
const std::string &_name =
"")
const;
159 public:
void SetBasePath(
const std::string &_path);
163 public: std::string GetBasePath()
const;
174 public:
bool GetFirstUpdate()
const;
178 public:
void Write(
bool _force =
false);
182 public:
unsigned int GetBufferSize()
const;
189 private:
void Update();
192 private:
void RunUpdate();
195 private:
void RunWrite();
198 private:
void ClearLogs();
201 private:
void PublishLogStatus();
205 private:
void OnLogControl(ConstLogControlPtr &_data);
210 private:
void Cleanup();
213 private:
void OnPause(
bool _pause);
224 public: Log(
LogRecord *_parent,
const std::string &_relativeFilename,
225 boost::function<
bool (std::ostringstream &)> _logCB);
228 public:
virtual ~Log();
232 public:
void Start(
const boost::filesystem::path &_path);
238 public:
void Write();
242 public:
unsigned int Update();
245 public:
void ClearBuffer();
249 public:
unsigned int GetBufferSize();
254 public: std::string GetRelativeFilename()
const;
258 public: std::string GetCompleteFilename()
const;
264 public: boost::function<bool (std::ostringstream &)> logCB;
267 public: std::string buffer;
270 public: std::ofstream logFile;
273 public: std::string relativeFilename;
276 private: boost::filesystem::path completePath;
282 private:
typedef std::map<std::string, Log*> Log_M;
288 private: Log_M::iterator updateIter;
291 private: Log_M::iterator logsEnd;
294 private: boost::condition_variable startThreadCondition;
297 private: boost::condition_variable updateCondition;
300 private: boost::condition_variable cleanupCondition;
303 private:
bool running;
306 private: boost::thread *writeThread;
309 private: boost::thread *updateThread;
312 private: boost::thread cleanupThread;
315 private:
mutable boost::mutex writeMutex;
318 private:
mutable boost::mutex runWriteMutex;
321 private:
mutable boost::mutex updateMutex;
324 private: boost::mutex controlMutex;
328 private: boost::condition_variable dataAvailableCondition;
331 private: boost::filesystem::path logBasePath;
334 private: boost::filesystem::path logCompletePath;
338 private: std::string logSubDir;
341 private: std::string encoding;
344 private:
bool initialized;
347 private:
bool paused;
350 private:
bool firstUpdate;
353 private:
bool stopThread;
374 private:
bool pauseState;
381 private:
bool readyToStart;
Forward declarations for the common classes.
Definition: Animation.hh:33
boost::shared_ptr< Subscriber > SubscriberPtr
Definition: TransportTypes.hh:53
Forward declarations for transport.
Singleton template class.
Definition: SingletonT.hh:33
#define GZ_UTIL_VISIBLE
Definition: system.hh:266
addtogroup gazebo_util
Definition: LogRecord.hh:69
std::vector< ConnectionPtr > Connection_V
Definition: CommonTypes.hh:151
boost::shared_ptr< Node > NodePtr
Definition: TransportTypes.hh:57
GAZEBO_VISIBLE void Init(google::protobuf::Message &_message, const std::string &_id="")
Initialize a message.
boost::shared_ptr< Publisher > PublisherPtr
Definition: TransportTypes.hh:49
A Time class, can be used to hold wall- or sim-time.
Definition: Time.hh:39