Loading...
Searching...
No Matches
connection_logger.hpp
1/* Copyright (c) 2018-2025 Marcelo Zimbres Silva (mzimbres@gmail.com)
2 *
3 * Distributed under the Boost Software License, Version 1.0. (See
4 * accompanying file LICENSE.txt)
5 */
6
7#ifndef BOOST_REDIS_CONNECTION_LOGGER_HPP
8#define BOOST_REDIS_CONNECTION_LOGGER_HPP
9
10#include <boost/redis/detail/reader_fsm.hpp>
11#include <boost/redis/logger.hpp>
12#include <boost/redis/response.hpp>
13
14#include <boost/asio/ip/tcp.hpp>
15#include <boost/system/error_code.hpp>
16
17#include <string_view>
18
19namespace boost::redis::detail {
20
21// Wraps a logger and a string buffer for re-use, and provides
22// utility functions to format the log messages that we use.
23// The long-term trend will be moving most of this class to finite state
24// machines as we write them
25class connection_logger {
26 logger logger_;
27 std::string msg_;
28
29public:
30 connection_logger(logger&& logger) noexcept
31 : logger_(std::move(logger))
32 { }
33
34 void reset(logger&& logger) { logger_ = std::move(logger); }
35
36 void on_resolve(system::error_code const& ec, asio::ip::tcp::resolver::results_type const& res);
37 void on_connect(system::error_code const& ec, asio::ip::tcp::endpoint const& ep);
38 void on_connect(system::error_code const& ec, std::string_view unix_socket_ep);
39 void on_ssl_handshake(system::error_code const& ec);
40 void on_write(system::error_code const& ec, std::size_t n);
41 void on_fsm_resume(reader_fsm::action const& action);
42 void on_hello(system::error_code const& ec, generic_response const& resp);
43 void log(logger::level lvl, std::string_view msg);
44 void log(logger::level lvl, std::string_view op, system::error_code const& ec);
45 void trace(std::string_view message) { log(logger::level::debug, message); }
46 void trace(std::string_view op, system::error_code const& ec)
47 {
48 log(logger::level::debug, op, ec);
49 }
50};
51
52} // namespace boost::redis::detail
53
54#endif // BOOST_REDIS_LOGGER_HPP
level
Syslog-like log levels.
Definition logger.hpp:25
adapter::result< std::vector< resp3::node > > generic_response
A generic response to a request.
Definition response.hpp:35