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
/*-
* syslog-rs - a syslog client translated from libc to rust
* Copyright (C) 2020 Aleksandr Morozov
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
//! syslog-rs
//!
//! Since v 0.2.4 this project is relicensed with MPLv2.0.
//! The contributors and authors agreed to change license:
//! Aleksandr Morozov
//! RELKOM s.r.o
//!
//! 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
//!
//! - GNU/Linux RFC3164 (UTF-8 by default)
//! - *BSD and OSX RFC5424 (BOM UTF-8 by default)
//!
//! Files:
//! - syslog_sync.rs - contains the thread-safe realization of the syslog (sync).
//! Thread safe. The Atomic and crossbeam backoff are used for sync.
//! - syslog_async.rs - contains the async realization of the syslog (async)
//! Thread safe. Tokio mutex are used for sync.
//! - syslog_sync_queue.rs - constains the sync realization, with asynchronious
//! processing. The internal sych of crossbeam are used to push data to queue.
//! - syslog_sync_internal.rs - a `use_sync` and `use_sync_queue` common code.
//! - unsafe_cell.rs - a file contains a Cell which can be used to share the syslog
//! instance. See examples.
//! - portable.rs - all system level code which is portable
//! - common.rs - a common items mostly exported
//! - socket.rs - contains socket realization
//! - async_socket.rs - contains socket realization
//! - error.rs - an error wrapper and mapper
//!
//! Features:
//! - feature = "use_async" for asynchronious code (use syslog_rs::sy_async::{Syslog};)
//! - feature = "use_sync" for synchronious code (use syslog_rs::sy_sync::{Syslog};)
//! - feature = "use_sync_queue" for synchronious with async processing (use syslog_rs::sy_async_queue::{Syslog};)
//!
//! All features can be used simultaniously.
//! # Usage
//!
//! syslog-rs = {version = "0.4", default-features = false, features = ["use_sync"]}
//!
//! By default, the following features are enabled: use_async, use_sync, use_sync_queue
//!
//! ```
//! #[macro_use] extern crate lazy_static;
//! #[macro_use] extern crate syslog_rs;
//!
//! use std::thread;
//! use std::time::Duration;
//! use syslog_rs::sy_sync::{Syslog, SyslogStd};
//! use syslog_rs::{LogStat, LogFacility, Priority};
//!
//!
//! lazy_static! {
//! static ref SYNC_SYSLOG: UnsafeReadOnlyCell<Syslog> =
//! unsafe { UnsafeReadOnlyCell::new_uninitialized("syslog_sync") };
//! }
//!
//! macro_rules! logdebug
//! {
//! ($($arg:tt)*) => (
//! SYSLOG.syslog(Priority::LOG_DEBUG, format!($($arg)*))
//! )
//! }
//!
//!
//! fn main()
//! {
//! let syslog =
//! Syslog::openlog(
//! Some("example"),
//! LogStat::LOG_CONS | LogStat::LOG_NDELAY | LogStat::LOG_PID,
//! LogFacility::LOG_DAEMON
//! ).unwrap();
//!
//! unsafe { SYNC_SYSLOG.init(syslog) };
//!
//! logdebug!("test message!");
//!
//! thread::sleep(Duration::from_micros(10));
//!
//! return;
//! }
//! ```
//! ```
//! #[macro_use] extern crate lazy_static;
//! #[macro_use] extern crate syslog_rs;
//!
//! use std::thread;
//! use std::time::Duration;
//!
//! #[cfg(feature = "use_sync")]
//! use syslog_rs::sy_sync::{Syslog, SyslogStd};
//!
//! use syslog_rs::{LogStat, LogFacility, Priority};
//!
//! lazy_static! {
//! static ref SYSLOG: Syslog =
//! Syslog::openlog(
//! Some("example"),
//! LogStat::LOG_CONS | LogStat::LOG_NDELAY | LogStat::LOG_PID,
//! LogFacility::LOG_DAEMON
//! ).unwrap();
//! }
//!
//! macro_rules! logdebug
//! {
//! ($($arg:tt)*) => (
//! SYSLOG.syslog(Priority::LOG_DEBUG, format!($($arg)*))
//! )
//! }
//!
//! pub fn main()
//! {
//! logdebug!("test message!");
//!
//! thread::sleep(Duration::from_micros(10));
//!
//! return;
//! }
//! ```
//-- REEXPORT --
#[macro_use]
extern crate bitflags;
#[cfg(any(feature = "use_sync", feature = "use_sync_queue"))]
extern crate crossbeam;
extern crate chrono;
extern crate nix;
#[macro_use]
extern crate lazy_static;
//-- ASYNC --
#[cfg(feature = "use_async")]
extern crate async_recursion;
#[cfg(feature = "use_async")]
extern crate async_trait;
#[cfg(feature = "use_async")]
extern crate tokio;
//-- SYNC --
#[cfg(feature = "use_sync")]
pub mod sync;
#[cfg(feature = "use_async")]
pub mod a_sync;
//-- NON EXPORT
mod portable;
mod socket;
//-- PUBLIC
pub mod unsafe_cell;
#[macro_use]
pub mod common;
#[macro_use]
pub mod error;
//#[cfg(any(feature = "use_sync", feature = "use_sync_queue"))]
//pub use sync::syslog_trait::SyslogCommon;
#[cfg(feature = "use_sync")]
pub use sync::syslog_sync as sy_sync;
#[cfg(feature = "use_async")]
pub use a_sync::syslog_async as sy_async;
#[cfg(feature = "use_sync_queue")]
pub use sync::syslog_sync_queue as sy_sync_queue;
pub use common::*;
pub use unsafe_cell::*;