Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/cabify/logrusiowriter
io.Writer implementation using logrus logger [managed by soy-programador]
https://github.com/cabify/logrusiowriter
Last synced: about 2 months ago
JSON representation
io.Writer implementation using logrus logger [managed by soy-programador]
- Host: GitHub
- URL: https://github.com/cabify/logrusiowriter
- Owner: cabify
- License: other
- Created: 2019-08-09T08:58:25.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2020-07-15T09:10:12.000Z (over 4 years ago)
- Last Synced: 2024-07-31T20:52:15.734Z (5 months ago)
- Language: Go
- Homepage:
- Size: 18.6 KB
- Stars: 16
- Watchers: 93
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
- awesome-go - logrusiowriter - `io.Writer` implementation using [logrus](https://github.com/sirupsen/logrus) logger. (Logging / Search and Analytic Databases)
- awesome-go-extra - logrusiowriter - 08-09T08:58:25Z|2020-07-15T09:10:12Z| (Logging / Advanced Console UIs)
README
# logrusiowriter
## `io.Writer` implementation using logrus[![Travis CI build status](https://travis-ci.com/cabify/logrusiowriter.svg?branch=master)](https://travis-ci.com/cabify/logrusiowriter)
[![GoDoc](https://godoc.org/github.com/cabify/logrusiowriter?status.svg)](https://godoc.org/github.com/cabify/logrusiowriter)
[![Coverage Status](https://coveralls.io/repos/github/cabify/logrusiowriter/badge.svg?branch=master)](https://coveralls.io/github/cabify/logrusiowriter?branch=master)
[![Mentioned in Awesome Go](https://awesome.re/mentioned-badge.svg)](https://github.com/avelino/awesome-go)# Motivation
Many golang libraries use the golang's `log` package to print their logs. This means that if your application
uses logrus to print structured logging, those packages will print a format that is (probably) incompatible with yours,
and you may end losing logs in your logs collector because they can't be parsed properly.# Solution
Print the logs written using `log.Printf` through `logrus`, by setting `log.SetOutput` to an `io.Writer` implementation
that uses `logrus` as output, i.e.:```go
log.SetOutput(logrusiowriter.New())
```See `example_*_test.go` files to find testable examples that serve as documentation.
# Simple solution
Or... you can simply use the standard APIs that logrus provides, i.e., this does the same as this package:
```go
log.SetOutput(logrus.WithFields(logrus.Fields{"logger": "stdlib"}).WriterLevel(logrus.InfoLevel))
```So, unless you want this to be configurable using an envconfig-filled struct, there's no reason to use this library.