Skip to content

How to log batched SQL queries? #680

@benjamin-bader

Description

@benjamin-bader

Hi there!

I'm working with logging at the moment, and noticing that in the v4 Logger interface, I see SQL text in the data map under the "sql" key. For batched queries, unfortunately, it seems that this field is always the literal value "batch query".

Is there a way, in pgx, to log the individual statements that make up a batch?

My log configuration code, in essence:

func (la *LogAdapter) Log(ctx context.Context, level pgx.LogLevel, msg string, data map[string]interface{}) {
  if sql, ok := data["sql"]; ok {
    la.logger.Infof("Executing SQL: %s", sql)
  }
}

config, err := pgxpool.ParseConfig(...)
// error handling omitted
config.ConnConfig.Logger = &LogAdapter{...}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions