logcast

Crates.iologcast
lib.rslogcast
version0.2.9
created_at2025-11-10 21:38:13.93876+00
updated_at2025-11-14 01:35:12.530851+00
descriptionSimple helper to send logs via TCP
homepage
repository
max_upload_size
id1926249
size45,949
(matheus-git)

documentation

README

logcast

rust

A helper that sends logs over TCP, for programs without terminal output, such as TUIs.

Example

logcast

Usage

Integrate with the log crate

See examples/log.rs for an example of integration with the log crate.

// src/main.rs
use logcast::init_on_addr;

init_on_addr("127.0.0.1:8080");
log::info!("The logger seems to work");

Example output:

$ ncat -l --keep-open 8080
INFO:systemd_manager_tui::terminal::components::details -- Test
INFO:systemd_manager_tui::terminal::components::details -- Service { name: "bluetooth.service", description: "Bluetooth service", state: ServiceState { load: "loaded", active: "active", sub: "running", file: "enabled" } }

Another option is to create your own macro.

Create macro

// src/macros.rs
macro_rules! log {
    ($($arg:tt)*) => {{
        crate::LOGGER.log(&format!($($arg)*));
    }};
}

Make the macro available globally and create the LOGGER

// src/main.rs
#[macro_use]
mod macros;

use std::sync::LazyLock;
use logcast::Logger;

pub static LOGGER: LazyLock<Logger> = LazyLock::new(|| Logger::new("127.0.0.1:8080"));

Use macro with log!

// anywhere
log!("Test");
log!("{:?}", service);

Output

To view the logs, open another terminal and run a program that listens for TCP connections, such as ncat -l --keep-open 8080, as shown in the example below.

└─$ ncat -l --keep-open 8080 
[2025-11-10 20:55:04] Test
[2025-11-10 20:55:04] Service { name: "cron.service", description: "Regular background program processing daemon", state: ServiceState { load: "loaded", active: "active", sub: "running", file: "enabled" } }

📝 License

This project is open-source under the MIT License.

Commit count: 0

cargo fmt