Sometimes it is useful to support logging with context.
E.g. I want to distinguish logs that belong to single request.
Could be achieved by allowing a logging function to receive a context:
func LogCtx(fn func(ctx context.Context, i ...interface{})) Option {
return func(c *config) {
c.logCtx = fn
}
}
Or by something like func getLog(ctx context.Context) func(...Interface{}) function that will return logging function for provided context.
Btw, thank you for your great project.
Sounds good, feel free to send a PR updating the current logging function as suggested above.
The codegen doesn't emit logs today - what emits them is a dialect wrapper called dialect.DebugDriver.
It can be achieved today by providing your own wrapper. However, I agree that it's nice to have that, so a PR is welcome for something like DebugWithContext (like RequestWithContext).
Note that, if you're using ocsql or something similar, you won't see additional logs than what ocsql emits.
@ernado If you don't mind, I'm really interested implementing this feature. I actually need this to use ent with zerolog.
Hey @aca, feel free to submit PR, it would be great!
I'm currently actively prototyping new project with ent, so slightly out of capacity and can't do it myself.
Most helpful comment
The codegen doesn't emit logs today - what emits them is a dialect wrapper called dialect.DebugDriver.
It can be achieved today by providing your own wrapper. However, I agree that it's nice to have that, so a PR is welcome for something like
DebugWithContext(like RequestWithContext).Note that, if you're using ocsql or something similar, you won't see additional logs than what ocsql emits.