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



use syslog_rs::formatters::DefaultSyslogFormatter;
use syslog_rs::{SyncSyslog, SyslogApi};
use syslog_rs::{LogFacility, LogStat, Priority, SyslogNetUdp};

pub static SYSLOG: LazyLock<SyncSyslog<DefaultSyslogFormatter, SyslogNetUdp>> = LazyLock::new(|| 
    {
        SyncSyslog
            ::<DefaultSyslogFormatter, SyslogNetUdp>
            ::openlog_with(
                Some("example"), 
                LogStat::LOG_CONS | LogStat::LOG_NDELAY | LogStat::LOG_PID, 
                LogFacility::LOG_DAEMON,
                SyslogNetUdp::new("127.0.0.1:7777", None).unwrap()            
            )
            .unwrap()
    }
);

/*
pub static SYSLOG2: LazyLock<Syslog<DefaultSyslogFormatter, syslog_rs::SyslogNetTcp>> = LazyLock::new(|| 
    {
        Syslog
            ::<DefaultSyslogFormatter, syslog_rs::SyslogNetTcp>
            ::openlog_with(
                Some("example"), 
                LogStat::LOG_CONS | LogStat::LOG_PID, 
                LogFacility::LOG_DAEMON,
                syslog_rs::SyslogNetTcp::new("127.0.0.1:7778", None, None).unwrap()            
            )
            .unwrap()
    }
);
*/

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

pub fn main()
{
    // netcat -ul 7777
    logdebug!("test message!");

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

    return;
}
