Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ways to configure the logger #27

Open
kartlee opened this issue May 8, 2016 · 2 comments
Open

Ways to configure the logger #27

kartlee opened this issue May 8, 2016 · 2 comments

Comments

@kartlee
Copy link

kartlee commented May 8, 2016

Hi Folks,

Is there a way to configure a new logger? I am thinking of using logrus to structure the logging in json format for a project, so if you have any suggestion, please recommend.

-Kartlee

@fvbock
Copy link
Owner

fvbock commented May 30, 2016

hi @kartlee

i am not familiar with logrus. what i did in some other project when using go-kit's logger was redirecting the output from the std lib log to the adapter gokit provides:

import (
    stdlog "log"
    kitlog "github.com/go-kit/kit/log"
)

stdlog.SetOutput(kitlog.NewStdlibAdapter(logger))

does something like that work for you?

@Zambiorix
Copy link

Zambiorix commented Jan 13, 2017

I think there is a better solution to implement in endless:

var logger = log.New(os.Stdout, "", 0)

var loggerDiscard = log.New(ioutil.Discard, "", 0)

// SetLogger ...
//
func SetLogger(lg *log.Logger) {

	if lg == nil {

		lg = loggerDiscard
	}

	logger = lg
}

func useLogger() {

	logger.Print("foo", "bar")
}

This way I can externally controle the logger (prefix, flags, ...) or even discard as I see fit.
I use endless in a daemon and I want to eliminate the output, with the above code implemented in endless it would be possible...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants