{"id":39138023,"url":"https://github.com/alt4dev/gcloud","last_synced_at":"2026-01-17T21:27:38.467Z","repository":{"id":57659330,"uuid":"473027388","full_name":"alt4dev/gcloud","owner":"alt4dev","description":"Alt4 logging library for gcloud","archived":false,"fork":false,"pushed_at":"2023-01-31T19:00:14.000Z","size":132,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-06-20T09:07:32.321Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/alt4dev.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}},"created_at":"2022-03-23T03:47:08.000Z","updated_at":"2022-03-24T10:10:29.000Z","dependencies_parsed_at":"2023-02-16T22:10:25.224Z","dependency_job_id":null,"html_url":"https://github.com/alt4dev/gcloud","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"purl":"pkg:github/alt4dev/gcloud","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alt4dev%2Fgcloud","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alt4dev%2Fgcloud/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alt4dev%2Fgcloud/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alt4dev%2Fgcloud/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/alt4dev","download_url":"https://codeload.github.com/alt4dev/gcloud/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alt4dev%2Fgcloud/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28518625,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-17T18:55:29.170Z","status":"ssl_error","status_checked_at":"2026-01-17T18:55:03.375Z","response_time":85,"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":[],"created_at":"2026-01-17T21:27:38.381Z","updated_at":"2026-01-17T21:27:38.453Z","avatar_url":"https://github.com/alt4dev.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003ca href=\"https://alt4.dev\"\u003e\u003cimg src=\"https://alt4.dev/banner.svg\" alt=\"\" height=\"120\"\u003e\u003c/a\u003e\n\n# Advanced Logging and Tracking 4 Developers\nWe stand by the principle of making developers' work easier, being able to debug your application easily is one of those requirements.\n\nIf you write logs through Google Cloud AppEngine python then you get your log requests automatically grouped for you per request by Google.\nThis functionality is not available on modern container based servers even the ones running on GCP. If you need the functionality you have to implement it yourself.\n\nThis library bridges that gap and provides a familiar API allowing you to easily group your logs. If you need assistance integrating this library reach out to: [me@billcountry.tech](mailto:me@billcountry.tech)\n\n## Google Cloud Logging Client, [Docs](https://pkg.go.dev/mod/github.com/alt4dev/gcloud)\n\n### Install\n```shell script\ngo get github.com/alt4dev/gcloud\n```\n\n### Configuration\n#### Authentication\nTo authenticate with gcloud see: [https://cloud.google.com/logging/docs/reference/libraries#setting_up_authentication](https://cloud.google.com/logging/docs/reference/libraries#setting_up_authentication).\nAn environment variable `PROJECT_ID` is required to set up the logging client.\n\n#### Mode\nDifferent modes are applicable:\n- `release`: This is the default mode and, it sends logs to Google cloud logging without emitting them to `stderr`\n- `debug`: This mode sends logs to Google cloud logging and emits them to `stderr`\n- `testing`: This mode only emits logs to `stderr` without attempting to send them to Google cloud logging\n- `silent`: This mode will silently ignore all the logs, they won't be sent to Google cloud logging or emitted to `stderr`\n\nYou can set a mode as shown below or by setting the environment variable `ALT4_MODE`\n```go\npackage main\nimport (\n    alt4Service \"github.com/alt4dev/gcloud/service\"\n)\n\nalt4Service.SetMode(\"release\")\n```\n\n#### Monitored Resource\nSet the monitored resource that the logs will be produced from. Below is an example of a monitored resource for a Google cloud run service.\n```json\n{\n    \"labels\": {\n        \"configuration_name\": \"test\",\n        \"location\": \"us-central1\",\n        \"project_id\": \"alt4dev\",\n        \"revision_name\": \"test-april-fools\",\n        \"service_name\": \"test-service\"\n    },\n    \"type\": \"cloud_run_revision\"\n}\n```\n\nThis library provides a function `service.SetMonitoredResource` to set a monitored resource for your service.\nThe easiest way to get these values is to check a previous log entry printed by the same resource to CGP logging.\n\nBelow is how you'd set the monitored resource for the above example:\n```go\npackage main\n\nimport (\n\t\"os\"\n\talt4Service \"github.com/alt4dev/gcloud/service\"\n)\n\nfunc init() {\n\t// The variables K_SERVICE, K_REVISION, K_CONFIGURATION are automatically added to a running Cloud run container\n\talt4Service.SetMonitoredResource(\"cloud_run_revision\", map[string]string{\n\t\t\"configuration_name\": os.Getenv(\"K_CONFIGURATION\"),\n\t\t\"location\": \"us-central1\",\n\t\t\"project_id\": os.Getenv(\"PROJECT_ID\"),\n\t\t\"revision_name\": os.Getenv(\"K_REVISION\"),\n\t\t\"service_name\": os.Getenv(\"K_SERVICE\"),\n    })   \n}\n\n```\n\n\n### Usage\nThis client emulates golang's built in `log` package as much as possible. Logs will be written asynchronously to Google cloud logging.\nIf you're running on a system that doesn't allow background processes(goroutines) e.g. google cloud run,\nwe recommend using [log grouping](#grouping) and making sure you defer close group. This will wait for all writes to complete.\n```go\npackage main\nimport (\n    \"github.com/alt4dev/gcloud/log\"\n    \"time\"\n)\n\nfunc main() {\n    log.Println(\"Normal logging as you're used to\")\n    log.Debugf(\"A formatted log entry, current time %s\", time.Now())\n    log.Warning(\"Create a log with a Warning severity level\")\n    log.Error(\"Create a log with an error severity level. This won't exit after.\")\n    log.Fatal(\"Logs with a critical severity level then exits with status 1.\")\n    log.Panic(\"Logs with a critical severity level then panics.\")\n}\n```\n\n#### Grouping\nGrouping can help you resolve issues faster by grouping related logs together.\nGoogle cloud logging groups logs based on a http request, this library uses goroutines to determine logs in the same request.\n\nThis example demonstrates the setup of a logging middle ware.\n```go\npackage main\n\nimport (\n    \"github.com/alt4dev/gcloud/log\"\n    \"net/http\"\n)\n\nfunc loggingMiddleWare(next http.Handler) http.Handler {\n    return http.HandlerFunc(func(writer http.ResponseWriter, request *http.Request) {\n\t\tlabels := make(map[string]interface{})\n        // Start a logging group for this request\n        group := log.Group(request, labels)\n\t\tdefer group.Close()\n\t\t\n\t\t// You can set additional labels to the group or even set the status of the request\n\t\t// These steps are not necessary\n\t\tgroup.SetLabel(\"key\", \"value\")\n\t\tgroup.SetStatus(200)\n\n        // All logs after this line will be grouped\n\n        next.ServeHTTP(writer, request)\n    })\n}\n\n```\n\n#### Set Default Logger to Write to Google cloud logging\nThis is the quickest way to get started with Google cloud logging without importing the library in every file that you do log from.\nThis is the recommended path for a pre-existing code base without the intention to use claims in logs.\n\nAll logs will have the default level.\n\nThis achieved by providing the following writer interfaces:\n- **`github.com/alt4dev/gcloud/service.Writer`** This writer receives a log message and writes it Google cloud logging.\n\nThe example below demonstrates this:\n```go\npackage main\nimport (\n    alt4Service \"github.com/alt4dev/gcloud/service\"\n    \"log\"\n)\n\nfunc main() {\n    // Set default logger to use Google cloud logging\n    log.SetOutput(alt4Service.Writer)\n    log.Println(\"This writes to Google cloud logging\")\n    \n    // Set a custom logger to use Google cloud logging\n    logger := log.New(alt4Service.Writer, \"[my custom logger]\", 0)\n    logger.Println(\"This writes Google cloud logging\")\n}\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falt4dev%2Fgcloud","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falt4dev%2Fgcloud","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falt4dev%2Fgcloud/lists"}