go-logging icon indicating copy to clipboard operation
go-logging copied to clipboard

Diffrent format / config for diffrent level

Open yoni386 opened this issue 7 years ago • 1 comments

Hello, How to make different config / format for each level, e.g. make debug and info with specific properties.

Thank you

yoni386 avatar Sep 06 '18 19:09 yoni386

https://github.com/op/go-logging/pull/60#issuecomment-159413338

You can easily create your own backend type, e.g:

type MyBackend struct {
	backend logging.Backend
}

func (b *MyBackend) Log(level logging.Level, calldepth int, rec *logging.Record) error {
	if level == logging.ERROR {
		formatted := rec.Formatted(calldepth)
		superImportantFunction(formatted)
		return nil
	} else {
		return b.backend.Log(level, calldepth, rec)
	}
}

iTrooz avatar Mar 25 '24 12:03 iTrooz