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>
42 #define GZ_LOG_VERSION "1.0"
82 public:
bool Init(
const std::string &_subdir);
96 public:
void Add(
const std::string &_name,
const std::string &_filename,
97 boost::function<
bool (std::ostringstream &)> _logCallback);
107 public:
bool Remove(
const std::string &_name);
113 public:
void Notify();
119 public:
void SetPaused(
bool _paused);
124 public:
bool GetPaused()
const;
129 public:
bool IsReadyToStart()
const;
133 public:
bool GetRunning()
const;
138 public:
bool Start(
const std::string &_encoding=
"zlib",
139 const std::string &_path=
"");
144 public:
const std::string &GetEncoding()
const;
149 public: std::string GetFilename(
const std::string &_name =
"")
const;
154 public:
unsigned int GetFileSize(
const std::string &_name =
"")
const;
158 public:
void SetBasePath(
const std::string &_path);
162 public: std::string GetBasePath()
const;
173 public:
bool GetFirstUpdate()
const;
177 public:
void Write(
bool _force =
false);
181 public:
unsigned int GetBufferSize()
const;
188 private:
void Update();
191 private:
void RunUpdate();
194 private:
void RunWrite();
197 private:
void ClearLogs();
200 private:
void PublishLogStatus();
204 private:
void OnLogControl(ConstLogControlPtr &_data);
209 private:
void Cleanup();
212 private:
void OnPause(
bool _pause);
223 public: Log(
LogRecord *_parent,
const std::string &_relativeFilename,
224 boost::function<
bool (std::ostringstream &)> _logCB);
227 public:
virtual ~Log();
231 public:
void Start(
const boost::filesystem::path &_path);
237 public:
void Write();
241 public:
unsigned int Update();
244 public:
void ClearBuffer();
248 public:
unsigned int GetBufferSize();
253 public: std::string GetRelativeFilename()
const;
257 public: std::string GetCompleteFilename()
const;
263 public: boost::function<bool (std::ostringstream &)> logCB;
266 public: std::string buffer;
269 public: std::ofstream logFile;
272 public: std::string relativeFilename;
275 private: boost::filesystem::path completePath;
281 private:
typedef std::map<std::string, Log*> Log_M;
287 private: Log_M::iterator updateIter;
290 private: Log_M::iterator logsEnd;
293 private: boost::condition_variable startThreadCondition;
296 private: boost::condition_variable updateCondition;
299 private: boost::condition_variable cleanupCondition;
302 private:
bool running;
305 private: boost::thread *writeThread;
308 private: boost::thread *updateThread;
311 private: boost::thread cleanupThread;
314 private:
mutable boost::mutex writeMutex;
317 private:
mutable boost::mutex runWriteMutex;
320 private:
mutable boost::mutex updateMutex;
323 private: boost::mutex controlMutex;
327 private: boost::condition_variable dataAvailableCondition;
330 private: boost::filesystem::path logBasePath;
333 private: boost::filesystem::path logCompletePath;
337 private: std::string logSubDir;
340 private: std::string encoding;
343 private:
bool initialized;
346 private:
bool paused;
349 private:
bool firstUpdate;
352 private:
bool stopThread;
373 private:
bool pauseState;
380 private:
bool readyToStart;
boost::shared_ptr< Subscriber > SubscriberPtr
Definition: TransportTypes.hh:48
Forward declarations for transport.
Singleton template class.
Definition: SingletonT.hh:33
addtogroup gazebo_util
Definition: LogRecord.hh:68
std::vector< ConnectionPtr > Connection_V
Definition: CommonTypes.hh:148
boost::shared_ptr< Node > NodePtr
Definition: TransportTypes.hh:52
GAZEBO_VISIBLE void Init(google::protobuf::Message &_message, const std::string &_id="")
Initialize a message.
boost::shared_ptr< Publisher > PublisherPtr
Definition: TransportTypes.hh:44
#define GAZEBO_VISIBLE
Use to represent "symbol visible" if supported.
Definition: system.hh:48
A Time class, can be used to hold wall- or sim-time.
Definition: Time.hh:43