Crate syslog_rs

source ·
Expand description

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;
}

Re-exports§

Modules§

Macros§