Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add trace logging to fuel core #932

Merged
merged 3 commits into from
Jan 25, 2023
Merged

Add trace logging to fuel core #932

merged 3 commits into from
Jan 25, 2023

Conversation

freesig
Copy link
Contributor

@freesig freesig commented Jan 25, 2023

This adds a tracing subscriber to any of our tests but it is behind the env var FUEL_TRACE so it doesn't collide with any downstream or custom subscribers.:

Usage

To enable tracing for a test, add the following to the lib.rs file of the crate you want to trace:

#[cfg(test)]
fuel_core_trace::enable_tracing!();

If you also want tracing in your integration tests, you need to add the above to each integration tests file.

Tracing is still disabled by default so to enable it set the following environment variable:

export FUEL_TRACE=1

Or if you just want it for a single test run:

FUEL_TRACE=1 cargo test

Now you will have error level tracing like:

2023-01-25T02:27:14.362856Z ERROR works: tracing: I'm visible if FUEL_TRACE=1 is set

You can use the RUST_LOG environment variable to control the level of tracing you want to see. For example:

FUEL_TRACE=1 RUST_LOG=trace cargo test

Additional Subscribers

You can set a few different types of subscribers:

Compact output:

FUEL_TRACE=compact cargo test

Pretty output:

FUEL_TRACE=pretty cargo test

Log to file:

FUEL_TRACE=log-file cargo test

Log to file and output to console:

FUEL_TRACE=log-show cargo test

You can also set the log file path:

FUEL_TRACE_PATH=/some/path FUEL_TRACE=log-file cargo test

If you don't set the path, it will default to CARGO_MANIFEST_DIR/logs/logfile.

@freesig freesig requested a review from a team January 25, 2023 02:36
@freesig freesig self-assigned this Jan 25, 2023
@freesig freesig mentioned this pull request Jan 25, 2023
6 tasks
@freesig freesig enabled auto-merge (squash) January 25, 2023 20:50
@freesig freesig merged commit 356e6d0 into master Jan 25, 2023
@freesig freesig deleted the freesig/test-tracing branch January 25, 2023 21:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants