syslog_rs/a_sync/
syslog_trait.rs

1/*-
2 * syslog-rs - a syslog client translated from libc to rust
3 * 
4 * Copyright 2025 Aleksandr Morozov
5 * 
6 * The syslog-rs crate can be redistributed and/or modified
7 * under the terms of either of the following licenses:
8 *
9 *   1. the Mozilla Public License Version 2.0 (the “MPL”) OR
10 *
11 *   2. The MIT License (MIT)
12 *                     
13 *   3. EUROPEAN UNION PUBLIC LICENCE v. 1.2 EUPL © the European Union 2007, 2016
14 */
15
16
17use crate::
18{
19    error::SyRes, 
20    formatters::SyslogFormatter, 
21    AsyncSyslogDestination, 
22    Priority, 
23    SyslogDestination
24};
25
26/// A syslog adapter to attach the async to sync queue.
27#[cfg(feature = "build_with_queue")]
28#[allow(async_fn_in_trait)]
29pub trait AsyncSyslogQueueApi<F: SyslogFormatter, D: SyslogDestination>: std::fmt::Debug + Send + 'static
30{
31    /// Requests to connect to remote server.
32    async fn a_connectlog(&mut self) -> SyRes<()>;
33
34    /// Sets the logmask to filter out the syslog calls.
35    /// 
36    /// See macroses [LOG_MASK] and [LOG_UPTO] to generate mask
37    ///
38    /// # Example
39    ///
40    /// LOG_MASK!(Priority::LOG_EMERG) | LOG_MASK!(Priority::LOG_ERROR)
41    ///
42    /// or
43    ///
44    /// ~(LOG_MASK!(Priority::LOG_INFO))
45    /// LOG_UPTO!(Priority::LOG_ERROR)
46    async fn a_setlogmask(&self, logmask: i32) -> SyRes<i32>;
47
48    /// Closes connection to the syslog server
49    async fn a_closelog(&self) -> SyRes<()>;
50
51    /// Similar to libc, syslog() sends data to syslog server.
52    /// 
53    /// # Arguments
54    ///
55    /// * `pri` - a priority [Priority]
56    ///
57    /// * `fmt` - a string message. In C exists a functions with
58    ///     variable argumets amount. In Rust you should create your
59    ///     own macros like format!() or use format!()]
60    async fn a_syslog(&self, pri: Priority, fmt: F);
61
62    /// This function can be used to update the facility name, for example
63    /// after fork().
64    /// 
65    /// # Arguments
66    /// 
67    /// * `ident` - a new identity (up to 48 UTF8 chars)
68    async fn a_change_identity(&self, ident: &str) -> SyRes<()>;
69
70    /// Re-opens the connection to the syslog server. Can be used to 
71    /// rotate logs(handle SIGHUP).
72    /// 
73    /// # Returns
74    /// 
75    /// A [Result] is retured as [SyRes].
76    /// 
77    /// * [Result::Ok] - with empty inner type.
78    /// 
79    /// * [Result::Err] - an error code and description 
80    async fn a_reconnect(&self) -> SyRes<()>;
81
82    /// Updates the instance's socket. `tap_data` [TapTypeData] should be of
83    /// the same variant (type) as current.
84    async fn a_update_tap_data(&self, tap_data: D) -> SyRes<()>;
85}
86
87
88/// An implementation for the syslog "style" message handling (base).
89pub(crate) trait AsyncSyslogApi<F: SyslogFormatter, D: AsyncSyslogDestination>: std::fmt::Debug + Send + 'static
90{
91    /// Requests to connect to remote server.
92    async fn connectlog(&mut self) -> SyRes<()>;
93
94    /// Sets the logmask to filter out the syslog calls.
95    /// 
96    /// See macroses [LOG_MASK] and [LOG_UPTO] to generate mask
97    ///
98    /// # Example
99    ///
100    /// LOG_MASK!(Priority::LOG_EMERG) | LOG_MASK!(Priority::LOG_ERROR)
101    ///
102    /// or
103    ///
104    /// ~(LOG_MASK!(Priority::LOG_INFO))
105    /// LOG_UPTO!(Priority::LOG_ERROR)
106    fn set_logmask(&mut self, logmask: i32) -> i32;
107
108    /// Closes connection to the syslog server
109    async fn closelog(&mut self) -> SyRes<()>;
110
111    /// Similar to libc, syslog() sends data to syslog server.
112    /// 
113    /// # Arguments
114    ///
115    /// * `pri` - a priority [Priority]
116    ///
117    /// * `fmt` - a formatted [SyslogFormatter] message. In C exists a functions with
118    ///     variable argumets amount. In Rust you should create your
119    ///     own macros like format!() or use format!()]
120    async fn vsyslog1(&mut self, pri: Priority, fmt: F);
121
122
123    /// This function can be used to update the facility name, for example
124    /// after fork().
125    /// 
126    /// # Arguments
127    /// 
128    /// * `ident` - a new identity (up to 48 UTF8 chars)
129    fn change_identity(&mut self, ident: &str);
130
131    /// Re-opens the connection to the syslog server. Can be used to 
132    /// rotate logs(handle SIGHUP).
133    /// 
134    /// # Returns
135    /// 
136    /// A [Result] is retured as [SyRes].
137    /// 
138    /// * [Result::Ok] - with empty inner type.
139    /// 
140    /// * [Result::Err] - an error code and description 
141    async fn reconnect(&mut self) -> SyRes<()>;
142
143    /// Updates the instance's socket. `tap_data` [TapTypeData] should be of
144    /// the same variant (type) as current.
145    async fn update_tap_data(&mut self, tap_data: D) -> SyRes<()>;
146}
147
148