4 releases (stable)

new 1.1.0 Mar 25, 2023
1.0.2 Mar 13, 2023
1.0.1 Mar 11, 2023
0.1.0 Sep 13, 2022

#215 in Debugging

Download history 9/week @ 2022-12-08 6/week @ 2022-12-15 5/week @ 2022-12-22 5/week @ 2022-12-29 5/week @ 2023-01-05 3/week @ 2023-01-12 6/week @ 2023-01-19 8/week @ 2023-01-26 8/week @ 2023-02-02 4/week @ 2023-02-09 8/week @ 2023-02-16 3/week @ 2023-02-23 3/week @ 2023-03-02 60/week @ 2023-03-09 26/week @ 2023-03-16 47/week @ 2023-03-23

136 downloads per month
Used in tracelogging_dynamic

MIT license

1.5K SLoC

TraceLogging for Rust

The tracelogging crate provides a simple and efficient system for logging TraceLogging events when the event schema is known at compile time.

This is similar to the C/C++ TraceLoggingProvider.h implementation in the Windows SDK.

use tracelogging as tlg;

// Define a static variable for the "MyCompany.MyComponent" provider.
    MY_PROVIDER,              // The static symbol to use for this provider.
    "MyCompany.MyComponent"); // The provider's name (string literal).

// Register the provider at module initialization. If you don't register (or if
// register fails) then MY_PROVIDER.enabled() will always return false, the
// write_event macro will be a no-op, and MY_PROVIDER.unregister() will be a no-op.
// Safety: MUST call MY_PROVIDER.unregister() before module unload.
unsafe { MY_PROVIDER.register(); }

// As necessary, call write_event to send events to ETW.
let field1_value = "String Value";
let field2_value = 42u32;
    MY_PROVIDER,                    // The provider to use for the event.
    "MyEventName",                  // The event's name (string literal).
    level(Warning),                 // Event's severity level.
    keyword(0x23),                  // Event category bits.
    str8("Field1", field1_value),   // Add a string field to the event.
    u32("Field2", &field2_value),   // Add an integer field to the event.

// Before module unload, unregister the provider.


This crate supports the following configurable features:

  • etw: Use Windows ETW APIs to log events. If not enabled, all logging operations will be no-ops. Enabled by default.
  • macros: Re-export the define_provider! and write_event! macros from the tracelogging_macros crate. Enabled by default.

In addition, this crate will log events only if compiled for a Windows operating system. If compiled for a non-Windows operating system, all logging operations will be no-ops.