Boost.Redis 1.4.2
A redis client library
Loading...
Searching...
No Matches
logger.hpp
1/* Copyright (c) 2018-2023 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_LOGGER_HPP
8#define BOOST_REDIS_LOGGER_HPP
9
10#include <boost/redis/response.hpp>
11#include <boost/asio/ip/tcp.hpp>
12#include <string>
13
14namespace boost::system {class error_code;}
15
16namespace boost::redis {
17
27class logger {
28public:
32 enum class level
33 {
36
38 emerg,
39
41 alert,
42
44 crit,
45
47 err,
48
50 warning,
51
53 notice,
54
56 info,
57
59 debug
60 };
61
68 : level_{l}
69 {}
70
77 void on_resolve(system::error_code const& ec, asio::ip::tcp::resolver::results_type const& res);
78
85 void on_connect(system::error_code const& ec, asio::ip::tcp::endpoint const& ep);
86
92 void on_ssl_handshake(system::error_code const& ec);
93
99 void on_connection_lost(system::error_code const& ec);
100
107 void on_write(system::error_code const& ec, std::string const& payload);
108
115 void on_read(system::error_code const& ec, std::size_t n);
116
123 void on_run(system::error_code const& reader_ec, system::error_code const& writer_ec);
124
131 void on_hello(system::error_code const& ec, generic_response const& resp);
132
138 void set_prefix(std::string_view prefix)
139 {
140 prefix_ = prefix;
141 }
142
150 void
152 system::error_code const& run_all_ec,
153 system::error_code const& health_check_ec,
154 system::error_code const& hello_ec);
155
156 void
157 on_check_health(
158 system::error_code const& ping_ec,
159 system::error_code const& check_timeout_ec);
160
161 void trace(std::string_view reason);
162
163private:
164 void write_prefix();
165 level level_;
166 std::string_view prefix_;
167};
168
169} // boost::redis
170
171#endif // BOOST_REDIS_LOGGER_HPP
Logger class.
Definition: logger.hpp:27
void on_runner(system::error_code const &run_all_ec, system::error_code const &health_check_ec, system::error_code const &hello_ec)
Called when the runner operation completes.
void on_run(system::error_code const &reader_ec, system::error_code const &writer_ec)
Called when the run operation completes.
void set_prefix(std::string_view prefix)
Sets a prefix to every log message.
Definition: logger.hpp:138
level
Syslog-like log levels.
Definition: logger.hpp:33
adapter::result< std::vector< resp3::node > > generic_response
A generic response to a request.
Definition: response.hpp:35
void on_resolve(system::error_code const &ec, asio::ip::tcp::resolver::results_type const &res)
Called when the resolve operation completes.
void on_ssl_handshake(system::error_code const &ec)
Called when the ssl handshake operation completes.
void on_connect(system::error_code const &ec, asio::ip::tcp::endpoint const &ep)
Called when the connect operation completes.
void on_write(system::error_code const &ec, std::string const &payload)
Called when the write operation completes.
logger(level l=level::disabled)
Constructor.
Definition: logger.hpp:67
void on_hello(system::error_code const &ec, generic_response const &resp)
Called when the HELLO request completes.
void on_read(system::error_code const &ec, std::size_t n)
Called when the read operation completes.
void on_connection_lost(system::error_code const &ec)
Called when the connection is lost.