ifm3d
log_formatter_json.h
1 // -*- c++ -*-
2 /*
3  * Copyright 2023-present ifm electronic, gmbh
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #ifndef IFM3D_COMMON_LOGGING_LOG_FORMATTER_JSON_H
8 #define IFM3D_COMMON_LOGGING_LOG_FORMATTER_JSON_H
9 
10 #include <cstring>
11 
12 #include <fmt/format.h>
13 
14 #include <ifm3d/common/json.hpp>
15 #include <ifm3d/common/logging/log_entry.h>
16 
17 namespace ifm3d
18 {
20  {
21  public:
22  static std::string
23  format(const LogEntry& entry)
24  {
25 
26  return json::object(
27  {
28  {"time",
29  fmt::format("{:%Y-%m-%dT%H:%M:%S%z}", entry.GetTime())},
30  {"msg", entry.GetMessage()},
31  {"file",
32  fmt::format("{}:{}", entry.GetFile(), entry.GetLine())},
33  {"level", LogLevelToString(entry.GetLogLevel())},
34  })
35  .dump();
36 
37  return {};
38  }
39  };
40 }
41 #endif // IFM3D_COMMON_LOGGING_LOG_FORMATTER_JSON_H
ifm3d::LogFormatterJson
Definition: log_formatter_json.h:19
ifm3d::LogEntry
Definition: log_entry.h:19