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/logger/levels.hpp>
55 template <
typename concurrency,
typename names>
59 : m_static_channels(0xffffffff)
60 , m_dynamic_channels(0)
64 : m_static_channels(c)
65 , m_dynamic_channels(0)
68 void set_ostream(std::ostream * out = &std::cout) {
72 void set_channels(level channels) {
73 if (channels == names::none) {
74 clear_channels(names::all);
78 scoped_lock_type lock(m_lock);
79 m_dynamic_channels |= (channels & m_static_channels);
82 void clear_channels(level channels) {
83 scoped_lock_type lock(m_lock);
84 m_dynamic_channels &= ~channels;
87 void write(level channel, std::string
const & msg) {
88 scoped_lock_type lock(m_lock);
89 if (!this->dynamic_test(channel)) {
return; }
90 *m_out <<
"[" << timestamp <<
"] "
91 <<
"[" << names::channel_name(channel) <<
"] "
96 void write(level channel,
char const * msg) {
97 scoped_lock_type lock(m_lock);
98 if (!this->dynamic_test(channel)) {
return; }
99 *m_out <<
"[" << timestamp <<
"] "
100 <<
"[" << names::channel_name(channel) <<
"] "
105 _WEBSOCKETPP_CONSTEXPR_TOKEN_
bool static_test(level channel)
const {
106 return ((channel & m_static_channels) != 0);
109 bool dynamic_test(level channel) {
110 return ((channel & m_dynamic_channels) != 0);
113 typedef typename concurrency::scoped_lock_type scoped_lock_type;
114 typedef typename concurrency::mutex_type mutex_type;
121 static std::ostream & timestamp(std::ostream & os) {
122 std::time_t t = std::time(NULL);
123 std::tm* lt = std::localtime(&t);
124 #ifdef _WEBSOCKETPP_CPP11_CHRONO_
125 return os << std::put_time(lt,
"%Y-%m-%d %H:%M:%S");
126 #else // Falls back to strftime, which requires a temporary copy of the string.
128 std::strftime(buffer,
sizeof(buffer),
"%Y-%m-%d %H:%M:%S",lt);
135 level
const m_static_channels;
136 level m_dynamic_channels;
137 std::ostream * m_out;
143 #endif // WEBSOCKETPP_LOGGER_BASIC_HPP
Basic logger that outputs to an ostream.
Namespace for the WebSocket++ project.