{"id":18155409,"url":"https://github.com/hirosassa/zerodriver","last_synced_at":"2025-05-01T13:13:22.663Z","repository":{"id":40470353,"uuid":"337906055","full_name":"hirosassa/zerodriver","owner":"hirosassa","description":"Zerolog based logging library optimized for Cloud Logging (formerly Stackdriver Logging)","archived":false,"fork":false,"pushed_at":"2023-03-19T22:19:03.000Z","size":35,"stargazers_count":30,"open_issues_count":7,"forks_count":10,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-05-01T12:49:41.370Z","etag":null,"topics":["cloud-logging","cloud-trace","golang","google-cloud","structured-logging","zerolog"],"latest_commit_sha":null,"homepage":"","language":"Go","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/hirosassa.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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":"2021-02-11T01:58:41.000Z","updated_at":"2024-06-01T05:45:21.000Z","dependencies_parsed_at":"2024-06-18T21:10:35.751Z","dependency_job_id":"22b50463-f3ac-4c8c-b5d2-c9abd16284c9","html_url":"https://github.com/hirosassa/zerodriver","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hirosassa%2Fzerodriver","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hirosassa%2Fzerodriver/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hirosassa%2Fzerodriver/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hirosassa%2Fzerodriver/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hirosassa","download_url":"https://codeload.github.com/hirosassa/zerodriver/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251879117,"owners_count":21658690,"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":["cloud-logging","cloud-trace","golang","google-cloud","structured-logging","zerolog"],"created_at":"2024-11-02T04:10:53.182Z","updated_at":"2025-05-01T13:13:22.643Z","avatar_url":"https://github.com/hirosassa.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# zerodriver\n\n[![Actions Status: test](https://github.com/hirosassa/zerodriver/workflows/test/badge.svg)](https://github.com/hirosassa/zerodriver/actions?query=workflow%3A\"test\")\n[![Actions Status: golangci-lint](https://github.com/hirosassa/zerodriver/workflows/golangci-lint/badge.svg)](https://github.com/hirosassa/zerodriver/actions?query=workflow%3A\"golangci-lint\")\n[![Go Reference](https://pkg.go.dev/badge/github.com/hirosassa/zerodriver.svg)](https://pkg.go.dev/github.com/hirosassa/zerodriver)\n[![Go Report Card](https://goreportcard.com/badge/github.com/hirosassa/zerodriver)](https://goreportcard.com/report/github.com/hirosassa/zerodriver)\n[![Coverage Status](https://coveralls.io/repos/github/hirosassa/zerodriver/badge.svg?branch=master)](https://coveralls.io/github/hirosassa/zerodriver?branch=master)\n[![Apache-2.0](https://img.shields.io/github/license/hirosassa/zerodriver)](LICENSE)\n\n[Zerolog](https://github.com/rs/zerolog) based logging libary optimized for [Cloud Logging](https://cloud.google.com/logging) (formerly Stackdriver Logging). This package is inspired by [Zapdriver](https://github.com/blendle/zapdriver).\n\n## What is this package?\n\nThis package provides simple structured logger optimized for [Cloud Logging](https://cloud.google.com/logging) based on [zerolog](https://github.com/rs/zerolog).\n\nKey features of zerodriver are:\n\n- zerolog based simple method chaining API\n- optimized for [Cloud Logging LogEntry](https://cloud.google.com/logging/docs/reference/v2/rest/v2/LogEntry) format\n\n## Usage\n\nFirst of all, initialize a logger.\n\n```go\nlogger := zerodriver.NewProductionLogger() // production mode (global log level set to `info`)\nlogger := zerodriver.NewDevelopmentLogger() // development mode (global log level set to `debug`)\n```\n\nThen, write logs by using zerolog based fluent API!\n```go\nlogger.Info().Str(\"key\", \"value\").Msg(\"Hello World!\")\n// output: {\"severity\":\"INFO\",\"key\":\"value\",\"time\":\"2009-11-10T23:00:00Z\",\"message\":\"hello world\"}\n```\n\nHere's complete example:\n\n```go\npackage main\n\nimport (\n    \"github.com/hirosassa/zerodriver\"\n)\n\nfunc main() {\n    logger := zerodriver.NewProductionLogger()\n    logger.Info().Str(\"key\", \"value\").Msg(\"hello world\")\n}\n\n// output: {\"severity\":\"INFO\",\"key\":\"value\",\"time\":\"2009-11-10T23:00:00Z\",\"message\":\"hello world\"}\n```\n\n### GCP specific fields\n\nIf your log follows [LogEntry](https://cloud.google.com/logging/docs/reference/v2/rest/v2/LogEntry) format,\nyou can query logs or create metrics alert easier and efficiently on GCP Cloud Logging console.\n\n#### HTTP request\n\nTo log HTTP related metrics and information, you can use following function\n\n```go\nfunc (e *Event) HTTP(req *HTTPPayload) *zerolog.Event\n```\n\nThis feature is forked from zapdriver. You can generate `zerodriver.HTTPPayload` from `http.Request` and `http.Response` using `NewHTTP` function.\nSame as zapdriver.NewHTTP, following fields needs to be set manually:\n\n- `ServerIP`\n- `Latency`\n- `CacheLookup`\n- `CacheHit`\n- `CacheValidatedWithOriginServer`\n- `CacheFillBytes`\n\nUsing these feature, you can log HTTP related information as follows,\n\n```go\np := NewHTTP(req, res)\np.Latency = time.Since(start) // add some fields manually\nlogger.Info().HTTP(p).Msg(\"request received\")\n```\n\n#### Trace context\n\nTo add trace information to your log, you can use `TraceContext`. The signature of the function is as follows:\n```go\nfunc (e *Event) TraceContext(trace string, spanId string, sampled bool, projectID string) *zerolog.Event\n```\n\nYou can use this feature as follows:\n\n```go\nimport\t\"go.opencensus.io/trace\"\n\nspan := trace.FromContext(r.Context()).SpanContext()\nlogger.Info().TraceContext(span.TraceID.String(), span.SpanID.String(), true, \"my-project\").Msg(\"trace contexts\")\n\n// {\"severity\":\"INFO\",\"logging.googleapis.com/trace\":\"projects/my-project/traces/00000000000000000000000000000000\",\"logging.googleapis.com/spanId\":\"0000000000000000\",\"logging.googleapis.com/trace_sampled\":true,\"message\":\"trace contexts\"}\n```\n\n#### Labels\n\nYou can add any \"labels\" to your log by following:\n\n```go\nlogger.Info().Labels(zerodriver.Label(\"foo\", \"var\")).Msg(\"labeled log\")\n\n// {\"severity\":\"INFO\",\"logging.googleapis.com/labels\":{\"foo\":\"var\"},\"message\":\"labeled log\"}\n```\n\n#### Operations\n\nYou can add additional information about a potentially long-running operation with which a log entry is associated by following function:\n\n```go\nfunc (e *Event) Operation(id, producer string, first, last bool) *zerolog.Event\n```\nLog entries with the same `id` are assumed to be part of the same operation.\nThe producer is an arbitrary identifier that should be globally unique amongst all the logs of all your applications (meaning it should probably be the unique name of the current application).\nYou should set `first` to true for the first log in the operation, and `last` to true for the final log of the operation.\n\nAlso see, https://cloud.google.com/logging/docs/reference/v2/rest/v2/LogEntry#LogEntryOperation\n\nFor readable implementation of `operation` log, you can use following functions:\n\n```go\nfunc (e *Event) OperationStart(id, producer string) *zerolog.Event\nfunc (e *Event) OperationContinue(id, producer string) *zerolog.Event\nfunc (e *Event) OperationEnd(id, producer string) *zerolog.Event\n```\n\nA concrete example of operation log is as follows:\n\n```go\nlogger.Info().OperationStart(\"foo\", \"bar\").Msg(\"started\")\nlogger.Debug().OperationContinue(\"foo\", \"bar\").Msg(\"processing\")\nlogger.Info().OperationEnd(\"foo\", \"bar\").Msg(\"done\")\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhirosassa%2Fzerodriver","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhirosassa%2Fzerodriver","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhirosassa%2Fzerodriver/lists"}