{"id":17355136,"url":"https://github.com/zephinzer/logrusfluenthook","last_synced_at":"2025-03-27T14:17:01.663Z","repository":{"id":79926666,"uuid":"189765416","full_name":"zephinzer/logrusfluenthook","owner":"zephinzer","description":"A logrus hook for streaming logs to a FluentD service","archived":false,"fork":false,"pushed_at":"2019-06-09T15:10:56.000Z","size":1974,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-01T18:26:48.325Z","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/zephinzer.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":"2019-06-01T18:26:57.000Z","updated_at":"2019-06-09T15:10:58.000Z","dependencies_parsed_at":null,"dependency_job_id":"755ce242-a65a-41f3-8f41-bf6a68c2677e","html_url":"https://github.com/zephinzer/logrusfluenthook","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/zephinzer%2Flogrusfluenthook","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zephinzer%2Flogrusfluenthook/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zephinzer%2Flogrusfluenthook/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zephinzer%2Flogrusfluenthook/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zephinzer","download_url":"https://codeload.github.com/zephinzer/logrusfluenthook/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245858880,"owners_count":20684062,"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-15T17:42:27.071Z","updated_at":"2025-03-27T14:17:01.637Z","avatar_url":"https://github.com/zephinzer.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Logrus Fluent Hook\nThis library exports a Logrus hook which enables streaming logs to FluentD when added to a Logrus instance.\n\n[![Build Status](https://travis-ci.org/zephinzer/logrusfluenthook.svg?branch=master)](https://travis-ci.org/zephinzer/logrusfluenthook)\n\n# Example Usage\n\n\u003e A full working application that uses this library can be found in [`./cmd/example/main.go`](./cmd/example/main.go).\n\n## Importing\n\n```go\npackage main\n\nimport (\n\t// ...\n  logrusfluenthook \"github.com/zephinzer/logrusfluenthook/hook\"\n  // ...\n)\n```\n\n## Configuring the Hook\n\n```go\nhookConfig := logrusfluenthook.Config{\n\t\tHost:    \"127.0.0.1\",\n\t\tPort:    24224,\n\t\tBaseTag: \"myapplication\",\n\t\tLevels: []string{\n\t\t\t\"trace\",\n\t\t\t\"debug\",\n\t\t\t\"info\",\n\t\t\t\"warn\",\n\t\t\t\"error\",\n\t\t\t\"fatal\",\n\t\t\t\"panic\",\n\t\t},\n\t\tFieldMap: map[string]string{\n\t\t\tlogrus.FieldKeyTime: \"@timestamp\",\n\t\t\tlogrus.FieldKeyMsg:   \"@msg\",\n\t\t\tlogrusfluenthook.FieldKeyData:      \"@data\",\n\t\t\tlogrus.FieldKeyLevel:     \"@level\",\n\t\t\tlogrus.FieldKeyFile:      \"@file\",\n\t\t\tlogrus.FieldKeyFunc:      \"@func\",\n\t\t},\n\t\tTimestampFormat: time.RFC3339,\n\t}\n```\n\n## Adding the Hook\n\n```go\n\tlogger := logrus.New()\n\t// the setting of formatter is necessary if you'd like\n\t// to have the same logs in stdout and in fluentd, if\n\t// that doesn't matter, you can ignore this next code block\n\tlogger.SetFormatter(\u0026logrus.JSONFormatter{\n\t\tDataKey: \"@data\",\n\t\tFieldMap: logrus.FieldMap{\n\t\t\tlogrus.FieldKeyTime:  \"@timestamp\",\n\t\t\tlogrus.FieldKeyFile:  \"@file\",\n\t\t\tlogrus.FieldKeyFunc:  \"@func\",\n\t\t\tlogrus.FieldKeyLevel: \"@level\",\n\t\t\tlogrus.FieldKeyMsg:   \"@msg\",\n\t\t},\n\t})\n\t// ... other customisations of logger ...\n\thook, err := logrusfluenthook.New(\u0026hookConfig)\n  if err != nil {\n\t\tlogger.Panic(err)\n\t} else {\n\t\t// note that the fluentd service has to be up and reachable\n\t\t// by your application at this point in time, write your\n\t\t// own retry/error handler\n\t\tlogger.AddHook(hook)\n\t}\n```\n\n## Using the Hook\n\n### Basic\n\n```go\n// ...\nlogrus.Info(\"hello from stdout (to fluentd)\")\n```\n\n#### Example FluentD Output\n\n```\n2019-06-09 14:56:57.683867999 +0000 base_tag.info: {\"@timestamp\":\"2019-06-09T22:56:57+08:00\",\"@msg\":\"hello from stdout (to fluentd)\",\"@data\":{},\"@level\":\"info\"}\n```\n\n### With Fields\n\n```go\n// ...\nlogrus.WithFields(logrus.Fields{\n  \"this_is\": \"an example of additional data attachments\",\n  \"tag\":     \"customise-me\",\n}).Info(\"hello from stdout (to fluentd)\")\n```\n\n#### Example FluentD Output\n\n```\n2019-06-09 14:56:57.685854295 +0000 base_tag.customise-me: {\"@timestamp\":\"2019-06-09T22:56:57+08:00\",\"@msg\":\"hello from stdout (to fluentd)\",\"@data\":{\"this_is\":\"an example of additional data attachments\",\"tag\":\"customise-me\"},\"@level\":\"info\"}\n```\n\n### With Caller Reporting\n\n```go\n// ...\nlogrus.SetReportCaller(true)\nlogrus.WithFields(logrus.Fields{\n  \"this_is\": \"an example of adding caller information\",\n  \"tag\":     \"with-caller-info\",\n}).Debug(\"hello from stdout (to fluentd)\")\n```\n\n#### Example FluentD Output\n\n```\n2019-06-09 14:56:57.687134165 +0000 base_tag.with-caller-info: {\"@msg\":\"hello from stdout (to fluentd)\",\"@data\":{\"this_is\":\"an example of adding caller information\",\"tag\":\"with-caller-info\"},\"@level\":\"debug\",\"@file\":\"/\u003cREDACTED\u003e/logrusfluenthook/cmd/example/main.go:59\",\"@func\":\"main.main\",\"@timestamp\":\"2019-06-09T22:56:57+08:00\"}\n```\n\n# Development\n\n## Start the FluentD Service\nRun `make setup`. This should use Docker Compose to spin up a FluentD service with its ports exposed to your local machine at `127.0.0.1:24224`.\n\nTo stop it, use `make teardown`.\n\n## Start Developing\nThe code is in [`./hook`](./hook) and the example application is at [`./cmd`](./cmd). To check if the example works, you can run `make run_example` from the root directory.\n\n## Testing\n\nTests can be run using `make run_tests` from the project root directory.\n\nNote that the tests include an integration test which can be found in the [`./test](./test) directory which requires Docker to run (it spins up its own FluentD instance and compares the output/streamed logs).\n\n# Licensing\nThis repository and the code within is licensed under the MIT license. See [LICENSE](./LICENSE) for the full text.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzephinzer%2Flogrusfluenthook","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzephinzer%2Flogrusfluenthook","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzephinzer%2Flogrusfluenthook/lists"}