Loading...
Searching...
No Matches
logger.hpp
1/* Copyright (c) 2018-2024 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
100 void on_write(system::error_code const& ec, std::string const& payload);
101
108 void on_read(system::error_code const& ec, std::size_t n);
109
116 void on_hello(system::error_code const& ec, generic_response const& resp);
117
123 void set_prefix(std::string_view prefix)
124 {
125 prefix_ = prefix;
126 }
127
128 void trace(std::string_view message);
129 void trace(std::string_view op, system::error_code const& ec);
130
131private:
132 void write_prefix();
133 level level_;
134 std::string_view prefix_;
135};
136
137} // boost::redis
138
139#endif // BOOST_REDIS_LOGGER_HPP
Logger class.
Definition logger.hpp:27
logger(level l=level::debug)
Constructor.
Definition logger.hpp:67
void set_prefix(std::string_view prefix)
Sets a prefix to every log message.
Definition logger.hpp:123
level
Syslog-like log levels.
Definition logger.hpp:33
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.
adapter::result< std::vector< resp3::node > > generic_response
A generic response to a request.
Definition response.hpp:35
void on_write(system::error_code const &ec, std::string const &payload)
Called when the write operation completes.
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.