machinery icon indicating copy to clipboard operation
machinery copied to clipboard

Is there an example or some instruction for custom logger with zap?

Open chinajuanbob opened this issue 4 years ago • 4 comments

It is complicated to use zap with custom logger since each level of machinery has its own logger, and zap logger set level by method, like Errorf() and Infoln()

I wonder if there are already some solutions or references.

Thanks a lot!

chinajuanbob avatar Mar 19 '20 04:03 chinajuanbob

any solutions for this ? :(

toet251 avatar Jul 16 '20 08:07 toet251

maybe you can use machinery/v1/log/Set(l logging.LoggerInterface)?

shallowclouds avatar Aug 09 '20 03:08 shallowclouds

maybe you can use machinery/v1/log/Set(l logging.LoggerInterface)?

// Set sets a custom logger for all log levels
func Set(l logging.LoggerInterface) {
	DEBUG = l
	INFO = l
	WARNING = l
	ERROR = l
	FATAL = l
}

Even if you'll make your custom logger with implemented interfaces you'll have a problem, because each level will not differ.

skykery avatar May 10 '21 12:05 skykery

maybe you can use machinery/v1/log/Set(l logging.LoggerInterface)?

// Set sets a custom logger for all log levels
func Set(l logging.LoggerInterface) {
	DEBUG = l
	INFO = l
	WARNING = l
	ERROR = l
	FATAL = l
}

Even if you'll make your custom logger with implemented interfaces you'll have a problem, because each level will not differ.

Actually machinery logger provides methods to set logger for each log level, for me I implement it by wrapping my own loggers like this:

image

shallowclouds avatar May 10 '21 12:05 shallowclouds