{"id":13830310,"url":"https://github.com/smallnest/slog-clickhouse","last_synced_at":"2026-02-28T16:32:22.291Z","repository":{"id":226924806,"uuid":"769962928","full_name":"smallnest/slog-clickhouse","owner":"smallnest","description":"slog: clickhouse handler","archived":false,"fork":false,"pushed_at":"2024-03-11T10:59:45.000Z","size":74,"stargazers_count":3,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-07-06T14:02:45.453Z","etag":null,"topics":["clickhouse","go","golang","handler","log","logger","slog"],"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/smallnest.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-03-10T14:53:30.000Z","updated_at":"2025-02-24T17:46:50.000Z","dependencies_parsed_at":"2024-03-11T23:34:26.840Z","dependency_job_id":null,"html_url":"https://github.com/smallnest/slog-clickhouse","commit_stats":null,"previous_names":["smallnest/slog-clickhouse"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/smallnest/slog-clickhouse","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/smallnest%2Fslog-clickhouse","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/smallnest%2Fslog-clickhouse/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/smallnest%2Fslog-clickhouse/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/smallnest%2Fslog-clickhouse/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/smallnest","download_url":"https://codeload.github.com/smallnest/slog-clickhouse/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/smallnest%2Fslog-clickhouse/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29942856,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-28T13:49:17.081Z","status":"ssl_error","status_checked_at":"2026-02-28T13:48:50.396Z","response_time":90,"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":["clickhouse","go","golang","handler","log","logger","slog"],"created_at":"2024-08-04T10:00:58.538Z","updated_at":"2026-02-28T16:32:22.268Z","avatar_url":"https://github.com/smallnest.png","language":"Go","funding_links":[],"categories":["Log forwarding"],"sub_categories":[],"readme":"# slog-clickhouse\nA ClickHouse Handler for slog Go library.\n\n![GitHub](https://img.shields.io/github/license/smallnest/slog-clickhouse) ![GitHub Action](https://github.com/smallnest/slog-clickhouse/actions/workflows/action.yaml/badge.svg) [![Go Report Card](https://goreportcard.com/badge/github.com/smallnest/slog-clickhouse)](https://goreportcard.com/report/github.com/smallnest/slog-clickhouse)  [![GoDoc](https://godoc.org/github.com/smallnest/slog-clickhouse?status.png)](http://godoc.org/github.com/smallnest/slog-clickhouse)  \n\n**See also:**\n\n- [slog-multi](https://github.com/samber/slog-multi): `slog.Handler` chaining, fanout, routing, failover, load balancing...\n- [slog-formatter](https://github.com/samber/slog-formatter): `slog` attribute formatting\n- [slog-sampling](https://github.com/samber/slog-sampling): `slog` sampling policy\n- [slog-gin](https://github.com/samber/slog-gin): Gin middleware for `slog` logger\n- [slog-echo](https://github.com/samber/slog-echo): Echo middleware for `slog` logger\n- [slog-fiber](https://github.com/samber/slog-fiber): Fiber middleware for `slog` logger\n- [slog-chi](https://github.com/samber/slog-chi): Chi middleware for `slog` logger\n- [slog-datadog](https://github.com/samber/slog-datadog): A `slog` handler for `Datadog`\n- [slog-rollbar](https://github.com/samber/slog-rollbar): A `slog` handler for `Rollbar`\n- [slog-sentry](https://github.com/samber/slog-sentry): A `slog` handler for `Sentry`\n- [slog-syslog](https://github.com/samber/slog-syslog): A `slog` handler for `Syslog`\n- [slog-logstash](https://github.com/samber/slog-logstash): A `slog` handler for `Logstash`\n- [slog-fluentd](https://github.com/samber/slog-fluentd): A `slog` handler for `Fluentd`\n- [slog-graylog](https://github.com/samber/slog-graylog): A `slog` handler for `Graylog`\n- [slog-loki](https://github.com/samber/slog-loki): A `slog` handler for `Loki`\n- [slog-slack](https://github.com/samber/slog-slack): A `slog` handler for `Slack`\n- [slog-telegram](https://github.com/samber/slog-telegram): A `slog` handler for `Telegram`\n- [slog-mattermost](https://github.com/samber/slog-mattermost): A `slog` handler for `Mattermost`\n- [slog-microsoft-teams](https://github.com/samber/slog-microsoft-teams): A `slog` handler for `Microsoft Teams`\n- [slog-webhook](https://github.com/samber/slog-webhook): A `slog` handler for `Webhook`\n- [slog-kafka](https://github.com/samber/slog-kafka): A `slog` handler for `Kafka`\n- [slog-nats](https://github.com/samber/slog-nats): A `slog` handler for `NATS`\n- [slog-parquet](https://github.com/samber/slog-parquet): A `slog` handler for `Parquet` + `Object Storage`\n- [slog-zap](https://github.com/samber/slog-zap): A `slog` handler for `Zap`\n- [slog-zerolog](https://github.com/samber/slog-zerolog): A `slog` handler for `Zerolog`\n- [slog-logrus](https://github.com/samber/slog-logrus): A `slog` handler for `Logrus`\n- [slog-channel](https://github.com/samber/slog-channel): A `slog` handler for Go channels\n\n## Installation\n\n```bash\ngo get github.com/smllnest/slog-clickhouse\n```\n\n**Compatibility**: `go \u003e= 1.21`\n\n## Usage\n\n### Handler options\n\n```go\ntype Option struct {\n\t// log level (default: debug)\n\tLevel slog.Leveler\n\n\t// ClickHouse connection\n\tDB       *sql.DB\n\tLogTable string\n\tTimeout  time.Duration // default: 60s\n\n\t// optional: customize clickhouse event builder\n\tConverter Converter\n\n\t// optional: see slog.HandlerOptions\n\tAddSource   bool\n\tReplaceAttr func(groups []string, a slog.Attr) slog.Attr\n}\n```\n\nOther global parameters:\n```go\nslogclickhouse.SourceKey = \"source\"\nslogclickhouse.ContextKey = \"extra\"\nslogclickhouse.RequestKey = \"request\"\nslogclickhouse.ErrorKeys = []string{\"error\", \"err\"}\nslogclickhouse.RequestIgnoreHeaders = false\n```\n\n### Supported attributes\nThe following attributes are interpreted by slogclickhouse.DefaultConverter:\n\n|Atribute name|\tslog.Kind|\tUnderlying type|\n|---|---|---|\n|\"error\"|\tany|\terror|\n|\"request\"|\tany|\t*http.Request|\n|other attributes\t|*\t||\n\n\nOther attributes will be injected in extra field.\n\n### Example\n\n\nYou must create the table before using it:\n```sh\nCREATE TABLE logs (\n   timestamp DateTime,\n   level String,\n   message String,\n   attrs String\n) ENGINE = MergeTree()\nORDER BY timestamp\nPARTITION BY toYYYYMMDD(timestamp)\n```\n\nthen run the below code:\n\n```go\npackage main\n\nimport (\n\t\"log/slog\"\n\t\"testing\"\n\t\"time\"\n\n\t\"github.com/smallnest/slog-clickhouse\"\n)\n\nfunc main() {\n\tconn := clickhouse.OpenDB(\u0026clickhouse.Options{\n\t\tAddr: []string{\"127.0.0.1:9000\"},\n\t\tAuth: clickhouse.Auth{\n\t\t\tDatabase: \"myapp\",\n\t\t\tUsername: \"\",\n\t\t\tPassword: \"\",\n\t\t},\n\t\tSettings: clickhouse.Settings{\n\t\t\t\"max_execution_time\": 60,\n\t\t},\n\t\tDialTimeout:          time.Second * 30,\n\t\tDebug:                true,\n\t\tBlockBufferSize:      10,\n\t\tMaxCompressionBuffer: 10240,\n\t})\n\n\tif err := conn.Ping(); err != nil {\n\t\tt.Log(\"local clickhouse server is not running, skipping test...\")\n\t\treturn\n\t}\n\n\tconn.SetMaxIdleConns(5)\n\tconn.SetMaxOpenConns(10)\n\tconn.SetConnMaxLifetime(time.Hour)\n\n\tlogger := slog.New(Option{Level: slog.LevelDebug, DB: conn, LogTable: \"myapp.logs\"}.NewClickHouseHandler())\n\n\tlogger.Info(\"Hello, ClickHouse!\", \"key1\", \"value1\", \"key2\", 2)\n}\n```\n\ncheck the result in ClickHouse:\n\n![](doc/clickhouse.png)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsmallnest%2Fslog-clickhouse","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsmallnest%2Fslog-clickhouse","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsmallnest%2Fslog-clickhouse/lists"}