https://github.com/drdaeman/viper-mate
Viper configuration provider for Logrus Mate
https://github.com/drdaeman/viper-mate
configuration go golang golang-library logging logrus logrus-helper spf13-viper
Last synced: about 1 year ago
JSON representation
Viper configuration provider for Logrus Mate
- Host: GitHub
- URL: https://github.com/drdaeman/viper-mate
- Owner: drdaeman
- License: mit
- Created: 2017-12-04T21:37:33.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2018-04-28T14:54:36.000Z (about 8 years ago)
- Last Synced: 2025-02-05T00:46:34.843Z (over 1 year ago)
- Topics: configuration, go, golang, golang-library, logging, logrus, logrus-helper, spf13-viper
- Language: Go
- Size: 7.81 KB
- Stars: 0
- Watchers: 2
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Viper configuration provider for Logrus Mate
============================================
This tiny project is a way to configure Logrus Mate using Viper
as the configuration source. It is meant to be used with the currently
unreleased version of Logrus Mate (`v1.0.0` doesn't have the configuration
providers, only `master` branch does).
As Viper is very different to other configuration options, there is
no way to mix it with e.g. HOCON. Basically, the assumption is that
your project uses Viper and you don't want any other configuration
system just for logging. If so, this library may come handy.
Here's a code snippet with usage example:
loggingConfig := viper.Sub("logging")
if loggingConfig != nil {
mate, err := vipermate.NewMate(loggingConfig)
if err != nil {
logrus.WithError(err).Panic("Failed to process configuration")
}
if err = mate.Hijack(logrus.StandardLogger(), "main"); err != nil {
logrus.WithError(err).Panic("Failed to configure main logger")
}
}
Then, an example config (I use YAML, YMMV) could look like, e.g.:
logging:
main:
out:
name: stdout
options: {}
level: debug
formatter:
name: text
options:
force-colors: true
timestamp-format: "2006-01-02T15:04:05Z07:00"
disable-timestamp: false
full-timestamp: true
hooks:
# Let's say we want to set up an ELK hook
logstash:
protocol: tcp
address: "elk.example.org:5959"
name: "myapp"
Check out the source code for more details and information
about the limitations. In particular, non-string slice functions
are not implemented because Viper doesn't have anything like that.