Crates.io | tracelogging |
lib.rs | tracelogging |
version | |
source | src |
created_at | 2022-09-13 18:52:56.37487+00 |
updated_at | 2025-03-03 21:13:42.115889+00 |
description | TraceLogging for Rust |
homepage | |
repository | https://github.com/microsoft/tracelogging |
max_upload_size | |
id | 664859 |
Cargo.toml error: | TOML parse error at line 19, column 1 | 19 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include` |
size | 0 |
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.
// Note that provider variable is not pub so it is not visible outside the
// module. To share the variable with multiple modules, put the define_provider
// in the parent module, e.g. in lib.rs.
tlg::define_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;
tlg::write_event!(
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.
MY_PROVIDER.unregister();
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.kernel_mode
: Use kernel-mode ETW APIs (e.g. EtwWriteTransfer
) instead of
user-mode ETW APIs (e.g. EventWriteTransfer
).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.