{"id":3662331,"name":"github.com/docker/dctx","ecosystem":"go","description":"Package dctx provides several utilities for working with\ngolang.org/x/net/context in http requests. Primarily, the focus is on\nlogging relevent request information but this package is not limited to\nthat purpose.\n\nThe easiest way to get started is to get the background context:\n\nThe returned context should be passed around your application and be the\nroot of all other context instances. If the application has a version, this\nline should be called before anything else:\n\nThe above will store the version in the context and will be available to\nthe logger.\n\nThe most useful aspect of this package is GetLogger. This function takes\nany context.Context interface and returns the current logger from the\ncontext. Canonical usage looks like this:\n\nGetLogger also takes optional key arguments. The keys will be looked up in\nthe context and reported with the logger. The following example would\nreturn a logger that prints the version with each log message:\n\nThe above would print out a log message like this:\n\nWhen used with WithLogger, we gain the ability to decorate the context with\nloggers that have information from disparate parts of the call stack.\nFollowing from the version example, we can build a new context with the\nconfigured logger such that we always print the version field:\n\nSince the logger has been pushed to the context, we can now get the version\nfield for free with our log messages. Future calls to GetLogger on the new\ncontext will have the version field:\n\nThis becomes more powerful when we start stacking loggers. Let's say we\nhave the version logger from above but also want a request id. Using the\ncontext above, in our request scoped function, we place another logger in\nthe context:\n\nWhen GetLogger is called on the new context, \"http.request.id\" will be\nincluded as a logger field, along with the original \"version\" field:\n\nNote that this only affects the new context, the previous context, with the\nversion field, can be used independently. Put another way, the new logger,\nadded to the request context, is unique to that context and can have\nrequest scoped varaibles.\n\nThis package also contains several methods for working with http requests.\nThe concepts are very similar to those described above. We simply place the\nrequest in the context using WithRequest. This makes the request variables\navailable. GetRequestLogger can then be called to get request specific\nvariables in a log line:\n\nLike above, if we want to include the request data in all log messages in\nthe context, we push the logger to a new context and use that one:\n\nThe concept is fairly powerful and ensures that calls throughout the stack\ncan be traced in log messages. Using the fields like \"http.request.id\", one\ncan analyze call flow for a particular request with a simple grep of the\nlogs.","homepage":"https://github.com/docker/dctx","licenses":"Apache-2.0","normalized_licenses":["Apache-2.0"],"repository_url":"https://github.com/docker/dctx","keywords_array":[],"namespace":"github.com/docker","versions_count":1,"first_release_published_at":"2015-11-04T02:49:56.000Z","latest_release_published_at":"2015-11-04T02:49:56.000Z","latest_release_number":"v0.0.0-20151104024956-4251a81a3473","last_synced_at":"2026-04-07T19:16:32.533Z","created_at":"2022-04-11T10:05:31.403Z","updated_at":"2026-04-07T19:16:32.533Z","registry_url":"https://pkg.go.dev/github.com/docker/dctx","install_command":"go get github.com/docker/dctx","documentation_url":"https://pkg.go.dev/github.com/docker/dctx#section-documentation","metadata":{},"repo_metadata":{},"repo_metadata_updated_at":"2023-03-21T18:55:18.327Z","dependent_packages_count":0,"downloads":null,"downloads_period":null,"dependent_repos_count":0,"rankings":{"downloads":null,"dependent_repos_count":9.345852080216646,"dependent_packages_count":6.999148183520997,"stargazers_count":null,"forks_count":null,"average":8.172500131868823},"purl":"pkg:golang/github.com/docker/dctx","advisories":[],"docker_usage_url":"https://docker.ecosyste.ms/usage/go/github.com/docker/dctx","docker_dependents_count":null,"docker_downloads_count":null,"usage_url":"https://repos.ecosyste.ms/usage/go/github.com/docker/dctx","dependent_repositories_url":"https://repos.ecosyste.ms/api/v1/usage/go/github.com/docker/dctx/dependencies","status":null,"funding_links":[],"critical":null,"issue_metadata":null,"versions_url":"https://packages.ecosyste.ms/api/v1/registries/proxy.golang.org/packages/github.com%2Fdocker%2Fdctx/versions","version_numbers_url":"https://packages.ecosyste.ms/api/v1/registries/proxy.golang.org/packages/github.com%2Fdocker%2Fdctx/version_numbers","dependent_packages_url":"https://packages.ecosyste.ms/api/v1/registries/proxy.golang.org/packages/github.com%2Fdocker%2Fdctx/dependent_packages","related_packages_url":"https://packages.ecosyste.ms/api/v1/registries/proxy.golang.org/packages/github.com%2Fdocker%2Fdctx/related_packages","codemeta_url":"https://packages.ecosyste.ms/api/v1/registries/proxy.golang.org/packages/github.com%2Fdocker%2Fdctx/codemeta","maintainers":[]}