zerolog icon indicating copy to clipboard operation
zerolog copied to clipboard

how to add caller package name in log?

Open woodgear opened this issue 3 years ago • 1 comments

woodgear avatar Feb 18 '22 03:02 woodgear

@woodgear I guess you are looking for this:

zerolog.CallerMarshalFunc = func(file string, line int) string {
	var n int
	for i := len(file) - 1; i >= 0; i-- {
		if file[i] == '/' {
			n++
			if n == 2 {
				file = file[i+1:]
				break
			}
		}
	}
	return file + ":" + strconv.Itoa(line)
}

roy2220 avatar Mar 01 '22 13:03 roy2220