logcast 0.1.5

Simple helper to send logs via UDP
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
use std::io;
use std::net::UdpSocket;
use chrono::Local;

pub fn send_log(message: &str, address: &str) -> io::Result<()> {
    let socket = UdpSocket::bind("0.0.0.0:0")?;

    let timestamp = Local::now().format("[%Y-%m-%d %H:%M:%S]").to_string();
    let formatted = format!("\x1b[90m{}\x1b[0m {}\n", timestamp, message);

    socket.send_to(formatted.as_bytes(), address)?;
    Ok(())
}