{"id":19510000,"url":"https://github.com/permify/sloggcp","last_synced_at":"2026-02-25T22:03:48.970Z","repository":{"id":260112975,"uuid":"880292792","full_name":"Permify/sloggcp","owner":"Permify","description":"A log/slog handler for Google Cloud Logging, enabling seamless integration with Google Cloud's logging infrastructure","archived":false,"fork":false,"pushed_at":"2024-10-29T17:40:30.000Z","size":22,"stargazers_count":2,"open_issues_count":1,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-04-26T03:44:27.509Z","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":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Permify.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,"zenodo":null}},"created_at":"2024-10-29T13:19:31.000Z","updated_at":"2024-10-29T17:40:34.000Z","dependencies_parsed_at":"2025-04-26T03:42:28.905Z","dependency_job_id":null,"html_url":"https://github.com/Permify/sloggcp","commit_stats":null,"previous_names":["permify/sloggcp"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/Permify/sloggcp","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Permify%2Fsloggcp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Permify%2Fsloggcp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Permify%2Fsloggcp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Permify%2Fsloggcp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Permify","download_url":"https://codeload.github.com/Permify/sloggcp/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Permify%2Fsloggcp/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29842855,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-25T21:18:31.832Z","status":"ssl_error","status_checked_at":"2026-02-25T21:18:29.265Z","response_time":61,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: 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":"2024-11-10T23:14:08.730Z","updated_at":"2026-02-25T22:03:48.953Z","avatar_url":"https://github.com/Permify.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# sloggcp\n\nA `log/slog` handler for Google Cloud Logging, enabling seamless integration with Google Cloud's logging infrastructure.\n\n## Quick Start\n\n### Installation\n\nEnsure you have the Google Cloud SDK installed and authenticated. Then, add `sloggcp` and necessary dependencies:\n\n```bash\ngo get github.com/Permify/sloggcp\n```\n\n### Usage\nBelow is a minimal example of configuring and using sloggcp to send logs to Google Cloud Logging.\n\n```go\npackage main\n\nimport (\n\t\"context\"\n\t\"fmt\"\n\t\"log/slog\"\n\t\"os\"\n\n\t\"github.com/Permify/sloggcp\"\n\t\"github.com/joho/godotenv\"\n)\n\nfunc main() {\n\t// Load environment variables from .env file\n\tif err := godotenv.Load(); err != nil {\n\t\tfmt.Printf(\"Error loading .env file: %v\\n\", err)\n\t\tos.Exit(1)\n\t}\n\n\t// Set up context and Google Cloud project ID\n\tctx := context.Background()\n\tprojectID := os.Getenv(\"GOOGLE_CLOUD_PROJECT\")\n\tif projectID == \"\" {\n\t\tfmt.Println(\"GOOGLE_CLOUD_PROJECT environment variable is not set\")\n\t\tos.Exit(1)\n\t}\n\tlogName := \"my-application-log\"\n\n\t// Create a new GoogleCloudSlogHandler\n\thandler, err := sloggcp.NewGoogleCloudSlogHandler(ctx, projectID, logName, \u0026slog.HandlerOptions{\n\t\tLevel: slog.LevelInfo,\n\t})\n\tif err != nil {\n\t\tfmt.Printf(\"Failed to create Google Cloud slog handler: %v\\n\", err)\n\t\tos.Exit(1)\n\t}\n\tdefer handler.Close()\n\n\t// Set up the slog logger with the Google Cloud handler\n\tlogger := slog.New(handler)\n\tslog.SetDefault(logger)\n\n\t// Log messages at different levels\n\tslog.Info(\"Application started\", \"version\", \"1.0\")\n\tslog.Debug(\"Debugging info\", \"module\", \"auth\")\n\tslog.Warn(\"Potential issue detected\", \"component\", \"database\")\n\tslog.Error(\"An error occurred\", \"error\", \"database connection failed\")\n\n\t// Optional: Close the handler when done to ensure logs are flushed\n\tif err := handler.Close(); err != nil {\n\t\tfmt.Printf(\"Failed to close the Google Cloud slog handler: %v\\n\", err)\n\t}\n}\n```\n### Explanation\n\n- Project ID and Log Name: Set projectID and logName to your Google Cloud Project ID and desired log name.\n- slog Handler: GoogleCloudSlogHandler sends logs directly to Google Cloud, handling attributes and severity levels automatically.\n- Logging Levels: Log messages can be sent with various levels (Info, Debug, Warn, Error), automatically converting to the corresponding Google Cloud severity level.\n\n### Environment Setup\n\nMake sure the environment running this code has the necessary permissions to write to Google Cloud Logging. You can achieve this by:\n\n1. Setting up authentication with a service account key.\n2. Configuring the GOOGLE_APPLICATION_CREDENTIALS environment variable to point to the key file.\n\n```bash\nexport GOOGLE_APPLICATION_CREDENTIALS=\"/path/to/your/service-account-key.json\"\n```\n\n### Testing Logs\nAfter running the example, go to Google Cloud Logging and check for entries under the specified log name (my-application-log).\n```bash\ngo test -v\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpermify%2Fsloggcp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpermify%2Fsloggcp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpermify%2Fsloggcp/lists"}