3#ifndef OCPP_COMMON_LOGGING_HPP
4#define OCPP_COMMON_LOGGING_HPP
12#include <ocpp/common/types.hpp>
38enum class LogRotationStatus {
48 std::string message_log_path;
49 std::string output_file_name;
51 bool detailed_log_to_console;
56 std::filesystem::path log_file;
58 std::filesystem::path html_log_file;
59 std::ofstream html_log_os;
60 std::filesystem::path security_log_file;
61 std::ofstream security_log_os;
62 std::mutex output_file_mutex;
63 std::function<void(
const std::string& message, MessageDirection direction)> message_callback;
64 std::function<void(LogRotationStatus status)> status_callback;
65 std::map<std::string, std::string> lookup_map;
66 std::recursive_mutex session_id_logging_mutex;
67 std::map<std::string, std::shared_ptr<MessageLogging>> session_id_logging;
70 std::string logfile_basename;
71 uint64_t maximum_file_size_bytes;
72 uint64_t maximum_file_count;
78 void log_output(
unsigned int typ,
const std::string& message_type,
const std::string& json_str);
81 std::string html_encode(
const std::string& msg);
87 void open_html_tags(std::ofstream& os);
90 void close_html_tags(std::ofstream& os);
93 std::string get_datetime_string();
96 std::uintmax_t file_size(
const std::filesystem::path& path);
100 LogRotationStatus rotate_log(
const std::string& file_basename);
103 LogRotationStatus rotate_log_if_needed(
const std::filesystem::path& path, std::ofstream& os);
107 LogRotationStatus rotate_log_if_needed(
const std::filesystem::path& path, std::ofstream& os,
108 std::function<
void(std::ofstream& os)> before_close_of_os,
109 std::function<
void(std::ofstream& os)> after_open_of_os);
114 bool log_messages,
const std::string& message_log_path,
const std::string& output_file_name,
115 bool log_to_console,
bool detailed_log_to_console,
bool log_to_file,
bool log_to_html,
bool log_security,
116 bool session_logging,
117 std::function<
void(
const std::string& message, MessageDirection direction)> message_callback);
121 bool log_messages,
const std::string& message_log_path,
const std::string& output_file_name,
122 bool log_to_console,
bool detailed_log_to_console,
bool log_to_file,
bool log_to_html,
bool log_security,
123 bool session_logging,
124 std::function<
void(
const std::string& message, MessageDirection direction)> message_callback,
125 LogRotationConfig log_rotation_config, std::function<
void(LogRotationStatus status)> status_callback);
129 void charge_point(
const std::string& message_type,
const std::string& json_str);
132 void central_system(
const std::string& message_type,
const std::string& json_str);
135 void sys(
const std::string& msg);
138 void security(
const std::string& msg);
contains a ocpp message logging abstraction
Definition: ocpp_logging.hpp:45
void central_system(const std::string &message_type, const std::string &json_str)
Log a message originating from the central system.
Definition: ocpp_logging.cpp:290
MessageLogging(bool log_messages, const std::string &message_log_path, const std::string &output_file_name, bool log_to_console, bool detailed_log_to_console, bool log_to_file, bool log_to_html, bool log_security, bool session_logging, std::function< void(const std::string &message, MessageDirection direction)> message_callback)
Creates a new MessageLogging object with the provided configuration.
Definition: ocpp_logging.cpp:17
bool session_logging_active()
Definition: ocpp_logging.cpp:428
void security(const std::string &msg)
Log a security message.
Definition: ocpp_logging.cpp:314
void stop_session_logging(const std::string &session_id)
Stop session logging.
Definition: ocpp_logging.cpp:413
std::string get_message_log_path()
Definition: ocpp_logging.cpp:424
void start_session_logging(const std::string &session_id, const std::string &log_path)
Start session logging (without log rotation)
Definition: ocpp_logging.cpp:407
void sys(const std::string &msg)
Log a system message.
Definition: ocpp_logging.cpp:304
void charge_point(const std::string &message_type, const std::string &json_str)
Log a message originating from the charge point.
Definition: ocpp_logging.cpp:276
Configuration for log rotation.
Definition: ocpp_logging.hpp:24
uint64_t maximum_file_size_bytes
The maximum size of the log file in bytes after which the file will be rotated.
Definition: ocpp_logging.hpp:28
bool date_suffix
Definition: ocpp_logging.hpp:25
uint64_t maximum_file_count
The maximum number of log files to keep in rotation.
Definition: ocpp_logging.hpp:29