syslog_rs/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
22use crate::{error::SyRes, socket::TapTypeData, Priority};
23
24
25pub trait SyslogApi: std::fmt::Debug + Send + 'static
26{
27 fn connectlog(&mut self) -> SyRes<()>;
28
29 /// Sets the logmask to filter out the syslog calls.
30 ///
31 /// See macroses [LOG_MASK] and [LOG_UPTO] to generate mask
32 ///
33 /// # Example
34 ///
35 /// LOG_MASK!(Priority::LOG_EMERG) | LOG_MASK!(Priority::LOG_ERROR)
36 ///
37 /// or
38 ///
39 /// ~(LOG_MASK!(Priority::LOG_INFO))
40 /// LOG_UPTO!(Priority::LOG_ERROR)
41 fn setlogmask(&self, logmask: i32) -> SyRes<i32>;
42
43 /// Closes connection to the syslog server
44 fn closelog(&self) -> SyRes<()>;
45
46 /// Similar to libc, syslog() sends data to syslog server.
47 ///
48 /// # Arguments
49 ///
50 /// * `pri` - a priority [Priority]
51 ///
52 /// * `fmt` - a string message. In C exists a functions with
53 /// variable argumets amount. In Rust you should create your
54 /// own macros like format!() or use format!()]
55 fn syslog(&self, pri: Priority, fmt: String);
56
57 /// Sends message to syslog (same as `syslog`).
58 fn vsyslog<S: AsRef<str>>(&self, pri: Priority, fmt: S);
59
60
61 /// This function can be used to update the facility name, for example
62 /// after fork().
63 ///
64 /// # Arguments
65 ///
66 /// * `ident` - a new identity (up to 48 UTF8 chars)
67 fn change_identity(&self, ident: &str) -> SyRes<()>;
68
69 /// Re-opens the connection to the syslog server. Can be used to
70 /// rotate logs(handle SIGHUP).
71 ///
72 /// # Returns
73 ///
74 /// A [Result] is retured as [SyRes].
75 ///
76 /// * [Result::Ok] - with empty inner type.
77 ///
78 /// * [Result::Err] - an error code and description
79 fn reconnect(&self) -> SyRes<()>;
80
81 /// Updates the instance's socket. `tap_data` [TapTypeData] should be of
82 /// the same variant (type) as current.
83 fn update_tap_data(&self, tap_data: TapTypeData) -> SyRes<()>;
84}
85