Ent: Feature Request: contextual logging

Created on 22 Jan 2020  路  4Comments  路  Source: ent/ent

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.

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.

All 4 comments

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

metalrex100 picture metalrex100  路  5Comments

jbub picture jbub  路  5Comments

DeedleFake picture DeedleFake  路  5Comments

HarikiRito picture HarikiRito  路  3Comments

sno6 picture sno6  路  4Comments