Crate tracing_proc_macros_ink

Crate tracing_proc_macros_ink 

Source
Expand description

§tracing-proc-macros-ink

docs.rs crates.io rustc

tracing-proc-macros-ink provides a working tracing integration for logging from within procedural macros. It only works in proc-macro = true crates and is nightly only.

Log records are emitted using nightly compiler diagnostics.

§Requirements

This crate requires a nightly compiler.

§Usage

Every top level function in your proc_macro crate should call tracing-proc-macros-ink::proc_macro_logger_default_setup() to setup the logger for the proc_macro crate. After that normal tracing logging can be used in the proc_macro crate.

§Example

Check out the example crate example_proc_macro.

§How to turn on logging?

By default logging is turned off.

To run it on, you need to set the RUST_LOG environment variable:

RUST_LOG=trace cargo build --workspace --bins

§How to speed up the compilation?

To remove the logging calls entirely from the proc_macro crate, you can directly depend on tracing and enable the features that remove the logging calls.

§Custom Logger setup

Providing a customized logging setup is trivial. Copy the code from tracing-proc-macros-ink::proc_macro_logger_default_setup() into your own crate and modify it to your needs. The default default-setup feature can be disabled with no-default-features = true to avoid enabling unnecessary tracing-subscriber features.

§License

This project is released under either:

at your choosing.

§Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

tracing

tracing-subscriber

Structs§

RustcDiagnosticsMakeWriter
A MakeWriter implementation that writes tracing logs to proc_macro diagnostics.
RustcDiagnosticsWriter
A io::Write implementation that writes tracing logs to proc_macro diagnostics. Users should not use this directly, but instead pass an instance of RustcDiagnosticsMakeWriter to fmt::Layer::with_writer.

Functions§

proc_macro_logger_default_setup
Sets up a default logging arrangement for the proc_macro. This function should be called once in every top level function of your proc_macro crate. To use a custom logging setup take a look at the source code of this function.