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 * Licensed under the EUPL, Version 1.2 or - as soon they will be approved by
7 * the European Commission - subsequent versions of the EUPL (the "Licence").
8 * 
9 * You may not use this work except in compliance with the Licence.
10 * 
11 * You may obtain a copy of the Licence at:
12 * 
13 *    https://joinup.ec.europa.eu/software/page/eupl
14 * 
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the Licence is distributed on an "AS IS" basis, WITHOUT
17 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
18 * Licence for the specific language governing permissions and limitations
19 * under the Licence.
20 */
21
22
23use async_trait::async_trait;
24
25use crate::{error::SyRes, socket::TapTypeData, Priority};
26
27/// An implementation for the syslog "style" message handling.
28#[async_trait]
29pub trait AsyncSyslogApi: std::fmt::Debug + Send + 'static
30{
31    /// Requests to connect to remote server.
32    async fn 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 setlogmask(&self, logmask: i32) -> SyRes<i32>;
47
48    /// Closes connection to the syslog server
49    async fn 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 syslog(&self, pri: Priority, fmt: String);
61
62    /// Sends message to syslog (same as `syslog`).
63    async fn vsyslog(&self, pri: Priority, fmt: &str);
64
65
66    /// This function can be used to update the facility name, for example
67    /// after fork().
68    /// 
69    /// # Arguments
70    /// 
71    /// * `ident` - a new identity (up to 48 UTF8 chars)
72    async fn change_identity(&self, ident: &str) -> SyRes<()>;
73
74    /// Re-opens the connection to the syslog server. Can be used to 
75    /// rotate logs(handle SIGHUP).
76    /// 
77    /// # Returns
78    /// 
79    /// A [Result] is retured as [SyRes].
80    /// 
81    /// * [Result::Ok] - with empty inner type.
82    /// 
83    /// * [Result::Err] - an error code and description 
84    async fn reconnect(&self) -> SyRes<()>;
85
86    /// Updates the instance's socket. `tap_data` [TapTypeData] should be of
87    /// the same variant (type) as current.
88    async fn update_tap_data(&self, tap_data: TapTypeData) -> SyRes<()>;
89}
90
91/*
92/// A trait for implementation of the attach logic to specific syslog instance from `syslog_sync_queue.rs`.
93#[cfg(feature = "use_sync_queue")]
94#[async_trait]
95pub trait AsyncSyslogQueue
96{
97    /// Attaches to the existing instance of `sy_sync_queue::Syslog`.
98    /// 
99    /// # Arguments 
100    /// 
101    /// * `syslog` - an instance of the `sy_sync_queue`.
102    /// 
103    /// # Returns
104    ///
105    /// * A [SyRes] with instance or Err()
106    async 
107    fn attach(syslog: &crate::sy_sync_queue::Syslog) -> SyRes<Self>
108    where Self: Sized;
109}
110    */