logcast 0.1.6

Simple helper to send logs via TCP
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
use std::io::{self, Write};
use std::net::TcpStream;
use chrono::Local;

pub fn send_log(message: &str, address: &str) -> io::Result<()> {
    let mut stream = TcpStream::connect(address)?;

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

    stream.write_all(formatted.as_bytes())?;
    Ok(())
}