Goby3 3.2.3
2025.05.13
Loading...
Searching...
No Matches
json_log_plugin.h
Go to the documentation of this file.
1// Copyright 2016-2025:
2// GobySoft, LLC (2013-)
3// Community contributors (see AUTHORS file)
4// File authors:
5// Toby Schneider <toby@gobysoft.org>
6//
7//
8// This file is part of the Goby Underwater Autonomy Project Libraries
9// ("The Goby Libraries").
10//
11// The Goby Libraries are free software: you can redistribute them and/or modify
12// them under the terms of the GNU Lesser General Public License as published by
13// the Free Software Foundation, either version 2.1 of the License, or
14// (at your option) any later version.
15//
16// The Goby Libraries are distributed in the hope that they will be useful,
17// but WITHOUT ANY WARRANTY; without even the implied warranty of
18// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19// GNU Lesser General Public License for more details.
20//
21// You should have received a copy of the GNU Lesser General Public License
22// along with Goby. If not, see <http://www.gnu.org/licenses/>.
23
24#ifndef GOBY_MIDDLEWARE_LOG_JSON_LOG_PLUGIN_H
25#define GOBY_MIDDLEWARE_LOG_JSON_LOG_PLUGIN_H
26
27#include "goby/middleware/log.h"
30#include "goby/time/convert.h"
31#include "log_plugin.h"
32
33namespace goby
34{
35namespace middleware
36{
37namespace log
38{
39class JSONPlugin : public LogPlugin
40{
41 public:
42 std::string debug_text_message(LogEntry& log_entry) override
43 {
44 return parse_message(log_entry)->dump();
45 }
46
47 std::shared_ptr<nlohmann::json> json_message(LogEntry& log_entry) override
48 {
49 return parse_message(log_entry);
50 }
51
52 void register_read_hooks(const std::ifstream& in_log_file) override {}
53
54 void register_write_hooks(std::ofstream& out_log_file) override {}
55
56 std::shared_ptr<nlohmann::json> parse_message(LogEntry& log_entry)
57 {
58 const auto& data = log_entry.data();
59 auto bytes_begin = data.begin(), bytes_end = data.end(), actual_end = data.begin();
60 return SerializerParserHelper<nlohmann::json,
62 bytes_end,
63 actual_end);
64 }
65};
66
67} // namespace log
68} // namespace middleware
69} // namespace goby
70
71#endif
void register_write_hooks(std::ofstream &out_log_file) override
std::shared_ptr< nlohmann::json > parse_message(LogEntry &log_entry)
std::shared_ptr< nlohmann::json > json_message(LogEntry &log_entry) override
std::string debug_text_message(LogEntry &log_entry) override
void register_read_hooks(const std::ifstream &in_log_file) override
const std::vector< unsigned char > & data() const
Definition log_entry.h:148
The global namespace for the Goby project.
Class for parsing and serializing a given marshalling scheme. Must be specialized for a particular sc...
Definition interface.h:98