{"id":15439481,"url":"https://github.com/glassonion1/logz","last_synced_at":"2025-04-15T16:41:17.785Z","repository":{"id":38329032,"uuid":"318683307","full_name":"glassonion1/logz","owner":"glassonion1","description":"The logz is Go library for grouping a access log and application logs","archived":false,"fork":false,"pushed_at":"2023-05-22T22:58:58.000Z","size":755,"stargazers_count":54,"open_issues_count":6,"forks_count":4,"subscribers_count":4,"default_branch":"main","last_synced_at":"2024-10-18T11:23:05.579Z","etag":null,"topics":["go","golang","grpc","http","logger","logging","opentelemetry"],"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/glassonion1.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","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},"funding":{"github":null,"patreon":null,"open_collective":null,"ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"custom":null}},"created_at":"2020-12-05T02:23:15.000Z","updated_at":"2024-02-15T00:25:31.000Z","dependencies_parsed_at":"2024-06-18T19:59:30.107Z","dependency_job_id":"85975577-996c-4bdf-ae25-38fd56d7086a","html_url":"https://github.com/glassonion1/logz","commit_stats":{"total_commits":194,"total_committers":5,"mean_commits":38.8,"dds":0.365979381443299,"last_synced_commit":"f037fdaee5697aba108b12510eff6ef1f856f06e"},"previous_names":[],"tags_count":52,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/glassonion1%2Flogz","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/glassonion1%2Flogz/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/glassonion1%2Flogz/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/glassonion1%2Flogz/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/glassonion1","download_url":"https://codeload.github.com/glassonion1/logz/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249110230,"owners_count":21214296,"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":["go","golang","grpc","http","logger","logging","opentelemetry"],"created_at":"2024-10-01T19:06:44.538Z","updated_at":"2025-04-15T16:41:17.768Z","avatar_url":"https://github.com/glassonion1.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Logz - yet another logger library for go\n\n![CI for Pull Request](https://github.com/glassonion1/logz/workflows/CI%20for%20Pull%20Request/badge.svg)\n[![Godoc](https://img.shields.io/badge/godoc-reference-blue)](https://godoc.org/github.com/glassonion1/logz)\n[![Go Report Card](https://goreportcard.com/badge/github.com/glassonion1/logz)](https://goreportcard.com/report/github.com/glassonion1/logz)\n[![GitHub license](https://img.shields.io/github/license/glassonion1/logz)](https://github.com/glassonion1/logz/blob/main/LICENSE)\n\nThe logz is logger library for grouping application logs related a access log. The logz uses OpenTelemetry([https://opentelemetry.io](https://opentelemetry.io)) to generate the trace id.  \nThis is for Google Cloud Logging (formerly known as Stackdriver Logging).  \n\n![screenshot](https://github.com/glassonion1/logz/blob/main/img/screenshot.png \"Cloug Logging\")\n\n## Features\n* Writes access log each http requests\n* Writes application log\n* Grouping application logs related a access log.\n  * The parent entry will inherit the severity of its children\n* Supports to App Engine 2nd and Cloud Run and GKE.\n\nUse [go111](https://github.com/glassonion1/logz/tree/main/go111) package if your project is App Engine 1st generation.\n\n### Contribution Packages\nThe logz contribution packages that provides middlewares for 3rd-party Go packages.\n* [gin](https://github.com/glassonion1/logz/tree/main/contrib/github.com/gin-gonic/gin/logzgin)\n* [echo](https://github.com/glassonion1/logz/tree/main/contrib/github.com/labstack/echo/logzecho)\n* [gRPC](https://github.com/glassonion1/logz/tree/main/contrib/google.golang.org/grpc/logzgrpc)\n\nFor more details: [https://github.com/glassonion1/logz/tree/main/contrib](https://github.com/glassonion1/logz/tree/main/contrib)\n\n## Install\n```\n$ go get github.com/glassonion1/logz\n```\n\n## Usage\n### Google App Engine Standard\n```go\nfunc main() {\n    mux := http.NewServeMux()\n    mux.HandleFunc(\"/\", func(w http.ResponseWriter, r *http.Request) {\n        ctx := r.Context()\n\n        // Writes info log\n        logz.Infof(ctx, \"writes %s log\", \"info\")\n    })\n\n    logz.SetConfig(logz.Config{\n        NeedsAccessLog: true, // Writes the access log\n    })\n    logz.InitTracer()\n    // Sets the middleware\n    h := middleware.NetHTTP(\"tracer name\")(mux)\n\n    log.Fatal(http.ListenAndServe(\":8080\", h))\n}\n```\n### Cloud Run\n```go\nfunc main() {\n    mux := http.NewServeMux()\n    mux.HandleFunc(\"/\", func(w http.ResponseWriter, r *http.Request) {\n        ctx := r.Context()\n\n        // Writes info log\n        logz.Infof(ctx, \"writes %s log\", \"info\")\n    })\n\n    logz.SetConfig(logz.Config{\n        ProjectID:       \"your gcp project id\",\n        NeedsAccessLog: false, // Writes no access log\n    })\n    logz.InitTracer()\n    // Sets the middleware\n    h := middleware.NetHTTP(\"tracer name\")(mux)\n\n    log.Fatal(http.ListenAndServe(\":8080\", h))\n}\n```\n### GKE\n```go\nfunc main() {\n    mux := http.NewServeMux()\n    mux.HandleFunc(\"/\", func(w http.ResponseWriter, r *http.Request) {\n        ctx := r.Context()\n\n        // Writes info log\n        logz.Infof(ctx, \"writes %s log\", \"info\")\n    })\n\n    logz.SetConfig(logz.Config{\n        ProjectID:       \"your gcp project id\",\n        NeedsAccessLog: true, // Writes the access log\n    })\n    logz.InitTracer()\n    // Sets the middleware\n    h := middleware.NetHTTP(\"tracer name\")(mux)\n\n    log.Fatal(http.ListenAndServe(\":8080\", h))\n}\n```\n\n## Examples\nSee this sample projects for logz detailed usage  \nhttps://github.com/glassonion1/logz/tree/main/example\n\n## How logs are grouped\nThe logz leverages the grouping feature of GCP Cloud Logging. See following references for more details.\n* https://godoc.org/cloud.google.com/go/logging#hdr-Grouping_Logs_by_Request\n\n## Log format\nThe log format is based on [LogEntry](https://cloud.google.com/logging/docs/reference/v2/rest/v2/LogEntry)'s structured payload\n\n### Application log format\n\n```json\n{\n  \"severity\":\"INFO\",\n  \"message\":\"writes info log\",\n  \"time\":\"2020-12-31T23:59:59.999999999Z\",\n  \"logging.googleapis.com/sourceLocation\":{\n    \"file\":\"logger_test.go\",\n    \"line\":\"57\",\n    \"function\":\"github.com/glassonion1/logz/internal/logger_test.TestLoggerWriteApplicationLog.func3\"\n  },\n  \"logging.googleapis.com/trace\":\"projects/test/traces/00000000000000000000000000000000\",\n  \"logging.googleapis.com/spanId\":\"0000000000000000\",\n  \"logging.googleapis.com/trace_sampled\":false\n}\n```\n\n### Access log format\n\n```json\n{\n  \"severity\":\"DEFAULT\",\n  \"time\":\"2020-12-31T23:59:59.999999999Z\",\n  \"logging.googleapis.com/trace\":\"projects/test/traces/a0d3eee13de6a4bbcf291eb444b94f28\",\n  \"httpRequest\":{\n    \"requestMethod\":\"GET\",\n    \"requestUrl\":\"/test1\",\n    \"requestSize\":\"0\",\n    \"status\":200,\n    \"responseSize\":\"333\",\n    \"remoteIp\":\"192.0.2.1\",\n    \"serverIp\":\"192.168.100.115\",\n    \"latencyy\":{\n      \"nanos\":100,\n      \"seconds\":0\n    },\n    \"protocol\":\"HTTP/1.1\"\n  }\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fglassonion1%2Flogz","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fglassonion1%2Flogz","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fglassonion1%2Flogz/lists"}