logcast 0.1.4

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

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

    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(), destino)?;
    Ok(())
}