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 <string>
22 
23 #include "gazebo/msgs/msgs.hh"
25 #include "gazebo/util/system.hh"
26 
27 #define GZ_LOG_VERSION "1.0"
28 
29 namespace gazebo
30 {
31  namespace util
32  {
36  {
38  public: std::string encoding = "zlib";
39 
41  public: std::string path;
42 
45  public: double period = -1;
46 
48  public: std::string filter;
49  };
50 
51  // Forward declare private data class
52  class LogRecordPrivate;
53 
56 
74  class GZ_UTIL_VISIBLE LogRecord : public SingletonT<LogRecord>
75  {
77  private: LogRecord();
78 
80  private: virtual ~LogRecord();
81 
88  public: bool Init(const std::string &_subdir);
89 
102  public: void Add(const std::string &_name, const std::string &_filename,
103  std::function<bool (std::ostringstream &)> _logCallback);
104 
113  public: bool Remove(const std::string &_name);
114 
116  public: void Stop();
117 
119  public: void Notify();
120 
125  public: void SetPaused(const bool _paused);
126 
130  public: bool Paused() const;
131 
134  public: double Period() const;
135 
138  public: void SetPeriod(const double _period);
139 
142  public: std::string Filter() const;
143 
146  public: void SetFilter(const std::string &_filter);
147 
150  // \return True if logger is ready to start.
151  public: bool IsReadyToStart() const;
152 
155  public: bool Running() const;
156 
159  public: bool Start(const LogRecordParams &_params);
160 
164  public: bool Start(const std::string &_encoding="zlib",
165  const std::string &_path="");
166 
170  public: const std::string &Encoding() const;
171 
175  public: std::string Filename(const std::string &_name = "") const;
176 
180  public: unsigned int FileSize(const std::string &_name = "") const;
181 
184  public: void SetBasePath(const std::string &_path);
185 
188  public: std::string BasePath() const;
189 
192  public: common::Time RunTime() const;
193 
195  public: void Fini();
196 
199  public: bool FirstUpdate() const;
200 
203  public: void Write(const bool _force = false);
204 
207  public: unsigned int BufferSize() const;
208 
213  private: void Update();
214 
216  private: void RunUpdate();
217 
219  private: void RunWrite();
220 
222  private: void ClearLogs();
223 
225  private: void PublishLogStatus();
226 
229  private: void OnLogControl(ConstLogControlPtr &_data);
230 
234  private: void Cleanup();
235 
237  private: void OnPause(const bool _pause);
238 
240  private: friend class SingletonT<LogRecord>;
241 
244  private: std::unique_ptr<LogRecordPrivate> dataPtr;
245  };
247  }
248 }
249 #endif
double period
Recording period.
Definition: LogRecord.hh:45
Singleton template class.
Definition: SingletonT.hh:33
std::string encoding
The type of encoding (txt, zlib, or bz2).
Definition: LogRecord.hh:38
addtogroup gazebo_util
Definition: LogRecord.hh:74
Log recording parameters.
Definition: LogRecord.hh:35
std::string filter
Log filter string.
Definition: LogRecord.hh:48
GAZEBO_VISIBLE void Init(google::protobuf::Message &_message, const std::string &_id="")
Initialize a message.
std::string path
Path in which to store log files.
Definition: LogRecord.hh:41
A Time class, can be used to hold wall- or sim-time.
Definition: Time.hh:44