Description
Is your feature request related to a problem? Please describe.
Currently there's no way to change the function name printed in the output when FunctionKey
is set. Instead of printing the full path like github.com/wakatime/wakatime-cli/cmd.RunE
, I'd like to manipulate this output and replace by cmd.RunE
.
{"level":"debug","now":"2024-11-08T11:58:54-03:00","caller":"cmd/run.go:141","func":"github.com/wakatime/wakatime-cli/cmd.RunE","message":"command: heartbeat"}
Describe the solution you'd like
I thought I could add a new option like func WithFunctionNameReplacer(fn func(function string) string) Option
that would set this cutomized function in logger struct and may be called at check()
where the function name is captured.
if log.addCaller {
funcName := frame.Function
if log.nameReplacerFunc != nil {
funcName = log.nameReplacerFunc(funcName)
}
ce.Caller = zapcore.EntryCaller{
Defined: frame.PC != 0,
PC: frame.PC,
File: frame.File,
Line: frame.Line,
Function: funcName,
}
}
Then the result will be
{"level":"debug","now":"2024-11-08T12:42:07-03:00","caller":"cmd/run.go:141","func":"cmd.RunE","message":"command: heartbeat"}
Describe alternatives you've considered
Could not find any alternative.
Is this a breaking change?
No
Additional context
Does that make sense? If so, I'd be happy to make a PR.
Activity