Code Monkey home page Code Monkey logo

fluent-golang-io-writer's Introduction

fluent-logger-io-writer GoDoc

This library is covered in an AWS Open Source blog post: Splitting an application’s logs into multiple streams: a Fluent tutorial

This library was created to demonstrate a somewhat experimental idea. If you end up using it (or write your own similar code), please plus one this issue to let us know. Thoughts/comments/feedback also welcome.

What is it?

Go Code that wraps the fluent-logger-golang in a struct that implements io.Writer.

This means it can be used as the underlying io stream for many loggers. See main.go for full example usage.

Simple example with the popular sirupsen/logrus logger:

import (
	"fmt"

	"github.com/awslabs/fluent-golang-io-writer/logger"

	"github.com/fluent/fluent-logger-golang/fluent"
	"github.com/sirupsen/logrus"
)

func main() {
	// configure logrus to output as JSON
	logrus.SetFormatter(&logrus.JSONFormatter{})
	logrus.SetLevel(logrus.DebugLevel)

	// create a FluentWriter instance
	fluentLogger, err := logger.NewFluentWriter(fluent.Config{}, "app", []string{"level"})
	if err != nil {
		fmt.Println(err)
		os.Exit(1)
	}

	// Set logrus to use it
	logrus.SetOutput(fluentLogger)

	// Now use logrus as normal!
	logrus.WithFields(logrus.Fields{
		"animal": "walrus",
	}).Info("A walrus appears")
}
logger.NewFluentWriter(fluent.Config{}, "app", []string{"level"})

Above, we see the call to the constructor for the library. The first argument is the Fluent Logger Golang config object which configures the connection to Fluentd/Bit. The second argument is a prefix for the tags given to logs emitted by this writer. The third argument is a list of keys in the log messages whose values will be the suffix of the tag. This library relies on the fact that the logs produced by Logrus will be JSON formatted. Thus, it will find the level key in each log message and append this to the tag prefix to construct the final tag. In practice, logs will be emitted with tags as follows:

  • app.debug for the debug logs
  • app.info for the info logs
  • app.warning for the warn logs
  • app.error for the error logs
  • app.fatal for the fatal logs

Logs which do not have a level field or which can not be parsed as JSON will simply be given the tag app.

License

This project is licensed under the Apache-2.0 License.

fluent-golang-io-writer's People

Contributors

amazon-auto avatar efekarakus avatar pettitwesley avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

fluent-golang-io-writer's Issues

Is this library useful?

I created this library to demonstrate an idea. I've tested it and used it a little myself as well. I think it's a good idea, but I could be wrong.

If you end up using this library (either by directly importing the code or copying it) please plus one this issue. Also plus one if you think you may use it in the future. That data will help encourage us to expand and improve it.

Comment or submit a new issue if you'd use if it were changed or more features were added.

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.