zerolog icon indicating copy to clipboard operation
zerolog copied to clipboard

Add ability to override exit function

Open nickpalmer opened this issue 2 years ago • 2 comments

There should be a way to override the os.Exit() function call with a different exit handler.

zerolog.SetExitFunc(exit func(int) {})
// or even via a global
var ExitFunc = os.Exit()

This would allow people to do required cleanup such as closing a log file, or to write tests that call Fatal() and check that fatal was called.

nickpalmer avatar Jan 16 '22 01:01 nickpalmer

That would be nice because it would allow me to test fatal functions.

roger-russel avatar Jan 06 '23 08:01 roger-russel

Was there ever a solution for this? Looking into how I can write unit tests around a function that uses the log.Fatal() function.

kieronlanning avatar Nov 04 '23 16:11 kieronlanning