tracing - a framework for instrumenting Rust programs to collect structured, event-based diagnostic information

Overview

Tracing — Structured, application-level diagnostics

tracing-appender

Writers for logging events and spans

Crates.io Documentation Documentation (master) MIT licensed Build Status Discord chat

Documentation | Chat

Overview

tracing is a framework for instrumenting Rust programs to collect structured, event-based diagnostic information. tracing-appender allows events and spans to be recorded in a non-blocking manner through a dedicated logging thread. It also provides a RollingFileAppender that can be used with or without the non-blocking writer.

Compiler support: requires rustc 1.53+

Usage

Add the following to your Cargo.toml:

tracing-appender = "0.2"

This crate can be used in a few ways to record spans/events:

Rolling File Appender

fn main(){
    let file_appender = tracing_appender::rolling::hourly("/some/directory", "prefix.log");
}

This creates an hourly rotating file appender that writes to /some/directory/prefix.log.YYYY-MM-DD-HH. [Rotation::DAILY] and [Rotation::NEVER] are the other available options.

The file appender implements std::io::Write. To be used with tracing_subscriber::FmtSubscriber, it must be combined with a MakeWriter implementation to be able to record tracing spans/event.

The rolling module's documentation provides more detail on how to use this file appender.

Non-Blocking Writer

The example below demonstrates the construction of a non_blocking writer with an implementation of std::io::Writer.

std::io::Result<()> { Ok(()) } } fn main() { let (non_blocking, _guard) = tracing_appender::non_blocking(TestWriter); tracing_subscriber::fmt().with_writer(non_blocking).init(); }">
use std::io::Error;

struct TestWriter;

impl std::io::Write for TestWriter {
    fn write(&mut self, buf: &[u8]) -> std::io::Result<usize> {
        let buf_len = buf.len();
    
        println!("{:?}", buf);
        Ok(buf_len)
    }

    fn flush(&mut self) -> std::io::Result<()> {
        Ok(())
    }
}

fn main() {
    let (non_blocking, _guard) = tracing_appender::non_blocking(TestWriter);
    tracing_subscriber::fmt().with_writer(non_blocking).init();
}

Note: _guard is a WorkerGuard which is returned by tracing_appender::non_blocking to ensure buffered logs are flushed to their output in the case of abrupt terminations of a process. See WorkerGuard module for more details.

The example below demonstrates the construction of a tracing_appender::non_blocking writer constructed with a std::io::Write:

fn main() {
    let (non_blocking, _guard) = tracing_appender::non_blocking(std::io::Stdout);
    tracing_subscriber::fmt()
        .with_writer(non_blocking)
        .init();
}

The non_blocking module's documentation provides more detail on how to use non_blocking.

Non-Blocking Rolling File Appender

fn main() {
    let file_appender = tracing_appender::rolling::hourly("/some/directory", "prefix.log");
    let (non_blocking, _guard) = tracing_appender::non_blocking(file_appender);
   tracing_subscriber::fmt()
       .with_writer(non_blocking)
       .init();
}

Supported Rust Versions

tracing-appender is built against the latest stable release. The minimum supported version is 1.53. The current tracing-appender version is not guaranteed to build on Rust versions earlier than the minimum supported version.

Tracing follows the same compiler support policies as the rest of the Tokio project. The current stable Rust compiler and the three most recent minor versions before it will always be supported. For example, if the current stable compiler version is 1.45, the minimum supported version will not be increased past 1.42, three minor versions prior. Increasing the minimum supported compiler version is not considered a semver breaking change as long as doing so complies with this policy.

License

This project is licensed under the MIT license.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in Tokio by you, shall be licensed as MIT, without any additional terms or conditions.

You might also like...
A patch to fix tracing LocalTime problem.

tracing-local-time A patch to fix tracing LocalTime problem. Tracing-subscriber now has a bug in LocalTime, so build ourselves' to fix it. In this pat

An example of a fairing for rocket to use tracing (as this pops up at many places in dicussions and questions)
An example of a fairing for rocket to use tracing (as this pops up at many places in dicussions and questions)

Rocket Tracing Fairing Example This repository aims to give a short example of how you can add a Fairing to your Rocket for tracing and how to use it

A dynamic binary tracing tool

Backlight Backlight is a dynamic binary tracing tool. Install $ git clone [email protected]:JoshMcguigan/backlight.git $ cd backlight $ cargo install-b

Tracing layer to quickly inspect spans and events

tracing-texray First, a word of warning: This is alpha software. Don't run this in prod or anywhere where a panic would ruin your day. tracing-texray

Middlewares and tools to integrate axum + tracing + opentelemetry

axum-tracing-opentelemetry Middlewares and tools to integrate axum + tracing + opentelemetry. Read OpenTelemetry header from incoming request Start a

A convenient tracing config and init lib, with symlinking and local timezone.
A convenient tracing config and init lib, with symlinking and local timezone.

clia-tracing-config A convenient tracing config and init lib, with symlinking and local timezone. Use these formats default, and can be configured: pr

Strongly typed, extensible event mediator.

mediatrix Strongly typed, extensible event mediator. For more info and explanation, please see the docs. Usage Sync use mediatrix::synchronous::basic:

Event listening, bubbling, and callbacks

Event listeners, bubbling, and callbacks for Bevy Oh my! License All code in this repository is dual-licensed under either: MIT License (LICENSE-MIT o

AWS Cloudwatch layer for tracing-subscriber

tracing-cloudwatch tracing-cloudwatch is a custom tracing-subscriber layer that sends your application's tracing events(logs) to AWS CloudWatch Logs.

Releases(v0.2.5)
Owner
Cris Liao
Program Builder/Trainer
Cris Liao
miette is a diagnostic library for Rust. It includes a series of traits/protocols that allow you to hook into its error reporting facilities, and even write your own error reports!

miette is a diagnostic library for Rust. It includes a series of traits/protocols that allow you to hook into its error reporting facilities, and even write your own error reports!

Kat Marchán 1.2k Jan 1, 2023
A rust `tracing` compatible framework inspired by log4rs.

trace4rs This crate allows users to configure output from tracing in the same way as you would configure the output of log4rs. Overview For a usage ex

Imperva 5 Oct 24, 2022
Error propagation tracing in Rust.

Propagate Error propagation tracing in Rust. Why Propagate? Being able to trace the cause of an error is critical for many types of software written i

Ben Reeves 10 Sep 23, 2021
Emit ETW events in tracing-enabled Rust applications.

tracing-etw Emit ETW events in tracing-enabled Rust applications. This crate depends on rust_win_etw. There are four ETW events. fn NewSpan(span_id: u

Microsoft 11 Aug 10, 2022
Nexmark event generator in Rust.

Nexmark-rs The Nexmark benchmark data generator in Rust. Installation cargo install nexmark --features bin Usage Generate nexmark events. Print one pe

RisingWave Labs 11 Nov 27, 2022
Utilities for integrating Datadog with opentelemetry + tracing in rust

Non-official datadog tracing and log correlation for Rust services. This crate contains the necessary glue to bridge the gap between OpenTelemetry, tr

willbank 5 Oct 31, 2023
This crate bridges between gstreamer and tracing ecosystems.

This crate provides a bridge between gstreamer and the tracing ecosystem. The goal is to allow Rust applications utilizing GStreamer to better integra

Standard Cognition OSS 17 Jun 7, 2022
A tracing profiler for the Sega MegaDrive/Genesis

md-profiler, a tracing profiler for the Sega MegaDrive/Genesis This program, meant to be used with this fork of BlastEm, helps you finding bottlenecks

null 15 Nov 3, 2022
A tracing layer for macOS/iOS's `oslog`

tracing_oslog This is a tracing layer for the Apple OS logging framework. Activities are used to handle spans, Example use tracing_oslog::OsLogger; l

Lucy 12 Dec 6, 2022
A real-time event-oriented data-hub

Redcar A real-time event-oriented data-hub, inspired by the data hub. It is: Universal: the front end uses gRPC to provide services. Fast: benchmarked

null 6 Mar 2, 2022