endless icon indicating copy to clipboard operation
endless copied to clipboard

Ways to configure the logger

Open kartlee opened this issue 9 years ago • 2 comments

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

kartlee avatar May 08 '16 02:05 kartlee

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?

fvbock avatar May 30 '16 13:05 fvbock

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...

Zambiorix avatar Jan 13 '17 11:01 Zambiorix