Error prints a log entry containing an error message assigned to the "error" key. Optionally, an error message prefix can be included. Prefix arguments are handled as in fmt.Print.
(ctx context.Context, err error, a ...interface{})
| 195 | // Optionally, an error message prefix can be included. Prefix arguments are |
| 196 | // handled as in fmt.Print. |
| 197 | func Error(ctx context.Context, err error, a ...interface{}) { |
| 198 | Helper() |
| 199 | if _, hasStack := errors.Stack(err).Next(); len(a) > 0 && hasStack { |
| 200 | err = errors.Wrap(err, a...) // keep err's stack |
| 201 | } else if len(a) > 0 { |
| 202 | err = fmt.Errorf("%s: %s", fmt.Sprint(a...), err) // don't add a stack here |
| 203 | } |
| 204 | Printkv(ctx, KeyError, err) |
| 205 | } |
| 206 | |
| 207 | // formatKey ensures that the stringified key is valid for use in a |
| 208 | // Splunk-style K=V format. It stubs out delimeter and quoter characters in |