Skip to content

feature request: trace log sql query statements #1716

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
stokito opened this issue May 13, 2025 · 0 comments
Open

feature request: trace log sql query statements #1716

stokito opened this issue May 13, 2025 · 0 comments

Comments

@stokito
Copy link

stokito commented May 13, 2025

I need to log the raw SQL statements.

We can specify a custom logger when opening a database:

	cfg, _ := mysql.ParseDSN(dsName)
	// set a custom logger
	tracer := log.New(os.Stdout, "[mysql] ", log.Ldate|log.Ltime|log.Lshortfile)
	cfg.Logger = tracer

	connector, err := mysql.NewConnector(cfg)
	if err != nil {
		return err
	}
	db := sql.OpenDB(connector)

But the logger won't log SQL statements from Exec() and Query(), but only some internal problems. See mysqlConn.log() usage.

Is it possible to add an sql logging in the driver? This may be a flag in a config like cfg.LogStatements = true or a separate logger/tracer field cfg.Tracer like this implemented in the PGX driver tracelog:

config, err := pgxpool.ParseConfig(dsName)
tracer = &tracelog.TraceLog{Logger: myLogger, LogLevel: tracelog.LogLevelInfo}
config.ConnConfig.Tracer = tracer
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant