1
+ /*
2
+ * Copyright (c) 2014, Peter Thorson. All rights reserved.
3
+ *
4
+ * Redistribution and use in source and binary forms, with or without
5
+ * modification, are permitted provided that the following conditions are met:
6
+ * * Redistributions of source code must retain the above copyright
7
+ * notice, this list of conditions and the following disclaimer.
8
+ * * Redistributions in binary form must reproduce the above copyright
9
+ * notice, this list of conditions and the following disclaimer in the
10
+ * documentation and/or other materials provided with the distribution.
11
+ * * Neither the name of the WebSocket++ Project nor the
12
+ * names of its contributors may be used to endorse or promote products
13
+ * derived from this software without specific prior written permission.
14
+ *
15
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18
+ * ARE DISCLAIMED. IN NO EVENT SHALL PETER THORSON BE LIABLE FOR ANY
19
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
22
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25
+ *
26
+ *
27
+ * The initial version of this logging policy was contributed to the WebSocket++
28
+ * project by Tom Hughes.
29
+ */
30
+
1
31
#ifndef WEBSOCKETPP_LOGGER_SYSLOG_HPP
2
32
#define WEBSOCKETPP_LOGGER_SYSLOG_HPP
3
33
@@ -15,37 +45,71 @@ namespace log {
15
45
template <typename concurrency, typename names>
16
46
class syslog : public basic <concurrency, names> {
17
47
public:
18
- syslog<concurrency,names>(channel_type_hint::value h =
48
+ typedef basic<concurrency, names> base;
49
+
50
+ // / Construct the logger
51
+ /* *
52
+ * @param hint A channel type specific hint for how to construct the logger
53
+ */
54
+ syslog<concurrency,names>(channel_type_hint::value hint =
19
55
channel_type_hint::access)
20
- : basic<concurrency,names>(h ), channel_type_hint_(h ) {}
56
+ : basic<concurrency,names>(hint ), m_channel_type_hint(hint ) {}
21
57
22
- syslog<concurrency,names>(level c, channel_type_hint::value h =
58
+ // / Construct the logger
59
+ /* *
60
+ * @param channels A set of channels to statically enable
61
+ * @param hint A channel type specific hint for how to construct the logger
62
+ */
63
+ syslog<concurrency,names>(level channels, channel_type_hint::value hint =
23
64
channel_type_hint::access)
24
- : basic<concurrency,names>(c, h ), channel_type_hint_(h ) {}
65
+ : basic<concurrency,names>(channels, hint ), m_channel_type_hint(hint ) {}
25
66
67
+ // / Write a string message to the given channel
68
+ /* *
69
+ * @param channel The channel to write to
70
+ * @param msg The message to write
71
+ */
26
72
void write (level channel, std::string const & msg) {
27
73
write (channel, msg.c_str ());
28
74
}
29
75
76
+ // / Write a cstring message to the given channel
77
+ /* *
78
+ * @param channel The channel to write to
79
+ * @param msg The message to write
80
+ */
30
81
void write (level channel, char const * msg) {
31
- scoped_lock_type lock (basic<concurrency,names> ::m_lock);
82
+ scoped_lock_type lock (base ::m_lock);
32
83
if (!this ->dynamic_test (channel)) { return ; }
33
- ::syslog (syslog_priority(channel), "[%s] %s", names::channel_name(channel), msg);
84
+ ::syslog (syslog_priority(channel), "[%s] %s",
85
+ names::channel_name(channel), msg);
34
86
}
35
-
36
87
private:
37
- typedef typename basic<concurrency,names>::scoped_lock_type scoped_lock_type;
38
- const int kDefaultSyslogLevel = LOG_INFO;
88
+ typedef typename base::scoped_lock_type scoped_lock_type;
89
+
90
+ // / The default level is used for all access logs and any error logs that
91
+ // / don't trivially map to one of the standard syslog levels.
92
+ static int const default_level = LOG_INFO;
39
93
40
- const int syslog_priority (level channel) const {
41
- if (channel_type_hint_ == channel_type_hint::access ) {
94
+ // / retrieve the syslog priority code given a WebSocket++ channel
95
+ /* *
96
+ * @param channel The level to look up
97
+ * @return The syslog level associated with `channel`
98
+ */
99
+ int syslog_priority (level channel) const {
100
+ if (m_channel_type_hint == channel_type_hint::access ) {
42
101
return syslog_priority_access (channel);
43
102
} else {
44
103
return syslog_priority_error (channel);
45
104
}
46
105
}
47
106
48
- const int syslog_priority_error (level channel) const {
107
+ // / retrieve the syslog priority code given a WebSocket++ error channel
108
+ /* *
109
+ * @param channel The level to look up
110
+ * @return The syslog level associated with `channel`
111
+ */
112
+ int syslog_priority_error (level channel) const {
49
113
switch (channel) {
50
114
case elevel::devel:
51
115
return LOG_DEBUG;
@@ -60,15 +124,20 @@ class syslog : public basic<concurrency, names> {
60
124
case elevel::fatal:
61
125
return LOG_CRIT;
62
126
default :
63
- return kDefaultSyslogLevel ;
127
+ return default_level ;
64
128
}
65
129
}
66
130
67
- _WEBSOCKETPP_CONSTEXPR_TOKEN_ int syslog_priority_access (level channel) const {
68
- return kDefaultSyslogLevel ;
131
+ // / retrieve the syslog priority code given a WebSocket++ access channel
132
+ /* *
133
+ * @param channel The level to look up
134
+ * @return The syslog level associated with `channel`
135
+ */
136
+ _WEBSOCKETPP_CONSTEXPR_TOKEN_ int syslog_priority_access (level) const {
137
+ return default_level;
69
138
}
70
139
71
- channel_type_hint::value channel_type_hint_ ;
140
+ channel_type_hint::value m_channel_type_hint ;
72
141
};
73
142
74
143
} // log
0 commit comments