{"id":24308908,"url":"https://github.com/nicus101/slog-elastic","last_synced_at":"2026-04-29T01:05:26.195Z","repository":{"id":271452863,"uuid":"911987660","full_name":"nicus101/slog-elastic","owner":"nicus101","description":"slog to elastic handler","archived":false,"fork":false,"pushed_at":"2025-05-23T12:38:41.000Z","size":41,"stargazers_count":1,"open_issues_count":1,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-05-31T22:37:35.245Z","etag":null,"topics":["elasticsearch","golang-package","slog"],"latest_commit_sha":null,"homepage":"","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/nicus101.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":"2025-01-04T11:47:14.000Z","updated_at":"2025-05-13T21:34:32.000Z","dependencies_parsed_at":"2025-03-27T13:29:27.854Z","dependency_job_id":"8f1fb233-6aee-4436-9c9d-26f170947a96","html_url":"https://github.com/nicus101/slog-elastic","commit_stats":null,"previous_names":["nicus101/slog-elastic"],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/nicus101/slog-elastic","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nicus101%2Fslog-elastic","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nicus101%2Fslog-elastic/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nicus101%2Fslog-elastic/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nicus101%2Fslog-elastic/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nicus101","download_url":"https://codeload.github.com/nicus101/slog-elastic/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nicus101%2Fslog-elastic/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32405905,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-28T19:38:08.556Z","status":"ssl_error","status_checked_at":"2026-04-28T19:37:55.688Z","response_time":56,"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":["elasticsearch","golang-package","slog"],"created_at":"2025-01-17T05:11:54.315Z","updated_at":"2026-04-29T01:05:26.163Z","avatar_url":"https://github.com/nicus101.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"![Go Report Card](https://goreportcard.com/badge/nicus101/slog-elastic)\n[![GoDoc](https://godoc.org/github.com/nicus101/slog-elastic?status.svg)](https://pkg.go.dev/github.com/nicus101/slog-elastic)\n[![Coverage](https://img.shields.io/codecov/c/github/nicus101/slog-elastic)](https://codecov.io/gh/nicus101/slog-elastic)\n[![License](https://img.shields.io/github/license/nicus101/slog-elastic)](./LICENSE)\n\n# Slog-Elastic - implementation of slog.Handler for elasticsearch\n\nGolang have structural logging for some time,\nnamed [slog](https://pkg.go.dev/log/slog).\nIt even has rich and\n[Awesome Slog](https://github.com/go-slog/awesome-slog)\necosystem.\nThis package is very young, your feedback is welcome.\n\n## Why?\n\nWhy use *ElasticSearch* directly?\nThere is [Logstash](https://www.elastic.co/logstash) after all.\nBut sometimes You...\n\n - Develop locally, and still want persistency.\n - Have IoT solution, and don't want big guns.\n - Didn't get access to logstash from Your operations department.\n\nThis package was made to solve the above.\nHaving somewhat decent implementation would be better than\ncobbling ad-hoc solutions in every project.\n\n## Features\n\n - Implements slog.Handler\n - Extracts values from *Context* using ContextAttrFunc\n - Utility function to connect database\n - Utility function to load `ES_LOG_xx` from .env or environment.\n - Works with [zinc](https://zincsearch.com/)\n - Works with [elasticsearch](https://www.elastic.co/elasticsearch/)\n - Ability  to overwrite error handler\n\n## Usage\n\n```go\n// initialize by config\nslogEsCfg := slogelastic.Config{\n\tAddress:  \"https://example.com\",\n\tIndex:    \"some-log-index\",\n\tUser:     \"john\",\n\tPass:     \"secret\",\n\tMinLevel: slog.LevelDebug,\n}\n\n// load from .env or enviroment ES_LOG_xxx\nerr := slogEsCfg.LoadFromEnv()\nif err != nil {\n\tlog.Fatal(err)\n}\n\n// connecting to ElasticSearch and selecting index\nerr = slogEsCfg.ConnectEsLog()\nif err != nil {\n\tlog.Fatal(err)\n}\n\n// or use arleady established connection\nslogEsCfg.ESIndex = slogelastic.AlreadyConnected()\n\n// finalize configuration and build slog.Handler\nesHandler := slogEsCfg.NewElasticHandler()\n\n// To see output in terminal, we recomend slogmulti.Fanout from Samber\nslog.SetDefault(slog.New(esHandler))\n\n// now we can use persistent logging in rest of application\nslog.Info(\"Registered banana\", \"bannanaId\", 42)\nslog.Warn(\"Invalid monkeyId\", \"monkeyId\", \"mojo\")\nslog.Error(\"BannanaDB connection failed\", \"error\", \"unknown protocol banana://\")\n```\n\n## Planned features and to-do\n\n - Ability for client code to filter/rename attributes.\n - Safeguard to propagate all logs before application shutdown.\n - Bulk inserts asynchronously.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnicus101%2Fslog-elastic","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnicus101%2Fslog-elastic","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnicus101%2Fslog-elastic/lists"}