28 #ifndef WEBSOCKETPP_LOGGER_BASIC_HPP
29 #define WEBSOCKETPP_LOGGER_BASIC_HPP
47 #include <websocketpp/common/cpp11.hpp>
48 #include <websocketpp/common/stdint.hpp>
49 #include <websocketpp/common/time.hpp>
50 #include <websocketpp/logger/levels.hpp>
56 template <
typename concurrency,
typename names>
61 : m_static_channels(0xffffffff)
62 , m_dynamic_channels(0)
66 : m_static_channels(0xffffffff)
67 , m_dynamic_channels(0)
72 : m_static_channels(c)
73 , m_dynamic_channels(0)
77 : m_static_channels(c)
78 , m_dynamic_channels(0)
81 void set_ostream(std::ostream * out = &std::cout) {
85 void set_channels(level channels) {
86 if (channels == names::none) {
87 clear_channels(names::all);
91 scoped_lock_type lock(m_lock);
92 m_dynamic_channels |= (channels & m_static_channels);
95 void clear_channels(level channels) {
96 scoped_lock_type lock(m_lock);
97 m_dynamic_channels &= ~channels;
100 void write(level channel, std::string
const & msg) {
101 scoped_lock_type lock(m_lock);
102 if (!this->dynamic_test(channel)) {
return; }
103 *m_out <<
"[" << timestamp <<
"] "
104 <<
"[" << names::channel_name(channel) <<
"] "
109 void write(level channel,
char const * msg) {
110 scoped_lock_type lock(m_lock);
111 if (!this->dynamic_test(channel)) {
return; }
112 *m_out <<
"[" << timestamp <<
"] "
113 <<
"[" << names::channel_name(channel) <<
"] "
118 _WEBSOCKETPP_CONSTEXPR_TOKEN_
bool static_test(level channel)
const {
119 return ((channel & m_static_channels) != 0);
122 bool dynamic_test(level channel) {
123 return ((channel & m_dynamic_channels) != 0);
126 typedef typename concurrency::scoped_lock_type scoped_lock_type;
127 typedef typename concurrency::mutex_type mutex_type;
134 static std::ostream & timestamp(std::ostream & os) {
135 std::time_t t = std::time(NULL);
136 std::tm lt = lib::localtime(t);
137 #ifdef _WEBSOCKETPP_PUTTIME_
138 return os << std::put_time(<,
"%Y-%m-%d %H:%M:%S");
139 #else // Falls back to strftime, which requires a temporary copy of the string.
141 size_t result = std::strftime(buffer,
sizeof(buffer),
"%Y-%m-%d %H:%M:%S",<);
142 return os << (result == 0 ?
"Unknown" : buffer);
148 level
const m_static_channels;
149 level m_dynamic_channels;
150 std::ostream * m_out;
156 #endif // WEBSOCKETPP_LOGGER_BASIC_HPP
uint32_t value
Type of a channel type hint value.
static value const access
Access log.
static value const error
Error log.
Basic logger that outputs to an ostream.
Namespace for the WebSocket++ project.