{"id":13636253,"url":"https://github.com/d-e-s-o/test-log","last_synced_at":"2025-12-12T16:53:53.931Z","repository":{"id":46228725,"uuid":"183934105","full_name":"d-e-s-o/test-log","owner":"d-e-s-o","description":"A replacement of the #[test] attribute that initializes logging and/or tracing infrastructure before running tests.","archived":false,"fork":false,"pushed_at":"2025-03-23T17:51:06.000Z","size":175,"stargazers_count":134,"open_issues_count":7,"forks_count":35,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-04-06T20:01:58.238Z","etag":null,"topics":["env-logger","logging","rust","test","testing"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/d-e-s-o.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE-APACHE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-04-28T16:44:10.000Z","updated_at":"2025-03-28T13:23:30.000Z","dependencies_parsed_at":"2023-10-13T04:16:00.730Z","dependency_job_id":"bc4d1c89-2219-4d8f-abd8-0a4e3fc2c969","html_url":"https://github.com/d-e-s-o/test-log","commit_stats":{"total_commits":62,"total_committers":4,"mean_commits":15.5,"dds":0.06451612903225812,"last_synced_commit":"f500323f947a4bfdcb015edbc814555ddb04a0fc"},"previous_names":["d-e-s-o/test-env-log"],"tags_count":20,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/d-e-s-o%2Ftest-log","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/d-e-s-o%2Ftest-log/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/d-e-s-o%2Ftest-log/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/d-e-s-o%2Ftest-log/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/d-e-s-o","download_url":"https://codeload.github.com/d-e-s-o/test-log/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248790085,"owners_count":21161942,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["env-logger","logging","rust","test","testing"],"created_at":"2024-08-02T00:00:59.022Z","updated_at":"2025-12-12T16:53:48.878Z","avatar_url":"https://github.com/d-e-s-o.png","language":"Rust","readme":"[![pipeline](https://github.com/d-e-s-o/test-log/actions/workflows/test.yml/badge.svg?branch=main)](https://github.com/d-e-s-o/test-log/actions/workflows/test.yml)\n[![crates.io](https://img.shields.io/crates/v/test-log.svg)](https://crates.io/crates/test-log)\n[![Docs](https://docs.rs/test-log/badge.svg)][docs-rs]\n[![rustc](https://img.shields.io/badge/rustc-1.71+-blue.svg)](https://blog.rust-lang.org/2023/07/13/Rust-1.71.0.html)\n\ntest-log\n========\n\n- [Documentation][docs-rs]\n- [Changelog](CHANGELOG.md)\n\n**test-log** is a crate that takes care of automatically initializing\nlogging and/or tracing for Rust tests.\n\nWhen running Rust tests it can often be helpful to have easy access to\nthe verbose log messages emitted by the code under test. Commonly, these\nlog messages may be coming from the [`log`][log] crate or being emitted\nthrough the [`tracing`][tracing] infrastructure.\n\nThe problem with either -- in the context of testing -- is that some\nform of initialization is required in order to make these crate's\nmessages appear on a standard output stream.\n\nThe commonly used [`env_logger`](https://crates.io/crates/env_logger)\n(which provides an easy way to configure `log` based logging), for\nexample, needs to be initialized like this:\n```rust\nlet _ = env_logger::builder().is_test(true).try_init();\n```\nin **each and every** test.\n\nSimilarly, `tracing` based solutions require a subscriber to be\nregistered that writes events/spans to the terminal.\n\nThis crate takes care of this per-test initialization in an intuitive\nway.\n\n\nUsage\n-----\n\nThe crate provides a custom `#[test]` attribute that, when used for\nrunning a particular test, takes care of initializing `log` and/or\n`tracing` beforehand.\n\n#### Example\n\nAs such, usage is as simple as importing and using said attribute:\n```rust\nuse test_log::test;\n\n#[test]\nfn it_works() {\n  info!(\"Checking whether it still works...\");\n  assert_eq!(2 + 2, 4);\n  info!(\"Looks good!\");\n}\n```\n\nIt is of course also possible to initialize logging for a chosen set of\ntests, by only annotating these with the custom attribute:\n```rust\n#[test_log::test]\nfn it_still_works() {\n  // ...\n}\n```\n\nYou can also wrap another attribute. For example, suppose you use\n[`#[tokio::test]`][tokio-test] to run async tests:\n```rust\nuse test_log::test;\n\n#[test(tokio::test)]\nasync fn it_still_works() {\n  // ...\n}\n```\n\n#### Cargo Feature Flags\n\n```toml\n# Cargo.toml\n[dependencies]\n# PICK ONE OF THE FOLLOWING:\n\n# Support `log` crate only (default).\ntest-log = {version = \"0.2\"}\n# Support `log` and `tracing` crates.\ntest-log = {version = \"0.2\", features = [\"trace\"]}\n# Support only `tracing` crate.\ntest-log = {version = \"0.2\", default-features = false, features = [\"trace\"]}\n```\n\nThe crate comes with two features pertaining \"backend\" initialization:\n- `log`, enabled by default, controls initialization for the `log`\n  crate.\n- `trace`, disabled by default, controls initialization for the\n  `tracing` crate.\n\nDepending on what backend the crate-under-test (and its dependencies)\nuse, the respective feature(s) should be enabled to make messages that\nare emitted by the test manifest on the terminal.\n\nOn top of that, the `color` feature (enabled by default) controls\nwhether to color output by default.\n\n#### Logging Configuration\n\nAs usual when running `cargo test`, the output is captured by the\nframework by default and only shown on test failure. The `--nocapture`\nargument can be supplied in order to overwrite this setting. E.g.,\n```bash\n$ cargo test -- --nocapture\n```\n\nFurthermore, the `RUST_LOG` environment variable is honored and can be\nused to influence the log level to work with (among other things). By\ndefault, log messages of criticality `INFO` (and higher) will be\nemitted. Please refer to the [`env_logger` docs][env-docs-rs] and\n[`tracing-subscriber`][tracing-env-docs-rs] documentation for supported\nvariable syntax and more information.\n\nIf the `trace` feature is enabled, the `RUST_LOG_SPAN_EVENTS`\nenvironment variable can be used to configure the tracing subscriber to\nlog synthesized events at points in the span lifecycle. Set the variable\nto a comma-separated list of events you want to see. For example,\n`RUST_LOG_SPAN_EVENTS=full` or `RUST_LOG_SPAN_EVENTS=new,close`.\n\nValid events are `new`, `enter`, `exit`, `close`, `active`, and `full`.\nSee the [`tracing_subscriber` docs][tracing-events-docs-rs] for details\non what the events mean.\n\n#### MSRV Policy\nThis crate adheres to Cargo's [semantic versioning rules][cargo-semver].\nAt a minimum, it builds with the most recent Rust stable release minus\nfive minor versions (\"N - 5\"). E.g., assuming the most recent Rust\nstable is `1.68`, the crate is guaranteed to build with `1.63` and\nhigher.\n\n[cargo-semver]: https://doc.rust-lang.org/cargo/reference/resolver.html#semver-compatibility\n[docs-rs]: https://docs.rs/test-log\n[env-docs-rs]: https://docs.rs/env_logger/0.11.2/env_logger\n[log]: https://crates.io/crates/log\n[tokio-test]: https://docs.rs/tokio/1.4.0/tokio/attr.test.html\n[tracing]: https://crates.io/crates/tracing\n[tracing-env-docs-rs]: https://docs.rs/tracing-subscriber/0.3.18/tracing_subscriber/filter/struct.EnvFilter.html#directives\n[tracing-events-docs-rs]: https://docs.rs/tracing-subscriber/0.3.18/tracing_subscriber/fmt/struct.SubscriberBuilder.html#method.with_span_events\n","funding_links":[],"categories":["Development tools"],"sub_categories":["Testing"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fd-e-s-o%2Ftest-log","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fd-e-s-o%2Ftest-log","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fd-e-s-o%2Ftest-log/lists"}