Giter Club home page Giter Club logo

viper-mate's Introduction

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.

viper-mate's People

Contributors

drdaeman avatar hpoul avatar

Watchers

 avatar  avatar

Forkers

hpoul

viper-mate's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.