{"id":16847829,"url":"https://github.com/stepancheg/rust-log-ndc","last_synced_at":"2025-04-11T06:38:26.603Z","repository":{"id":62442407,"uuid":"169000517","full_name":"stepancheg/rust-log-ndc","owner":"stepancheg","description":"log crate extension with NDC-like functionality","archived":false,"fork":false,"pushed_at":"2021-02-22T22:10:49.000Z","size":23,"stargazers_count":5,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-25T04:33:06.884Z","etag":null,"topics":["logging","rust"],"latest_commit_sha":null,"homepage":null,"language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/stepancheg.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-02-03T22:24:27.000Z","updated_at":"2022-06-28T13:52:28.000Z","dependencies_parsed_at":"2022-11-01T22:02:32.501Z","dependency_job_id":null,"html_url":"https://github.com/stepancheg/rust-log-ndc","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stepancheg%2Frust-log-ndc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stepancheg%2Frust-log-ndc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stepancheg%2Frust-log-ndc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stepancheg%2Frust-log-ndc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/stepancheg","download_url":"https://codeload.github.com/stepancheg/rust-log-ndc/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248126300,"owners_count":21051901,"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":["logging","rust"],"created_at":"2024-10-13T13:09:10.854Z","updated_at":"2025-04-11T06:38:26.567Z","avatar_url":"https://github.com/stepancheg.png","language":"Rust","readme":"# log crate extension with NDC-like functionality\n\n[![Build Status](https://img.shields.io/travis/stepancheg/rust-log-ndc.svg)](https://travis-ci.org/stepancheg/log-ndc)\n[![License](https://img.shields.io/crates/l/log-ndc.svg)](https://github.com/stepancheg/rust-log-ndc/blob/master/LICENSE.txt)\n[![crates.io](https://img.shields.io/crates/v/log-ndc.svg)](https://crates.io/crates/log-ndc)\n\n* `log-ndc` crate provides a logger which wraps arbitrary logger\n  which prepends thread-local information to each log message\n* `log-ndc-env-logger` is a very simple (10 lines of code) drop-in wrapper/replacement of `env_logger` crate\n\n## log-ndc\n\nThis crate allows settings a thread-local variable which will be prepended to log messages.\n\n`log_ndc::set_boxed_logger(logger)` wraps passed `logger` object with `log_ndc::Logger` and calls\nunderlying `log::set_boxed_logger(..)`.\n\n`log_ndc` functions like `log_ndc::set(..)` or `log_ndc::push(..)` replace thread-local text\nwhich is later prepended to log messages in the wrapper logger.\n\n```\n// works exactly like regular `warn!` macro with any logger\n// `warn!` is a macro from `log` library\nwarn!(\"something happened\");\n\n// set thread-local information like request id\nlog_ndc::set(format!(\"reqid={}\", 10));\n\ninfo!(\"starting request\");\n// outputs\n// INFO 2019-02-03T23:51:26Z: mycrate: [reqid=10] starting request\n```\n\n## log-ndc-env-logger\n\nDrop-in replacement/wrapper of `env_logger` crate.\n\nIt simply initialzes `env_logger` wrapper and wraps it with `log_ndc::Logger`.\n\nThe crate is dead simple, have a look at\n[single file source](https://github.com/stepancheg/rust-log-ndc/blob/master/log-ndc-env-logger/src/lib.rs).\n\n## FAQ\n\n(I think these are FAQ, however nobody asked me anything yet.)\n\n### What what NDC means?\n\nThe word \"NDC\" is [taken from log4j](https://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/NDC.html),\nit means \"nested dianostics context\".\n\n### Is it compatible with `log` crate or my favorite backend?\n\nYes, `log-ndc` wraps logging backend and delegates it to `log` crate.\n\nSo all macros like `warn!(..)` should work as before.\n\n## See also `log-mdc`\n\n* [log-mdc](https://github.com/sfackler/rust-log-mdc) is a similar project, which allows storing thread-local\ndata by key. However, log-mdc is compatible only with certain loggers like\n[log4rs](https://github.com/sfackler/log4rs). It is not possible to obtain thread-local information set in\n`log-mdc` in when e. g. `env-logger` is used.\n\n## Where should we go?\n\nI think it would be right thing if `log` crate supported basic\nthread-local context like provided in this crate.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstepancheg%2Frust-log-ndc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstepancheg%2Frust-log-ndc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstepancheg%2Frust-log-ndc/lists"}