ekf_cal  0.4.0
A Kalman filter-based sensor calibration package
data_logger.hpp
1 // Copyright 2023 Jacob Hartzer
2 //
3 // This program is free software: you can redistribute it and/or modify
4 // it under the terms of the GNU General Public License as published by
5 // the Free Software Foundation, either version 3 of the License, or
6 // (at your option) any later version.
7 //
8 // This program is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 // GNU General Public License for more details.
12 //
13 // You should have received a copy of the GNU General Public License
14 // along with this program. If not, see <https://www.gnu.org/licenses/>.
15 
16 #ifndef INFRASTRUCTURE__DATA_LOGGER_HPP_
17 #define INFRASTRUCTURE__DATA_LOGGER_HPP_
18 
19 #include <string>
20 #include <fstream>
21 
26 {
27 public:
28  DataLogger() {}
29 
35  DataLogger(const std::string & log_directory, const std::string & file_name);
36 
43  DataLogger(const std::string & log_directory, const std::string & file_name, double logging_rate);
44 
49  void Log(const std::string & message);
50 
56  void RateLimitedLog(const std::string & message, double time);
57 
62  void DefineHeader(const std::string & header);
63 
67  void EnableLogging();
68 
73  void SetOutputDirectory(const std::string & log_directory);
74 
79  void SetOutputFileName(const std::string & file_name);
80 
85  void SetLogRate(double rate);
86 
87 private:
88  bool m_initialized{false};
89  std::string m_log_header{""};
90  std::ofstream m_log_file;
91  bool m_logging_on {false};
92  std::string m_log_directory {""};
93  std::string m_file_name {"default.log"};
94  double m_rate{0.0};
95  double m_time_init{0};
96  unsigned int m_log_count{0};
97 };
98 
99 #endif // INFRASTRUCTURE__DATA_LOGGER_HPP_
DataLogger class.
Definition: data_logger.hpp:26
void Log(const std::string &message)
Log message.
Definition: data_logger.cpp:36
void DefineHeader(const std::string &header)
Function to set the output file header.
Definition: data_logger.cpp:83
void SetLogRate(double rate)
Data logging rate setter.
Definition: data_logger.cpp:88
void RateLimitedLog(const std::string &message, double time)
Log rate-limited messages.
Definition: data_logger.cpp:49
void SetOutputDirectory(const std::string &log_directory)
Output directory setter.
Definition: data_logger.cpp:71
void EnableLogging()
Function to enable logging.
Definition: data_logger.cpp:65
void SetOutputFileName(const std::string &file_name)
Output file name setter.
Definition: data_logger.cpp:77