Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sohlich/elogrus
Logrus Hook for ElasticSearch
https://github.com/sohlich/elogrus
elasticsearch golang logging logrus
Last synced: 7 days ago
JSON representation
Logrus Hook for ElasticSearch
- Host: GitHub
- URL: https://github.com/sohlich/elogrus
- Owner: sohlich
- License: mit
- Created: 2016-01-09T11:58:37.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2024-06-04T12:35:19.000Z (8 months ago)
- Last Synced: 2025-01-16T06:56:43.269Z (16 days ago)
- Topics: elasticsearch, golang, logging, logrus
- Language: Go
- Homepage:
- Size: 44.9 KB
- Stars: 158
- Watchers: 9
- Forks: 52
- Open Issues: 13
-
Metadata Files:
- Readme: README.MD
- License: LICENSE
Awesome Lists containing this project
README
# ElasticSearch Hook for [Logrus](https://github.com/Sirupsen/logrus)
## Releases
**Notice that the master branch always refers to the latest version of Elastic. If you want to use stable versions of elogus, you should use the packages released via [gopkg.in](https://gopkg.in).***Here's the version matrix:*
ElasticSearch version | Elastic version | Package URL | Remarks |
----------------------|------------------|------------------------------------------|---------|
7.x | 7.0 | [`gopkg.in/sohlich/elogrus.v7`](http://gopkg.in/sohlich/elogrus.v7)| Use Go modules.
6.x | 6.0 | [`gopkg.in/sohlich/elogrus.v3`](http://gopkg.in/sohlich/elogrus.v3)| Actively maintained.
5.x | 5.0 | [`gopkg.in/sohlich/elogrus.v2`](http://gopkg.in/sohlich/elogrus.v2)| Actively maintained.
2.x | 3.0 | [`gopkg.in/sohlich/elogrus.v1`](http://gopkg.in/sohlich/elogrus.v1)| Deprecated. Please update.*For elastic search 7.x*
```bash
# We name v7 to align with elastic v7
go get gopkg.in/sohlich/elogrus.v7
go get github.com/olivere/elastic/v7
```*For elastic search 6.x*
```bash
go get gopkg.in/sohlich/elogrus.v3
go get github.com/olivere/elastic```
*For elastic search 5.x*
```bash
go get gopkg.in/sohlich/elogrus.v2
go get gopkg.in/olivere/elastic.v5```
## Changelog
- elastic 7.x support (currently in master)## Usage
```go
package mainimport (
"github.com/olivere/elastic/v7"
"github.com/sirupsen/logrus"
"gopkg.in/sohlich/elogrus.v7"
)func main() {
log := logrus.New()
client, err := elastic.NewClient(elastic.SetURL("http://localhost:9200"))
if err != nil {
log.Panic(err)
}
hook, err := elogrus.NewAsyncElasticHook(client, "localhost", logrus.DebugLevel, "mylog")
if err != nil {
log.Panic(err)
}
log.Hooks.Add(hook)log.WithFields(logrus.Fields{
"name": "joe",
"age": 42,
}).Error("Hello world!")
}
```### Asynchronous hook
```go
...
elogrus.NewAsyncElasticHook(client, "localhost", logrus.DebugLevel, "mylog")
...
```