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
273
274
275
276
277
278
279
280
281
282
/*-
* syslog-rs - a syslog client translated from libc to rust
*
* Copyright 2025(c) Aleksandr Morozov
*
* The syslog-rs crate can be redistributed and/or modified
* under the terms of either of the following licenses:
*
* 1. the Mozilla Public License Version 2.0 (the “MPL”) OR
*
* 2. The MIT License (MIT)
*
* 3. EUROPEAN UNION PUBLIC LICENCE v. 1.2 EUPL © the European Union 2007, 2016
*/
//! syslog-rs
//!
//! <img src="https://cdn.4neko.org/syslog_logo.webp" width="280"/> <img src="https://cdn.4neko.org/source_avail.webp" width="280"/> <img src="https://cdn.4neko.org/mit_mpl_eupl_2.webp" width="280"/>
//! <br/>
//! <img src="https://codeberg.org/4neko/syslog-rs/badges/workflows/multi-os.yml/badge.svg" />
//! An implementation of the syslog from glibc/libc like it was designed in
//! in both system libraries. The API is almost compatible with what is in
//! libc/glibc.
//!
//! Also supports windows Event Log and/or remote syslog server.
//!
//! ## Supports
//!
//! * GNU/Linux RFC3164 (UTF-8 by default)
//! * *BSD and OSX RFC5424 (BOM UTF-8 by default) (including msgid and parametes).
//! * Windows Event Log via `WindowsEvent` provider and `RFC3164`/`RFC5424` via network or file.
//! * Tokio async
//! * Smol async
//! * TLS over TCP syslog server connection
//! * TCP/UDP syslog server connection
//! * Local file writer
//! * Logger
//!
//! Directories:
//! * a_sync - all async code
//! * formatters - syslog message formatter.
//! * sync - all sync code
//! * src - all common code for both sync and async.
//!
//! Features:
//! * feature = `build_with_thread_local` enables the lockless syslog client for single threaded or `thread_local` instances.
//! * feature = "build_sync" a base feature which enables all SYNC code. Just enabling the `use_sync`
//! would enable only basic SharedSyslog.
//! * feature = "build_async_tokio" a Tokio based async IO. Includes the tokio and tokio-rustls deps.
//! * feature = "build_async_smol" for synchronious with async processing (use syslog_rs::sy_async_queue::{Syslog};)
//! * feature = "build_async_interface" for asynchronious interface only without any realisations.
//! * feature = "build_with_queue" a Smol based async IO. Includes the smol and futures-rustls dep.
//! moves the syslog client to separate thread and by default uses
//! crossbeam-channel to receive messages.
//! Depending on which async procvider is selected, the channel realization
//! will be switched suring compilation. In this case, an async code can be
//! attached to the sync queue which allows to write to the same syslog
//! connection with the same setup.
//! * feature = "build_ext_net" adds the networking support! (TCP, UDP)
//! * feature = "build_ext_tls" adds the TLS support over network (TCP).
//! * feature = "build_ext_file" writing directly to file.
//! * feature = "build_with_logger" enables the ready to use logger. See below.
//!
//! --
//! * feature = "udp_truncate_1024_bytes" - Forces truncation of the (whole) syslog message to 1024
//! * feature = udp_truncate_1440_bytes - Forces truncation of the (whole) syslog message to 1440
//! * feature = tcp_truncate_1024_bytes - Forces truncation of the (whole) syslog message to 1024
//! * feature = tcp_truncate_2048_bytes - Forces truncation of the (whole) syslog message to 2048
//! * feature = tcp_truncate_4096_bytes - Forces truncation of the (whole) syslog message to 4096
//! * feature = tcp_truncate_max_bytes - Forces truncation of the (whole) syslog message to 8192 (max)
//! * feature = dgram_sysctl_failure_panic - BSD only! By default, if crate fails to obtain a sysctl net.local.dgram.maxdgram,
//! it returns a default value 2048. If this feature is enabled, then it will panic.
//!
//! `build_async_tokio` and `build_async_smol` cannot be used together.
//!
//! `build_with_queue` behaves differently if enabled ine of the async providers.
//!
//! **For mor info, please see README.md!**
//!
//! # Usage Example
//!
//! syslog-rs = {version = "7.0", default-features = false, features = ["build_sync", "truncate_default", "build_with_logger"]}
//!
//! By default, the following features are enabled: `build_sync`, `truncate_default`, `build_with_logger`
//!
//! ## Examples
//!
//! See the directory `./examples`
//!
//! ## build_with_logger
//!
//! `logger.rs`
//!
//! A logger can be controlled via environmental variables:
//!
//! * `SYSLOG_LOGGER_DST_URI` - enables the logger and configures it.
//!
//! * `SYSLOG_LOGGER_LOG_FACILITY` - optional, overrides the default which is LOG_DAEMON
//!
//! * `SYSLOG_LOGGER_LOG_FORMATTER` - optional, overrides the default formatter dep on the OS.
//!
//! * `SYSLOG_LOGGER_LOG_IDENTITY` - optional, if not set, will be determined automatically.
//!
//! The vars can have suffix, for example `XIO`, so SYSLOG_LOGGER_DST_URI_XIO, SYSLOG_LOGGER_LOG_FACILITY_XIO, ...
//!
//! In the crate or executable, a logger should be initialized. It can be done using:
//!
//! ```ignore
//! init_event_log(None).unwrap();
//! ```
//!
//! if `suffix` was used then it should be specified:
//!
//! ```ignore
//! init_event_log(Some("XIO")).unwrap();
//! ```
//!
//! Below are the macroses and functions which can be used to send messages
//!
//! ```ignore
//! logger_dbg!("debug: test_logger_simple");
//! logger_info!("info: test1test_logger_simple23");
//! logger_error!("error: test_logger_simple");
//! logger_warn!("warn: test_logger_simple");
//! logger_emerg!("emerg: test_logger_simple");
//! logger_custom!(Priority::LOG_EMERG, "custom");
//! logger_log(Priority::LOG_EMERG, format!("abc"));
//! ```
//!
//! Also the logger can be attached to the existing syslog instance i.e in the larger work:
//!
//! Example:
//! ```ignore
//! attach_event_log_shared(&syslog).unwrap()
//! ```
//!
//! attaches the crate's syslog to the created one in a larger program. But the crate which
//! uses logger must provide a function which would call this routine internally!
//!
//! There are two attach methods:
//!
//! * `attach_event_log_shared` - for a [SyShared] instance
//!
//! * `attach_event_log_queued` - for a [SyQueue] instance
//!
// make sure that the smol and tokio are not used together.
compile_error!;
// make sure that the build_async_interface and either async_embedded are not used together.
compile_error!;
//-- REEXPORT --
extern crate bitflags;
pub extern crate chrono;
extern crate socket2;
pub extern crate nix;
/// winDAws crp...
pub extern crate windows;
// -- TLS --
extern crate rustls;
extern crate tokio_rustls;
extern crate futures_rustls;
// -- ASYNC --
extern crate tokio;
extern crate smol;
// -- SYNC --
extern crate crossbeam_channel;
extern crate crossbeam_utils;
/// A sync syslog realization including shared and queued syslog client.
/// An async interface and/or realisations. The main async syslog struct is located there.
/// A message formatters i.e RFC5424 and other. Also a message formatter interface.
/// A syslog destnation. i.e local, remote, remote TLS, local file. Needed to initialize the
/// (both sync and async) instances.
pub use *;
/// A common things for the sockets managment.
/// A logger which can be setup from env.
/// A common code which holds all flags and macroses.
/// Unified error interface.
//-- NON EXPORT
/// A portable code which is different for different OSes.
/// Public use of the type of the tap.
pub use TapType;
/// A streamable sync instance (both).
pub use ;
pub use ;
pub use attach_event_log_queued;
/// A `sy_async` is a shortcut to the file `syslog_async.rs` in dir `a_sync`.
pub use syslog_async as sy_async;
/// A main async syslog instance.
pub use AsyncSyslog;
/// A shortcut for the internals of the `async_syslog` and IO for user implementation.
pub use ;
/// A shortcut to the trait `AsyncMutex` which unifies the mutex realiztion of different
/// exec environments.
pub use AsyncMutex;
/// Use this trait to access queue interface for async code.
pub use AsyncSyslogQueueApi;
/// A shortcut to the file `syslog_sync_queue.rs` in dir `sync`.
pub use syslog_sync_queue as sy_sync_queue;
/// A (previosuly SyslogQueue) queued sync type of the syslog client. Also async queue.
pub use SyQueued;
pub use SyThreadLocal;
/// A shortcut use of all in the `common.rs`.
pub use *;