syslog-rs
A syslog client Rust crate which supports most commonly used RFC message formatters, Local and Remote server connections and both sync and async interfaces.
Attention! V5.0.0 was rejected, and in V6.0.0 the API is stabilized.
Dual licensed crate.
- This crate i.e code is NOT an Open Source software. This is a FREE (gratis) software and follows the principle of Sources Available/Disclosed software which must be fairly used.
- It is published under FSF/OSI approved licenses however author does not follow/share/respect OSI and FSF principles and phylosophy.
- License is subject to be changed in further versions without warning.
- If you are using code in non-free (in terms of gratis) software you MUST NEVER demand a development of any features which are missing and needed for your business if you are not sponsoring/contributing those changes.
- Access to the code can be limited by author/platform to specific entities due to the local laws (not my bad or fault)(despite what is said in the license).
- AI generated sloppy code is prohibited. AI generates slop "a priori" (anyway).
- Licenses (thank you OSS sectarians ) do not anyhow limit AI training, but f^ck you all - ChatGPT, Co
ckPilot, especially Claude and rest unidentified cr@p. - It is strongly discouraged from using the AI based tools to write or enhance the code. AI slope would 100% violate the license by introducing the 3rd party licensed code.
The pull requests are now supported because the repository was moved to Codeberg. The alternative way is to send patches over the email to patch[at]4neko.org.
In case if you would like to contribute the code, please use pull request. Your pull request should include:
-
Description of changes and why it is needed.
-
Test the pull request.
In case of you prefer email and patch files please consider the following:
-
For each feature or fix, please send patches separatly.
-
Please write what your patch is implementing or fixing.
-
I can read the code and I am able to understand it, so don't write a poem or essay in the description to the patches.
-
Please test your patch.
- Can I use the MPL-2.0 licensed code (crate) in larger project licensed with more permissive license like BSD or MIT.
I want to distribute (outside my organization) executable programs or libraries that I have compiled from someone else's unchanged MPL-licensed source code, either standalone or part of a larger work. What do I have to do?
You must inform the recipients where they can get the source for the MPLed code in the executable program or library you are distributing (i.e., you must comply with Section 3.2). You may distribute any executables you create under a license of your choosing, as long as that license does not interfere with the recipients' rights to the source under the terms of the MPL.
Yes, MPL- and Apache-licensed code can be used with an MIT codebase (so in that sense, they are "compatible"). However, the MPL- / Apache-licensed code remains under its original license. (So although compatible, you cannot relicense someone else's MPL or Apache code into the MIT license.) This means that your final codebase will contain a mix of MPL, Apache, and MIT licensed code. As an example, MPL has weak copyleft, so if you modified an MPL file, that file (including your changes) must remain under the MPL license.
You should use this license if you are located in the EU which gives you more advantages over GPL because in case of any disputes, the license allows you to defend your rights in a European Union country, in this case it will be Spain. It has also been translated into all languages of the EU member states.
Matrix of EUPL compatible open source licences
EUPL-1.2
is incompatiable with GPL
according to GNU ORG
This is a free software license. By itself, it has a copyleft comparable to the GPL's, and incompatible with it.
Version
v 6.1.0
Attention! Previous version 5.0.0 was rejected. In version v6.0.0 the crate's API is stabilized and should not change.
- Added more comments.
- Improved
syslog_5424.rs
sequence number assign and added conditional comilation to fallback to mutex if Atomics are not available. - Fixed the
SyslogFormatted
structure and traitSyslogFormatter
.CoW
is no longer used.vsyslog1_format
is now borrowing the progname and pid.
- The
syslog.rs
was removed due to redundancy. - Now the
SyslogShared
(v4.0.0) isSyncSyslog
. - Now the
SyslogQueue
(v4.0.0) isQueuedSyslog
. - Now the
SyslogThreadLocal
(v5.0.0) isSingleSyslog
. - The
StreamableSyslog
is nowSyStream
andStreamableSyslogApi
is nowSyStreamApi
.
- The syslog (sync) API was updated once again. Now the main SYSLOG instance is Syslog<>.
- The
SyslogSync
(previouslySyslogShared
) is no logner using mutex, but experimental CoW crate which should allow to perfrom the log sending without blocking mutex. - The
SyslogQueueThread
(previouslySyslogQueue
) changed, but nothing has changed dramatically. - Added thread local syslog in syslog_threadlocal.rs, structure
SyslogThreadLocal
. - get_max_msg_size() in the
SyslogTap
is no longer requiresself
. - The
formatters
traitSyslogFormatter
functionvsyslog1_format
no longer provides thetap
data.
License:
Sources are available under: MPL-2.0 OR EUPL-1.2
Issues tracker:
The project has moved to Codeberg.
Description
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. Supports both sync and async and custom formatters.
- GNU/Linux RFC3164 (UTF-8 by default)
- *BSD and OSX RFC5424 (BOM UTF-8 by default) (including msgid and parametes).
- Tokio async
- Smol async
- TLS over TCP syslog server connection
- TCP/UDP syslog server connection
- Local file writer
Available features:
- feature =
use_sync
enables the sync syslogSyncSyslog
and all sync functionality. - feature =
build_with_thread_local
enables the lockless syslog clientSingleSyslog
for single threaded orthread_local
instances. - feature =
build_async_tokio
orbuild_async_smol
for asynchronious execution. EnablesAsyncSyslog
. Cannot be used together. - feature =
build_async_interface
an experimental feature which allowes to implement async for some unsupported executor. See /docs/ for info. Can not be used together withbuild_async_tokio
orbuild_async_smol
. - feature =
build_with_queue
autmaticallly enablesuse_sync
as dependancy. It also enables theQueuedSyslog
. When used in combination with one of thebuild_async_tokio
orbuild_async_smol
, can be used to write to syslog server from both sync and async code using single connection to syslog server. - feature =
build_with_net
enables the TCP/UDP - feature =
build_ext_tls
enables the TLS over TCP support. - feature =
build_ext_file
enables the local logging to file (without syslog server).
The use_sync
is acting like the libc's/glibc's functions syslog(), openlog()...
There are two types of syslog client:
SyncSyslog
- a single syslog instance which is shared between the threads. A CoW is used for simultanious access control.QueuedSyslog
- a signle syslog instance which is shared between the threads using MPSC channels. A worker thread is allocated to receive messages from other threads and forward mwssages to syslog server.SingleSyslog
- a single thread syslog which is notSend
and notSync
. Can be used withthread_local
.
The use_sync_queue
has the same API as libc/glibc but it is different in some ways. It spawns a worker thread which forwards messages from the queue (channel) to syslog server. If used with async
can act as a sync/async interfacing by providing the interface to attach the async syslog instance to the sync queue and use a signle channel to syslog server.
┌───────────────────────────────────────────────────────────────────┐
│build_with_queue │
│ │
│ build_sync │
│ ┌────────────┐ ┌───────────┐ │
│ │ SYNC_QUEUE ┼────► CROSSBEAM ┼────────────────┐ │
│ └────────────┘ │ adapter │ │ │
│ └───────────┘ │ │
│ │ │
│ build_async_tokio ┌───────────▼───────────┐│
│ ┌────────────┐ ┌────────────┐ │ ││
│ ┌────► SYNC_QUEUE ┼───► TOKIO MPSC ┼────► SYSLOG_WORKER THREAD ││
│ │ └────────────┘ │ adapter │ │ ││
│ │ └────────────┘ └───────────▲────▲──────┘│
│ │ │ │ │
│ │ build_async_smol ┌────────────┐ │ │ │
│ │ ┌────────────┐ │ SMOL MPSC │ │ │ │
│ ├────► SYNC_QUEUE ┼───► adapter ┼────────────────┘ │ │
│ │ └────────────┘ └────────────┘ │ │
│ │ │ │
│ │ │ │
│ │ build_async_interface │ │
│ │ ┌────────────┐ ┌────────────┐ │ │
│ ┼────► SYNC_QUEUE ┼───► EXT MPSC ┼─────────────────────┘ │
│ │ └────────────┘ │ adapter │ │
│ │ └────────────┘ │
│ │ ┌──────────────────────┐ │
│ └──┼ AsyncSyslogQueueApi │ │
│ │ trait │ │
│ └──────────────────────┘ │
└───────────────────────────────────────────────────────────────────┘
A AsyncSyslog
is the only client option which is available. But, the sync QueuedSyslog
supports the
async API if use_async_*
is enabled.
Available tunables:
- feature =
udp_truncate_1024_bytes
- feature =
udp_truncate_1440_bytes
DEFAULT
The above is for RFC5424 which controls the syslog message length for forwarding via UDP protocol.
-
feature =
tcp_truncate_1024_bytes
-
feature =
tcp_truncate_2048_bytes
DEFAULT -
feature =
tcp_truncate_4096_bytes
-
feature =
tcp_truncate_max_bytes
-
feature =
truncate_default
- a shortcut forudp_truncate_1440_bytes
andtcp_truncate_2048_bytes
The above is for RFC5424
which controls the syslog message length for forwarding via TCP protocol.
- feature =
dgram_sysctl_failure_panic
The above is for *BSD systems only and controls the behaviour of the sysctl error handling. If this is enabled, the crate will panic is access to sysctl fails. Not enabled by default.
Usage:
For default syslog-rs = "6.1"
For customization: syslog-rs = {version = "6.1", default-features = false, features = ["use_sync", "truncate_default"]}
Contributors
Ordered by Relkom s.r.o (c) 2021
Developed by: Aleksandr Morozov
Examples
See ./examples/ in the repository.
use ;
use Duration;
use DefaultSyslogFormatter;
use ;
use ;
pub static SYSLOG: = new;
pub static SYSLOG2: = new;
pub static SYSLOG3: = new;
use AsyncSyslog;
use OnceCell;
use ;
use ;
pub static SYSLOG: = const_new;
async
This exampel requires the feature build_with_thread_local
to be enabled.
use ;
use ;
thread_local!
use OnceLock;
use thread;
use Duration;
use ;
use ;
use ;
use ;
use ;
pub static SYNC_SYSLOG: = new;
;
unsafe
use OnceLock;
use thread;
use Duration;
use ;
use ;
use ;
use ;
pub static SYNC_SYSLOG: = new;
pub static SYNC_SYSLOG: = new;
Either build_async_tokio
or build_async_smol
and build_with_queue
should be enabled. Example below requires also feature build_ext_file
to be enabled.
use OnceLock;
use thread;
use Duration;
use ;
use ;
use DefaultQueueAdapter;
use ;
use AsyncSyslogQueueApi;
use ;
use ;
pub static SYSLOG: = new;
This example requires the feature build_ext_net
to be enabled.
use ;
use Duration;
use DefaultSyslogFormatter;
use ;
use ;
pub static SYSLOG: = new;
/*
pub static SYSLOG2: LazyLock<Syslog<DefaultSyslogFormatter, syslog_rs::SyslogNetTcp>> = LazyLock::new(||
{
Syslog
::<DefaultSyslogFormatter, syslog_rs::SyslogNetTcp>
::openlog_with(
Some("example"),
LogStat::LOG_CONS | LogStat::LOG_PID,
LogFacility::LOG_DAEMON,
syslog_rs::SyslogNetTcp::new("127.0.0.1:7778", None, None).unwrap()
)
.unwrap()
}
);
*/
This exampel requires the feature build_ext_tls
to be enabled.
use ;
use Duration;
use DefaultSyslogFormatter;
use ;
use ;
pub const CERT_INLINE: &'static = b"cert...";
pub static SYSLOG: = new;
This exampel requires the feature build_async_smol
to be enabled.
use Duration;
use ;
use OnceCell;
use AsyncSyslog;
use ;
pub static SYSLOG: = new;
From the crate version 3, the crate can be provided with custom implementation of the async props like sockets or other things. In order to achieve this
some traits should be implemented in the program which uses this crate and enables the build_async_interface
. The build-in async exec like tokio or smol
can not be enabled together.
See example file.
extern crate syslog_rs;
use fmt;
use ErrorKind;
use Shutdown;
use Duration;
use ;
use AsyncMutexGuard;
use DefaultSyslogFormatter;
use Errno;
use libc;
use SyslogError;
use ;
use ;
use File;
use AsyncWriteExt;
use UnixDatagram;
use MutexGuard;
use sleep;
use ;
/// Implemeting the custom IO and thread control things which is needed by the crate.
;
/// Implementing the mutex realization for out executor.
;
/// Also the mutex guard.
;
/// Implementing the sylog provider (in this example a SyslogLocal will be wrapped into our struct
/// because it is not possible to implement foreign traits for foreign structs.
;
/// A async destination where the type of the tap i.e socket is declared.
/// A maximum message size.
/// Implementing a [AsyncSyslogTap] for the previously created [NativeSyslogLocal] for the
/// [AsyncTap] - socket.
async