{"id":13413324,"url":"https://github.com/echocat/slf4g","last_synced_at":"2026-02-03T16:15:35.943Z","repository":{"id":57543631,"uuid":"295325718","full_name":"echocat/slf4g","owner":"echocat","description":"Simple Logging Facade for Golang","archived":false,"fork":false,"pushed_at":"2024-09-10T20:39:52.000Z","size":435,"stargazers_count":3,"open_issues_count":0,"forks_count":1,"subscribers_count":4,"default_branch":"main","last_synced_at":"2024-09-11T00:10:07.404Z","etag":null,"topics":["golang","logging","simple","slf4g","slf4j"],"latest_commit_sha":null,"homepage":"https://pkg.go.dev/github.com/echocat/slf4g","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/echocat.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":"2020-09-14T06:35:23.000Z","updated_at":"2024-09-10T20:39:54.000Z","dependencies_parsed_at":"2023-11-29T09:30:53.915Z","dependency_job_id":"90e695c6-47fd-41b4-8cf0-ab7125a90d84","html_url":"https://github.com/echocat/slf4g","commit_stats":null,"previous_names":[],"tags_count":85,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/echocat%2Fslf4g","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/echocat%2Fslf4g/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/echocat%2Fslf4g/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/echocat%2Fslf4g/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/echocat","download_url":"https://codeload.github.com/echocat/slf4g/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248564977,"owners_count":21125412,"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":["golang","logging","simple","slf4g","slf4j"],"created_at":"2024-07-30T20:01:37.744Z","updated_at":"2026-01-06T19:12:53.487Z","avatar_url":"https://github.com/echocat.png","language":"Go","funding_links":[],"categories":["日志记录","Logging"],"sub_categories":["检索及分析资料库","Search and Analytic Databases","Advanced Console UIs"],"readme":"[![PkgGoDev](https://pkg.go.dev/badge/github.com/echocat/slf4g)](https://pkg.go.dev/github.com/echocat/slf4g)\n[![Continuous Integration](https://github.com/echocat/slf4g/workflows/Continuous%20Integration/badge.svg)](https://github.com/echocat/slf4g/actions?query=workflow%3A%22Continuous+Integration%22)\n[![Coverage Status](https://coveralls.io/repos/github/echocat/slf4g/badge.svg?branch=main)](https://coveralls.io/github/echocat/slf4g?branch=main)\n[![Go Report Card](https://goreportcard.com/badge/github.com/echocat/slf4g)](https://goreportcard.com/report/github.com/echocat/slf4g)\n\n# Simple Log Framework for Golang (slf4g)\n\n## TOC\n\n* [Principles](#principles)\n* [Motivation](#motivation)\n* [Getting started](#getting-started)\n* [Implementations](#implementations)\n* [Bridges](#bridges) (and their [hooks](#hooks))\n* [Contributing](#contributing)\n* [License](#license)\n\n## Principles\n\n### KISS for users\n\nIf you want to log something it should be easy, intuitive and straight forward. This should work either for very small applications (just one file) or big applications, too.\n\nYou should not care about the implementation, you want just to use it.\n\n### KISS for implementators\n\nIf you want to implement a new logger you should not be required to educate your users how to use it.\n\nYou just want to write a logger for a user-case. Someone else should take care of the public API.\n\n### Separation\n\nA logging framework should not be both, by design: API and implementation.\n\nYou want to have one API and the possibility to use whatever implementation you want.\n\n### Interoperable\n\nRegardless how used or implemented you want that just everything sticks together, and you're not ending up over and over again in writing new wrappers or in worst-case see different styled log messages in the console.\n\nEvery library should just work transparently with one logger.\n\n## Motivation\n\nI've tried out many logging frameworks for Golang. They're coming with different promises, like:\n\n1. There are ones which tries to be \"blazing fast\"; focussing on be fast and non-blocking to be able to log as much log events as possible.\n\n2. Other ones are trying to be as minimalistic as possible. Just using a very few amount of code to work.\n\n3. ...\n\n...but overall they're just violating the [Principles listed above](#principles) and we're ending up in just mess.\n\nSlf4g is born out of feeling this pain every day again and be simply annoyed. It is inspired by [Simple Logging Facade for Java (SLF4J)](http://www.slf4j.org/), which was born out of the same pains; but obviously in Java before. Since [SLF4J](http://www.slf4j.org/) exists, and it is now broadly used in Java, nobody does experience this issues any longer.\n\n## Getting started\n\nIt is very easy to use slf4g (as the naming is promising ☺️):\n\n1. Import the API to your current project (in best with a [Go Modules project](https://blog.golang.org/using-go-modules))\n    ```bash\n    $ go get -u github.com/echocat/slf4g\n    ```\n\n2. Select one of the implementation of [slf4g](https://github.com/echocat/slf4g) and import it too (see [Implementations](#implementations)). Example:\n\n    ```bash\n    $ go get -u github.com/echocat/slf4g/native\n    ```\n\n   \u003e ℹ️ If you do not pick one implementation the fallback logger is used. It works, too, but is obviously less powerful and is not customizable. It is comparable with the [SDK based logger](https://pkg.go.dev/log).\n\n3. Configure your application to use the selected logger implementation:\n\n   This should be only done in `main/main.go`:\n\n    ```go\n    package main\n   \n    import (\n    \t_ \"github.com/echocat/slf4g/native\"\n    )\n   \n    func main() {\n    \t// do your stuff...\n    }\n    ```\n\n4. In each package create a logger variable, in best case you create a file named `common.go` or `package.go` which will contain it:\n\n    ```go\n    package foo\n   \n    import (\n    \t\"github.com/echocat/slf4g\"\n    )\n   \n    var logger = log.GetLoggerForCurrentPackage()\n    ```\n\n5. Now you're ready to go. In every file of this package you can do stuff, like:\n\n    ```go\n    package foo\n   \n    func MyFunction() {\n    \tlogger.Info(\"Hello, world!\")\n\n    \tif !loaded {\n    \t\tlogger.With(\"field\", 123).\n    \t\t       Warn(\"That's not great.\")\n    \t}\n\n    \tif err := doSomething(); err != nil {\n    \t\tlogger.WithError(err).\n    \t\t       Error(\"Doh!\")\n    \t}\n    }\n    ```\n\n   For sure, you're able to simply do stuff like that (although to ensure interoperability this is not recommended):\n\n    ```go\n    package foo\n    \n    import (\n    \t\"github.com/echocat/slf4g\"\n    )\n    \n    func MyFunction() {\n    \tlog.Info(\"Hello, world!\")\n    \n    \tif !loaded {\n    \t\tlog.With(\"field\", 123).\n    \t\t    Warn(\"That's not great.\")\n    \t}\n\n    \tif err := doSomething(); err != nil {\n    \t\tlog.WithError(err).\n    \t\t    Error(\"Doh!\")\n    \t}\n    }\n    ```\n\nDone. Enjoy!\n\n## Implementations\n\n1. [native](native): Reference implementation of [slf4g](https://github.com/echocat/slf4g), best use for most applications.\n\n2. [testlog](sdk/testlog): Ensure that everything which is logged within test by [slf4g](https://github.com/echocat/slf4g) appears correctly within tests.\n\n3. [recording](testing/recording): Will record everything which is logged by [slf4g](https://github.com/echocat/slf4g) and can then be asserted inside test cases.\n\n## Bridges\n\nThere are several bridges available to use [slf4g](https://github.com/echocat/slf4g) in other frameworks:\n\n1. [sdk/bridge](sdk/bridge) to implement the [Go's SDK log interface](https://pkg.go.dev/log).\n2. [sdk/bridge/slog](sdk/bridge/slog) to implement the [Go's SDK slog interface](https://pkg.go.dev/log/slog).\n3. [github.com/echocat/slf4g-logr](https://github.com/echocat/slf4g-logr) to implement [github.com/go-logr/logr](https://github.com/go-logr/logr).\n4. [github.com/echocat/slf4g-logrus](https://github.com/echocat/slf4g-logrus) to implement [github.com/sirupsen/logrus](https://github.com/sirupsen/logrus).\n5. [github.com/echocat/slf4g-klog](https://github.com/echocat/slf4g-klog) to implement [k8s.io/klog/v2](https://github.com/kubernetes/klog).\n\n### Hooks\n\nThese are automatically registering itself by simply calling an anonymous import (instead of explicitly importing - see [Bridges](#bridges) above), like:\n\n```go\npackage main\n\nimport (\n\t// For hook into SDK's log package\n\t_ \"github.com/echocat/slf4g/hooks/sdklog\"\n\n\t// For hook into SDK's log/slog package\n\t_ \"github.com/echocat/slf4g/hooks/sdkslog\"\n\n\t// For hook into github.com/sirupsen/logrus\n\t_ \"github.com/echocat/slf4g-logrus/logrus2slf4g/hook\"\n\n\t// For hook into Kubernetes' k8s.io/klog/v2\n\t_ \"github.com/echocat/slf4g-klog/bridge/hook\"\n)\n```\n\n## Contributing\n\n**slf4g** is an open source project by [echocat](https://echocat.org). So if you want to make this project even better, you can contribute to this project on [Github](https://github.com/echocat/slf4g) by [fork us](https://github.com/echocat/slf4g/fork).\n\nIf you commit code to this project, you have to accept that this code will be released under the [license](#license) of this project.\n\n## License\n\nSee the [LICENSE](LICENSE) file.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fechocat%2Fslf4g","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fechocat%2Fslf4g","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fechocat%2Fslf4g/lists"}