summaryrefslogtreecommitdiff
path: root/libs/log/doc/html/boost/log/sinks/syslog_backend.html
blob: 095a3cfceb7fcb6211bcd6c9f34458aa4f5f9ef5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>Class syslog_backend</title>
<link rel="stylesheet" href="../../../../../../../doc/src/boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.78.1">
<link rel="home" href="../../../index.html" title="Chapter&#160;1.&#160;Boost.Log v2">
<link rel="up" href="../../../sinks.html#header.boost.log.sinks.syslog_backend_hpp" title="Header &lt;boost/log/sinks/syslog_backend.hpp&gt;">
<link rel="prev" href="syslog/custom_severity_mapping.html" title="Class template custom_severity_mapping">
<link rel="next" href="syslog/make_level.html" title="Function make_level">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr><td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../../../boost.png"></td></tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="syslog/custom_severity_mapping.html"><img src="../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../../../sinks.html#header.boost.log.sinks.syslog_backend_hpp"><img src="../../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../../index.html"><img src="../../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="syslog/make_level.html"><img src="../../../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
<div class="refentry">
<a name="boost.log.sinks.syslog_backend"></a><div class="titlepage"></div>
<div class="refnamediv">
<h2><span class="refentrytitle">Class syslog_backend</span></h2>
<p>boost::log::sinks::syslog_backend &#8212; An implementation of a syslog sink backend. </p>
</div>
<h2 xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="refsynopsisdiv-title">Synopsis</h2>
<div xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="refsynopsisdiv"><pre class="synopsis"><span class="comment">// In header: &lt;<a class="link" href="../../../sinks.html#header.boost.log.sinks.syslog_backend_hpp" title="Header &lt;boost/log/sinks/syslog_backend.hpp&gt;">boost/log/sinks/syslog_backend.hpp</a>&gt;

</span>
<span class="keyword">class</span> <a class="link" href="syslog_backend.html" title="Class syslog_backend">syslog_backend</a> <span class="special">:</span> <span class="keyword">public</span> <span class="identifier">basic_formatted_sink_backend</span><span class="special">&lt;</span> <span class="keyword">char</span> <span class="special">&gt;</span> <span class="special">{</span>
<span class="keyword">public</span><span class="special">:</span>
  <span class="comment">// types</span>
  <span class="keyword">typedef</span> <span class="identifier">base_type</span><span class="special">::</span><span class="identifier">char_type</span>   <a name="boost.log.sinks.syslog_backend.char_type"></a><span class="identifier">char_type</span><span class="special">;</span>             <span class="comment">// Character type. </span>
  <span class="keyword">typedef</span> <span class="identifier">base_type</span><span class="special">::</span><span class="identifier">string_type</span> <a name="boost.log.sinks.syslog_backend.string_type"></a><span class="identifier">string_type</span><span class="special">;</span>           <span class="comment">// String type that is used to pass message test. </span>
  <span class="keyword">typedef</span> <span class="emphasis"><em><span class="identifier">unspecified</span></em></span>            <a name="boost.log.sinks.syslog_backend.severity_mapper_type"></a><span class="identifier">severity_mapper_type</span><span class="special">;</span>  <span class="comment">// Syslog severity level mapper type. </span>

  <span class="comment">// <a class="link" href="syslog_backend.html#boost.log.sinks.syslog_backendconstruct-copy-destruct">construct/copy/destruct</a></span>
  <a class="link" href="syslog_backend.html#idp38062112-bb"><span class="identifier">syslog_backend</span></a><span class="special">(</span><span class="special">)</span><span class="special">;</span>
  <span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">typename</span><span class="special">...</span> ArgsT<span class="special">&gt;</span> <span class="keyword">explicit</span> <a class="link" href="syslog_backend.html#idp38063328-bb"><span class="identifier">syslog_backend</span></a><span class="special">(</span><span class="identifier">ArgsT</span><span class="special">...</span><span class="keyword">const</span> <span class="special">&amp;</span><span class="special">)</span><span class="special">;</span>
  <a class="link" href="syslog_backend.html#idp38074192-bb"><span class="special">~</span><span class="identifier">syslog_backend</span></a><span class="special">(</span><span class="special">)</span><span class="special">;</span>

  <span class="comment">// <a class="link" href="syslog_backend.html#idp38038096-bb">public member functions</a></span>
  <span class="keyword">void</span> <a class="link" href="syslog_backend.html#idp38038656-bb"><span class="identifier">set_severity_mapper</span></a><span class="special">(</span><span class="identifier">severity_mapper_type</span> <span class="keyword">const</span> <span class="special">&amp;</span><span class="special">)</span><span class="special">;</span>
  <span class="keyword">void</span> <a class="link" href="syslog_backend.html#idp38040704-bb"><span class="identifier">set_local_address</span></a><span class="special">(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span> <span class="keyword">const</span> <span class="special">&amp;</span><span class="special">,</span> <span class="keyword">unsigned</span> <span class="keyword">short</span> <span class="special">=</span> <span class="number">514</span><span class="special">)</span><span class="special">;</span>
  <span class="keyword">void</span> <a class="link" href="syslog_backend.html#idp38045344-bb"><span class="identifier">set_local_address</span></a><span class="special">(</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">asio</span><span class="special">::</span><span class="identifier">ip</span><span class="special">::</span><span class="identifier">address</span> <span class="keyword">const</span> <span class="special">&amp;</span><span class="special">,</span> 
                         <span class="keyword">unsigned</span> <span class="keyword">short</span> <span class="special">=</span> <span class="number">514</span><span class="special">)</span><span class="special">;</span>
  <span class="keyword">void</span> <a class="link" href="syslog_backend.html#idp38049936-bb"><span class="identifier">set_target_address</span></a><span class="special">(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span> <span class="keyword">const</span> <span class="special">&amp;</span><span class="special">,</span> <span class="keyword">unsigned</span> <span class="keyword">short</span> <span class="special">=</span> <span class="number">514</span><span class="special">)</span><span class="special">;</span>
  <span class="keyword">void</span> <a class="link" href="syslog_backend.html#idp38054608-bb"><span class="identifier">set_target_address</span></a><span class="special">(</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">asio</span><span class="special">::</span><span class="identifier">ip</span><span class="special">::</span><span class="identifier">address</span> <span class="keyword">const</span> <span class="special">&amp;</span><span class="special">,</span> 
                          <span class="keyword">unsigned</span> <span class="keyword">short</span> <span class="special">=</span> <span class="number">514</span><span class="special">)</span><span class="special">;</span>
  <span class="keyword">void</span> <a class="link" href="syslog_backend.html#idp38059248-bb"><span class="identifier">consume</span></a><span class="special">(</span><span class="identifier">record_view</span> <span class="keyword">const</span> <span class="special">&amp;</span><span class="special">,</span> <span class="identifier">string_type</span> <span class="keyword">const</span> <span class="special">&amp;</span><span class="special">)</span><span class="special">;</span>
<span class="special">}</span><span class="special">;</span></pre></div>
<div class="refsect1">
<a name="idp109184080"></a><h2>Description</h2>
<p>The backend provides support for the syslog protocol, defined in RFC3164. The backend sends log records to a remote host via UDP. The host name can be specified by calling the <code class="computeroutput">set_target_address</code> method. By default log records will be sent to localhost:514. The local address can be specified as well, by calling the <code class="computeroutput">set_local_address</code> method. By default syslog packets will be sent from any local address available.</p>
<p>It is safe to create several sink backends with the same local addresses - the backends within the process will share the same socket. The same applies to different processes that use the syslog backends to send records from the same socket. However, it is not guaranteed to work if some third party facility is using the socket.</p>
<p>On systems with native syslog implementation it may be preferable to utilize the POSIX syslog API instead of direct socket management in order to bypass possible security limitations that may be in action. To do so one has to pass the <code class="computeroutput">use_impl = native</code> to the backend constructor. Note, however, that in that case you will only have one chance to specify syslog facility and process identification string - on the first native syslog backend construction. Other native syslog backends will ignore these parameters. Obviously, the <code class="computeroutput">set_local_address</code> and <code class="computeroutput">set_target_address</code> methods have no effect for native backends. Using <code class="computeroutput">use_impl = native</code> on platforms with no native support for POSIX syslog API will have no effect. </p>
<div class="refsect2">
<a name="idp109190912"></a><h3>
<a name="boost.log.sinks.syslog_backendconstruct-copy-destruct"></a><code class="computeroutput">syslog_backend</code> 
        public
       construct/copy/destruct</h3>
<div class="orderedlist"><ol class="orderedlist" type="1">
<li class="listitem">
<pre class="literallayout"><a name="idp38062112-bb"></a><span class="identifier">syslog_backend</span><span class="special">(</span><span class="special">)</span><span class="special">;</span></pre>
<p>Constructor. Creates a UDP socket-based backend with <code class="computeroutput">syslog::user</code> facility code. IPv4 protocol will be used. </p>
</li>
<li class="listitem">
<pre class="literallayout"><span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">typename</span><span class="special">...</span> ArgsT<span class="special">&gt;</span> <span class="keyword">explicit</span> <a name="idp38063328-bb"></a><span class="identifier">syslog_backend</span><span class="special">(</span><span class="identifier">ArgsT</span><span class="special">...</span><span class="keyword">const</span> <span class="special">&amp;</span> args<span class="special">)</span><span class="special">;</span></pre>
<p>Constructor. Creates a sink backend with the specified named parameters. The following named parameters are supported:</p>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem"><p><code class="computeroutput">facility</code> - Specifies the facility code. If not specified, <code class="computeroutput">syslog::user</code> will be used. </p></li>
<li class="listitem"><p><code class="computeroutput">use_impl</code> - Specifies the backend implementation. Can be one of: </p></li>
<li class="listitem"><p><code class="computeroutput">native</code> - Use the native syslog API, if available. If no native API is available, it is equivalent to <code class="computeroutput">udp_socket_based</code>. </p></li>
<li class="listitem"><p><code class="computeroutput">udp_socket_based</code> - Use the UDP socket-based implementation, conforming to RFC3164 protocol specification. This is the default. </p></li>
<li class="listitem"><p><code class="computeroutput">ip_version</code> - Specifies IP protocol version to use, in case if socket-based implementation is used. Can be either <code class="computeroutput">v4</code> (the default one) or <code class="computeroutput">v6</code>. </p></li>
<li class="listitem"><p><code class="computeroutput">ident</code> - Process identification string. This parameter is only supported by native syslog implementation. </p></li>
</ul></div>
<p>
</p>
</li>
<li class="listitem">
<pre class="literallayout"><a name="idp38074192-bb"></a><span class="special">~</span><span class="identifier">syslog_backend</span><span class="special">(</span><span class="special">)</span><span class="special">;</span></pre>
<p>Destructor </p>
</li>
</ol></div>
</div>
<div class="refsect2">
<a name="idp109222976"></a><h3>
<a name="idp38038096-bb"></a><code class="computeroutput">syslog_backend</code> public member functions</h3>
<div class="orderedlist"><ol class="orderedlist" type="1">
<li class="listitem">
<pre class="literallayout"><span class="keyword">void</span> <a name="idp38038656-bb"></a><span class="identifier">set_severity_mapper</span><span class="special">(</span><span class="identifier">severity_mapper_type</span> <span class="keyword">const</span> <span class="special">&amp;</span> mapper<span class="special">)</span><span class="special">;</span></pre>
<p>The method installs the function object that maps application severity levels to syslog levels </p>
</li>
<li class="listitem">
<pre class="literallayout"><span class="keyword">void</span> <a name="idp38040704-bb"></a><span class="identifier">set_local_address</span><span class="special">(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span> <span class="keyword">const</span> <span class="special">&amp;</span> addr<span class="special">,</span> <span class="keyword">unsigned</span> <span class="keyword">short</span> port <span class="special">=</span> <span class="number">514</span><span class="special">)</span><span class="special">;</span></pre>
<p>The method sets the local host name which log records will be sent from. The host name is resolved to obtain the final IP address.</p>
<div class="note"><table border="0" summary="Note">
<tr>
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../../../../../doc/src/images/note.png"></td>
<th align="left">Note</th>
</tr>
<tr><td align="left" valign="top"><p>Does not have effect if the backend was constructed to use native syslog API</p></td></tr>
</table></div>
<p>

</p>
<div class="variablelist"><table border="0" class="variablelist compact">
<colgroup>
<col align="left" valign="top">
<col>
</colgroup>
<tbody><tr>
<td><p><span class="term">Parameters:</span></p></td>
<td><div class="variablelist"><table border="0" class="variablelist compact">
<colgroup>
<col align="left" valign="top">
<col>
</colgroup>
<tbody>
<tr>
<td><p><span class="term"><code class="computeroutput">addr</code></span></p></td>
<td><p>The local address </p></td>
</tr>
<tr>
<td><p><span class="term"><code class="computeroutput">port</code></span></p></td>
<td><p>The local port number </p></td>
</tr>
</tbody>
</table></div></td>
</tr></tbody>
</table></div>
</li>
<li class="listitem">
<pre class="literallayout"><span class="keyword">void</span> <a name="idp38045344-bb"></a><span class="identifier">set_local_address</span><span class="special">(</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">asio</span><span class="special">::</span><span class="identifier">ip</span><span class="special">::</span><span class="identifier">address</span> <span class="keyword">const</span> <span class="special">&amp;</span> addr<span class="special">,</span> 
                       <span class="keyword">unsigned</span> <span class="keyword">short</span> port <span class="special">=</span> <span class="number">514</span><span class="special">)</span><span class="special">;</span></pre>
<p>The method sets the local address which log records will be sent from.</p>
<div class="note"><table border="0" summary="Note">
<tr>
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../../../../../doc/src/images/note.png"></td>
<th align="left">Note</th>
</tr>
<tr><td align="left" valign="top"><p>Does not have effect if the backend was constructed to use native syslog API</p></td></tr>
</table></div>
<p>

</p>
<div class="variablelist"><table border="0" class="variablelist compact">
<colgroup>
<col align="left" valign="top">
<col>
</colgroup>
<tbody><tr>
<td><p><span class="term">Parameters:</span></p></td>
<td><div class="variablelist"><table border="0" class="variablelist compact">
<colgroup>
<col align="left" valign="top">
<col>
</colgroup>
<tbody>
<tr>
<td><p><span class="term"><code class="computeroutput">addr</code></span></p></td>
<td><p>The local address </p></td>
</tr>
<tr>
<td><p><span class="term"><code class="computeroutput">port</code></span></p></td>
<td><p>The local port number </p></td>
</tr>
</tbody>
</table></div></td>
</tr></tbody>
</table></div>
</li>
<li class="listitem">
<pre class="literallayout"><span class="keyword">void</span> <a name="idp38049936-bb"></a><span class="identifier">set_target_address</span><span class="special">(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span> <span class="keyword">const</span> <span class="special">&amp;</span> addr<span class="special">,</span> <span class="keyword">unsigned</span> <span class="keyword">short</span> port <span class="special">=</span> <span class="number">514</span><span class="special">)</span><span class="special">;</span></pre>
<p>The method sets the remote host name where log records will be sent to. The host name is resolved to obtain the final IP address.</p>
<div class="note"><table border="0" summary="Note">
<tr>
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../../../../../doc/src/images/note.png"></td>
<th align="left">Note</th>
</tr>
<tr><td align="left" valign="top"><p>Does not have effect if the backend was constructed to use native syslog API</p></td></tr>
</table></div>
<p>

</p>
<div class="variablelist"><table border="0" class="variablelist compact">
<colgroup>
<col align="left" valign="top">
<col>
</colgroup>
<tbody><tr>
<td><p><span class="term">Parameters:</span></p></td>
<td><div class="variablelist"><table border="0" class="variablelist compact">
<colgroup>
<col align="left" valign="top">
<col>
</colgroup>
<tbody>
<tr>
<td><p><span class="term"><code class="computeroutput">addr</code></span></p></td>
<td><p>The remote host address </p></td>
</tr>
<tr>
<td><p><span class="term"><code class="computeroutput">port</code></span></p></td>
<td><p>The port number on the remote host </p></td>
</tr>
</tbody>
</table></div></td>
</tr></tbody>
</table></div>
</li>
<li class="listitem">
<pre class="literallayout"><span class="keyword">void</span> <a name="idp38054608-bb"></a><span class="identifier">set_target_address</span><span class="special">(</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">asio</span><span class="special">::</span><span class="identifier">ip</span><span class="special">::</span><span class="identifier">address</span> <span class="keyword">const</span> <span class="special">&amp;</span> addr<span class="special">,</span> 
                        <span class="keyword">unsigned</span> <span class="keyword">short</span> port <span class="special">=</span> <span class="number">514</span><span class="special">)</span><span class="special">;</span></pre>
<p>The method sets the address of the remote host where log records will be sent to.</p>
<div class="note"><table border="0" summary="Note">
<tr>
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../../../../../doc/src/images/note.png"></td>
<th align="left">Note</th>
</tr>
<tr><td align="left" valign="top"><p>Does not have effect if the backend was constructed to use native syslog API</p></td></tr>
</table></div>
<p>

</p>
<div class="variablelist"><table border="0" class="variablelist compact">
<colgroup>
<col align="left" valign="top">
<col>
</colgroup>
<tbody><tr>
<td><p><span class="term">Parameters:</span></p></td>
<td><div class="variablelist"><table border="0" class="variablelist compact">
<colgroup>
<col align="left" valign="top">
<col>
</colgroup>
<tbody>
<tr>
<td><p><span class="term"><code class="computeroutput">addr</code></span></p></td>
<td><p>The remote host address </p></td>
</tr>
<tr>
<td><p><span class="term"><code class="computeroutput">port</code></span></p></td>
<td><p>The port number on the remote host </p></td>
</tr>
</tbody>
</table></div></td>
</tr></tbody>
</table></div>
</li>
<li class="listitem">
<pre class="literallayout"><span class="keyword">void</span> <a name="idp38059248-bb"></a><span class="identifier">consume</span><span class="special">(</span><span class="identifier">record_view</span> <span class="keyword">const</span> <span class="special">&amp;</span> rec<span class="special">,</span> <span class="identifier">string_type</span> <span class="keyword">const</span> <span class="special">&amp;</span> formatted_message<span class="special">)</span><span class="special">;</span></pre>
<p>The method passes the formatted message to the syslog API or sends to a syslog server </p>
</li>
</ol></div>
</div>
</div>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright &#169; 2007-2014 Andrey Semashev<p>
        Distributed under the Boost Software License, Version 1.0. (See accompanying
        file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>).
      </p>
</div></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="syslog/custom_severity_mapping.html"><img src="../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../../../sinks.html#header.boost.log.sinks.syslog_backend_hpp"><img src="../../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../../index.html"><img src="../../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="syslog/make_level.html"><img src="../../../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
</body>
</html>