{"id":38015367,"url":"https://github.com/ronny/clog","last_synced_at":"2026-01-16T19:24:32.009Z","repository":{"id":236083201,"uuid":"791876764","full_name":"ronny/clog","owner":"ronny","description":"Google Cloud Logging adapter for `log/slog`.","archived":false,"fork":false,"pushed_at":"2024-05-29T05:00:36.000Z","size":25,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-06-19T11:31:37.458Z","etag":null,"topics":["cloud-logging","cloud-run","go","golang","google-cloud","google-cloud-platform","logging","slog","structured-logging"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ronny.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":"2024-04-25T14:42:01.000Z","updated_at":"2024-06-02T07:39:45.000Z","dependencies_parsed_at":"2024-04-25T15:51:00.972Z","dependency_job_id":"6fe665b0-2d03-4890-9319-18ac03425552","html_url":"https://github.com/ronny/clog","commit_stats":null,"previous_names":["ronny/clog"],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/ronny/clog","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ronny%2Fclog","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ronny%2Fclog/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ronny%2Fclog/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ronny%2Fclog/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ronny","download_url":"https://codeload.github.com/ronny/clog/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ronny%2Fclog/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28481681,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-16T11:59:17.896Z","status":"ssl_error","status_checked_at":"2026-01-16T11:55:55.838Z","response_time":107,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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-run","go","golang","google-cloud","google-cloud-platform","logging","slog","structured-logging"],"created_at":"2026-01-16T19:24:31.889Z","updated_at":"2026-01-16T19:24:31.982Z","avatar_url":"https://github.com/ronny.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# clog\n\n[![Go Reference](https://pkg.go.dev/badge/github.com/ronny/clog.svg)](https://pkg.go.dev/github.com/ronny/clog)\n\nA lightweight [`log/slog.JSONHandler`](https://pkg.go.dev/log/slog#JSONHandler)\nwrapper that adapts the fields to the [Google Cloud Logging structured log\nformat](https://cloud.google.com/logging/docs/structured-logging#structured_logging_special_fields).\n\nThe intended use case is Cloud Run, but it should work in similar environments\nwhere logs are emitted to stdout/stderr and automatically picked up by Cloud\nLogging (e.g. App Engine, Cloud Functions, GKE).\n\n## Features\n\n- Lightweight. The handler merely reformats/renames the structured JSON log\n  fields. It's still [`log/slog.JSONHandler`](https://pkg.go.dev/log/slog#JSONHandler)\n  under the hood. It does NOT send logs to Cloud Logging directly (e.g. using\n  the Cloud SDK).\n\n- Tracing. A tracing middleware is provided to automatically extract tracing\n  information from `traceparent` or `X-Cloud-Trace-Context` HTTP request header,\n  and attaches it to the request context. The Handler automatically includes any\n  tracing information as log attributes.\n\n- Custom levels as supported by Google Cloud Logging, e.g. CRITICAL and NOTICE.\n\n## Usage\n\n```go\nimport (\n\t\"log/slog\"\n\n\t\"cloud.google.com/go/compute/metadata\"\n\t\"github.com/ronny/clog\"\n)\n\nfunc main() {\n\tprojectID, err := metadata.ProjectID()\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\tlogger := slog.New(\n\t\tclog.NewHandler(os.Stderr, clog.HandlerOptions{\n\t\t\tLevel: clog.LevelInfo,\n\t\t\tGoogleProjectID: projectID,\n\t\t}),\n\t)\n\tslog.SetDefault(logger)\n\n\tmux := http.NewServeMux()\n\tmux.Handle(\"POST /warn\", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {\n\t\tctx := r.Context()\n\t\t// ⚠️ The log will have tracing attrs since we're using\n\t\t// trace.Middleware below (assuming trace header is in the request):\n\t\t// \"logging.googleapis.com/trace\"\n\t\t// \"logging.googleapis.com/spanId\"\n\t\t// \"logging.googleapis.com/traceSampled\"\n\t\tslog.WarnContext(ctx, \"flux capacitor is too warm\",\n\t\t\t\"mycount\", 42,\n\t\t)\n\t}))\n\tmux.Handle(\"POST /critical\", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {\n\t\tctx := r.Context()\n\t\t// ⚠️ Custom level CRITICAL\n\t\tslog.Log(ctx, clog.LevelCritical, \"flux capacitor is on fire\")\n\t}))\n\n\tport := os.Getenv(\"PORT\")\n\tif port == \"\" {\n\t\tport = \"8080\"\n\t}\n\tlog.Printf(\"listening on port %s\", port)\n\n\t// ⚠️ `trace.Middleware` to make tracing information available in ctx in mux\n\t// handlers.\n\tif err := http.ListenAndServe(\":\"+port, trace.Middleware(mux)); err != nil {\n\t\tlog.Fatal(err)\n\t}\n}\n```\n\n## Credits and acknowledgements\n\nThank you to Remko Tronçon for doing most of the hard work in\nhttps://github.com/remko/cloudrun-slog which is the basis for this library.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fronny%2Fclog","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fronny%2Fclog","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fronny%2Fclog/lists"}