winston_transport

Crates.iowinston_transport
lib.rswinston_transport
version0.5.0
created_at2024-09-02 06:50:47.931404+00
updated_at2025-08-03 10:29:09.887389+00
descriptionwinston-transport for rust
homepage
repositoryhttps://github.com/ifeanyi-ugwu/winston_transport_rs
max_upload_size
id1360195
size137,637
Ifeanyi Ugwu (ifeanyi-ugwu)

documentation

https://docs.rs/winston_transport

README

winston_transport

A flexible, extensible logging transport library for Rust, designed to provide various transport implementations with support for batching, asynchronous threading, and adapter interoperability.

Overview

winston_transport offers a modular system for logging transports, enabling efficient and customizable log handling. It provides core abstractions and multiple transport implementations, including batch processing and threaded asynchronous logging. Additionally, it includes adapters to seamlessly convert between the Transport trait and standard Rust Write trait, facilitating integration with existing IO systems.

Features

  • Core Transport trait defining the logging interface.
  • BatchedTransport for efficient batch processing of log messages.
  • ThreadedTransport for non-blocking, asynchronous logging on background threads.
  • Adapters to convert between Transport and Write traits (both owned and borrowed).
  • Support for querying logs via LogQuery.
  • Configurable batching parameters such as batch size and flush timing.

Usage

Creating a Custom Transport

To create a custom transport, implement the Transport trait:

use winston_transport::Transport;
use logform::LogInfo;

struct MyTransport;

impl Transport for MyTransport {
    fn log(&self, info: LogInfo) {
        // Implement your logging logic here
        println!("{}: {}", info.level, info.message);
    }
}

Basic Transport Usage

use winston_transport::{Transport, threaded_transport::ThreadedTransport};
use logform::LogInfo;

fn main() {
    let my_transport = MyTransport;
    let threaded = ThreadedTransport::new(my_transport);

    threaded.log(LogInfo::new("INFO", "This is a log message"));
    threaded.flush().expect("Failed to flush logs");
}

Using BatchedTransport

use winston_transport::{batch_transport::{BatchedTransport, BatchConfig}, Transport};
use logform::LogInfo;
use std::time::Duration;

fn main() {
    let base_transport = MyTransport;
    let config = BatchConfig {
        max_batch_size: 50,
        max_batch_time: Duration::from_millis(200),
        flush_on_drop: true,
    };

    let batched = BatchedTransport::with_config(base_transport, config);

    batched.log(LogInfo::new("INFO", "Batched log message"));
    batched.flush().expect("Flush failed");
}

Using Transport Adapters

Convert a Transport into a Write:

use winston_transport::transport_adapters::IntoTransportWriter;
use std::io::Write;

fn example<T: winston_transport::Transport + Sized>(transport: T) {
    let mut writer = transport.into_writer();
    writeln!(writer, "Log message via writer").unwrap();
}

Convert a Write into a Transport:

use winston_transport::transport_adapters::IntoWriterTransport;
use std::io::stdout;

fn example() {
    let stdout = stdout();
    let transport = stdout.into_transport();
    transport.log(logform::LogInfo::new("INFO", "Log via transport"));
}

License

This project is licensed under the MIT License. See the LICENSE file for details. } }

Commit count: 56

cargo fmt