[Proposal] Add the log level to the error builder
What about adding a .Level(slog.Level) method to the error builder?
Pros:
- When I build an error in a nested function, the caller cannot differentiate between an acceptable error (warning?) and a blocking error (error).
- An HTTP status 404 is a warning while a 500 is an error, but both are considered errors by the HTTP frameworks.
Cons:
- The log level is a logger thing, while this library provides an error builder. The separation of concern is not fully respected.
It depends on how you get the level value back when logging the error.
I would stick to slog levels if this is to be implemented. In that case it would be easy to implement a conversion function if the user wants to convert the slog-level to another logger format (logrus e.g.).
For slog:
err := oops.WithLevel(slog.LevelInfo)
slog.LogAttrs(ctx, err.Level(), err.Error(), slog.Any("error", err)
For logrus:
err := oops.WithLevel(slog.LevelInfo)
logger.Logf(oops.LogrusLevel(err.Level()), err)
The question is, do you want to include conversion functions for "all" known/commonly used log implementations? The biggest concern here is that you don't want to add dependencies on those loggers.
If we want to add such a method, I agree, we must use slog.
But the question is: do we want such a method ?? 😅 The library has emerged as a wrapper that complements loggers. I'm not sure the error level should be considered as part of the semantics.
Some loggers already have a custom integration to oops: https://github.com/samber/oops/tree/main/loggers
How valuable the method would be, I think it is not up to "oops" to define the level of an error message, except maybe at the "TRACE" level.
For instance, I'm looking at using oops within my SDK for the NetScaler Nitro API, but it is still up to the SDK's consumers to decide when and which errors to log at which level.
Maybe not call it log level, call it DetailLevel. Then users can decide how much detail they want on which log level with a custom wrapper.
but looking at the OP I would just add a field called Severity SeverityLevel