
use std::{sync::LazyLock, thread};
use std::time::Duration;
use std::fmt::Write;

use syslog_rs::{SyStreamApi, SyncSyslog, SyslogApi};


#[cfg(target_family = "unix")]
use syslog_rs::{LogFacility, LogStat, Priority, SyslogLocal};

#[cfg(target_family = "windows")]
use syslog_rs::{LogFacility, LogStat, Priority, WindowsEvent};

#[cfg(target_family = "unix")]
pub static SYSLOG: LazyLock<SyncSyslog> = LazyLock::new(|| 
    {
        SyncSyslog::openlog(
            Some("example"), 
            LogStat::LOG_CONS | LogStat::LOG_NDELAY | LogStat::LOG_PID, 
            LogFacility::LOG_DAEMON,
            SyslogLocal::new()
        )
        .unwrap()
    }
);

#[cfg(target_family = "windows")]
pub static SYSLOG: LazyLock<SyncSyslog> = LazyLock::new(|| 
    {
        SyncSyslog::openlog(
            Some("example"), 
            LogStat::LOG_CONS | LogStat::LOG_NDELAY | LogStat::LOG_PID, 
            LogFacility::LOG_DAEMON,
            WindowsEvent::new()
        )
        .unwrap()
    }
);


macro_rules! logdebug 
{
    ($($arg:tt)*) => (
        SYSLOG.syslog(Priority::LOG_DEBUG, format!($($arg)*).into())
    )
}

pub fn main()
{
    
    logdebug!("test message!");

    thread::sleep(Duration::from_micros(10));

    let d = "890";

    let _ = write!(SYSLOG.stream(Priority::LOG_DEBUG), "test {} 123 stream test ", d);

    return;
}

