{"id":16966216,"url":"https://github.com/scottlepp/loki-logger","last_synced_at":"2026-05-11T16:04:47.300Z","repository":{"id":64346029,"uuid":"575122678","full_name":"scottlepp/loki-logger","owner":"scottlepp","description":"A go based logger for Loki with ZeroLog adapter","archived":false,"fork":false,"pushed_at":"2022-12-09T17:28:56.000Z","size":40,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-01-26T12:28:26.144Z","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":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/scottlepp.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-12-06T20:05:05.000Z","updated_at":"2024-01-30T15:29:11.000Z","dependencies_parsed_at":"2023-01-15T13:01:20.266Z","dependency_job_id":null,"html_url":"https://github.com/scottlepp/loki-logger","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scottlepp%2Floki-logger","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scottlepp%2Floki-logger/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scottlepp%2Floki-logger/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scottlepp%2Floki-logger/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/scottlepp","download_url":"https://codeload.github.com/scottlepp/loki-logger/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244840936,"owners_count":20519306,"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":[],"created_at":"2024-10-14T00:05:03.328Z","updated_at":"2026-05-11T16:04:42.220Z","avatar_url":"https://github.com/scottlepp.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# loki-logger\nA go based logger for Loki with [ZeroLog](https://github.com/rs/zerolog) adapter.\n\n![logging-evolved](https://user-images.githubusercontent.com/6108819/206758962-22c9f687-fa6e-4795-b45e-b4c6b91feea2.png)\n\n## Usage with Grafana backend plugins.\n\nStep 1.  Setup a [Free Grafana Cloud Account with Loki/Logging](https://grafana.com/logs/)\n\nStep 2.  Add settings to a plugin in your grafana.ini\n```\n[plugin.my-plugin-id]\n# the logger to use:  console, file, loki\nlogger = loki\n# the log level to capture\nlogger_level = 0\nlogger_url = https://logs-prod3.grafana.net/loki/api/v1/push\n# logger_key is base64 encoded\nlogger_key = user:apikey\n# size of buffer lines to keep in memory\nlogger_buffer = 5 \n# comma delimited list of labels to apply to the log message\nlogger_labels = plugin:dynatrace\n# log all http requests from the plugin to external rest apis\nlogger_http = true\n```\n\nStep 3.  Go get \"github.com/scottlepp/loki-logger/pkg/log\"\n\nStep 4.  Add logging to your code. These will be sent to loki if your logger_level (above) is low enough.\n```\nlog.Debug(\"foo\")\n```\n\nStep 5. (optional) Log all incoming requests to the plugin\n\nTypically when setting up your plugin you supply handlers for query, health, resources like so:\n```\n\tim := datasource.NewInstanceManager(getInstance)\n\thandler := \u0026Plugin{\n\t\tIM: im,\n\t}\n\trouter := host.getCallResourceHandler()\n\treturn datasource.ServeOpts{\n\t\tQueryDataHandler:    handler,\n\t\tCheckHealthHandler:  handler,\n\t\tCallResourceHandler: httpadapter.New(router),\n\t}\n```\nJust wrap the plugin that handles the calls:\n```\n\tim := datasource.NewInstanceManager(getInstance)\n\thandler := \u0026Plugin{\n\t\tIM: im,\n\t}\n\tlogHandler := log.Handler{\n\t\tPlugin: handler,\n\t}\n\trouter := host.getCallResourceHandler()\n\treturn datasource.ServeOpts{\n\t\tQueryDataHandler:    logHandler,\n\t\tCheckHealthHandler:  logHandler,\n\t\tCallResourceHandler: httpadapter.New(router),\n\t}\n```\n\nStep 6. (optional) Log all http calls to external rest apis.\nWhen creating your http client, wrap the transport \n```\nc.Transport = log.NewHTTPLogger(\"my-plugin-id\", c.Transport)\n```\n\n## Usage with [ZeroLog](https://github.com/rs/zerolog)\n\n```\nloki := \u0026lokiLogger{\n\tURL:        \"https://logs-prod3.grafana.net/loki/api/v1/push\",\n\tKey:        \"user:key\", // base64 encoded\n\tBufferSize: 50,\n\tLevel:      0,\n\tLabels:     \"label1:1,label2:2\"\n}\n  \nzl := zerolog.New(loki).Level(zerolog.Level(loki.Level))\nzl.Debug(\"foo\")\n```\n\n## Standalone\n```\nlogger := \u0026lokiLogger{\n\tURL:        \"https://logs-prod3.grafana.net/loki/api/v1/push\",\n\tKey:        \"user:key\", // base64 encoded\n\tBufferSize: 50,\n\tLevel:      0,\n\tLabels:     \"label1:1,label2:2\"\n}\nlogger.Write([]byte(\"foo\"))\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fscottlepp%2Floki-logger","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fscottlepp%2Floki-logger","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fscottlepp%2Floki-logger/lists"}