LogRecord.hh
Go to the documentation of this file.
1/*
2 * Copyright (C) 2012 Open Source Robotics Foundation
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *
16*/
17#ifndef _GAZEBO_UTIL_LOGRECORD_HH_
18#define _GAZEBO_UTIL_LOGRECORD_HH_
19
20#include <fstream>
21#include <set>
22#include <string>
23
24#include "gazebo/msgs/msgs.hh"
26#include "gazebo/util/system.hh"
27
28#define GZ_LOG_VERSION "1.0"
29
31GZ_SINGLETON_DECLARE(GZ_UTIL_VISIBLE, gazebo, util, LogRecord)
32
33namespace gazebo
34{
35 namespace util
36 {
40 {
42 public: std::string encoding = "zlib";
43
45 public: std::string path;
46
49 public: double period = -1;
50
52 public: std::string filter;
53
56 public: bool recordResources = false;
57 };
58
59 // Forward declare private data class
60 class LogRecordPrivate;
61
64
82 class GZ_UTIL_VISIBLE LogRecord : public SingletonT<LogRecord>
83 {
85 private: LogRecord();
86
88 private: virtual ~LogRecord();
89
96 public: bool Init(const std::string &_subdir);
97
110 public: void Add(const std::string &_name, const std::string &_filename,
111 std::function<bool (std::ostringstream &)> _logCallback);
112
121 public: bool Remove(const std::string &_name);
122
124 public: void Stop();
125
127 public: void Notify();
128
133 public: void SetPaused(const bool _paused);
134
138 public: bool Paused() const;
139
142 public: double Period() const;
143
146 public: void SetPeriod(const double _period);
147
150 public: std::string Filter() const;
151
154 public: void SetFilter(const std::string &_filter);
155
159 public: bool RecordResources() const;
160
163 public: void SetRecordResources(const bool _record);
164
167 // \return True if logger is ready to start.
168 public: bool IsReadyToStart() const;
169
172 public: bool Running() const;
173
176 public: bool Start(const LogRecordParams &_params);
177
181 public: bool Start(const std::string &_encoding="zlib",
182 const std::string &_path="");
183
187 public: const std::string &Encoding() const;
188
192 public: std::string Filename(const std::string &_name = "") const;
193
197 public: unsigned int FileSize(const std::string &_name = "") const;
198
201 public: void SetBasePath(const std::string &_path);
202
205 public: std::string BasePath() const;
206
209 public: common::Time RunTime() const;
210
212 public: void Fini();
213
216 public: bool FirstUpdate() const;
217
220 public: bool SaveModels(const std::set<std::string> &models);
221
225 public: bool SaveFiles(const std::set<std::string> &resources);
226
229 public: void Write(const bool _force = false);
230
233 public: unsigned int BufferSize() const;
234
239 private: void Update();
240
242 private: void RunUpdate();
243
245 private: void RunWrite();
246
248 private: void ClearLogs();
249
251 private: void PublishLogStatus();
252
255 private: void OnLogControl(ConstLogControlPtr &_data);
256
260 private: void Cleanup();
261
263 private: void OnPause(const bool _pause);
264
266 private: friend class SingletonT<LogRecord>;
267
270 private: std::unique_ptr<LogRecordPrivate> dataPtr;
271 };
273 }
274}
275#endif
util
Definition Diagnostics.hh:33
gazebo
Definition LogRecord.hh:31
util
Definition LogRecord.hh:31
Singleton template class.
Definition SingletonT.hh:34
A Time class, can be used to hold wall- or sim-time.
Definition Time.hh:48
Log recording parameters.
Definition LogRecord.hh:40
std::string encoding
The type of encoding (txt, zlib, or bz2).
Definition LogRecord.hh:42
std::string path
Path in which to store log files.
Definition LogRecord.hh:45
std::string filter
Log filter string.
Definition LogRecord.hh:52
bool recordResources
Recording resources.
Definition LogRecord.hh:56
double period
Recording period.
Definition LogRecord.hh:49
addtogroup gazebo_util
Definition LogRecord.hh:83
void Fini()
Finialize, and shutdown.
void Add(const std::string &_name, const std::string &_filename, std::function< bool(std::ostringstream &)> _logCallback)
Add an object to a log file.
bool Remove(const std::string &_name)
Remove an entity from a log.
void Stop()
Stop the logger.
bool Paused() const
Get whether logging is paused.
const std::string & Encoding() const
Get the encoding used.
std::string Filter() const
Get the log recording filter string.
bool RecordResources() const
Get whether the model meshes and materials are saved when recording.
common::Time RunTime() const
Get the run time in sim time.
std::string Filename(const std::string &_name="") const
Get the filename for a log object.
void SetPeriod(const double _period)
Set the log recording period.
void SetBasePath(const std::string &_path)
Set the base path.
bool SaveModels(const std::set< std::string > &models)
Return true if all the models are saved successfully.
void SetPaused(const bool _paused)
Set whether logging should pause.
void Notify()
Tell the recorder that an update should occur.
bool IsReadyToStart() const
Get whether the logger is ready to start, which implies that any previous runs have finished.
void Write(const bool _force=false)
Write all logs.
bool Start(const std::string &_encoding="zlib", const std::string &_path="")
Start the logger.
void SetFilter(const std::string &_filter)
Set the log recording filter string.
unsigned int BufferSize() const
Get the size of the buffer.
bool Running() const
Get whether logging is running.
double Period() const
Get the log recording period.
bool Start(const LogRecordParams &_params)
Start the logger.
std::string BasePath() const
Get the base path for a log recording.
unsigned int FileSize(const std::string &_name="") const
Get the file size for a log object.
bool FirstUpdate() const
Return true if an Update has not yet been completed.
bool SaveFiles(const std::set< std::string > &resources)
Return true if all the files are saved successfully.
bool Init(const std::string &_subdir)
Initialize logging into a subdirectory.
void SetRecordResources(const bool _record)
Set whether to save model meshes and materials when recording.
#define GZ_SINGLETON_DECLARE(visibility, n1, n2, singletonType)
Helper to declare typed SingletonT.
Definition SingletonT.hh:58
Forward declarations for the common classes.
Definition Animation.hh:27