GORM Playground Link
Sorry in advance if I am not posting a gorm playground link but as what I am reporting it's not a crash and it's really in plainsight I will skip it. Happy to do it anyway if requested.
Description
The Migrator always wraps out the defined gorm logger to print out the SQL in DryRun mode.
Here the reference code
SQL always printed out: https://github.com/go-gorm/gorm/blob/master/migrator/migrator.go#L51
Logger interface wrapping https://github.com/go-gorm/gorm/blob/master/migrator/migrator.go#L115
I am building a migration tool that generates the SQL and using the Trace
function of Logger.Interface
would avoid way more complex workarounds (e.g. wrapping the migrator and dialector, which are driver specific).
It's not clear why this behaviour is hardcoded taking into account that the logging infrastructure exists in gorm for these specific use cases.
This is the PR that introduced it https://github.com/go-gorm/gorm/pull/5689
The main reason for not reusing the logging infrastructure as-is seems to be pointed out in this comment https://github.com/go-gorm/gorm/pull/5689#discussion_r1002510923
But de-facto the SQL is always passed as-is to the Trace
function except for a semi-colon printed by the wrapper on its own and therefore there is no actual difference between invoking the Trace
function and printing out the SQL.
SQL printed out https://github.com/go-gorm/gorm/blob/master/migrator/migrator.go#L51
Trace function invocation https://github.com/go-gorm/gorm/blob/master/migrator/migrator.go#L52
As this code was changed about 2 years ago I guess a few things have changed in the meantime and doesn't seem that fmt.Println is needed anymore.
Comment From: github-actions[bot]
The issue has been automatically marked as stale as it missing playground pull request link, which is important to help others understand your issue effectively and make sure the issue hasn't been fixed on latest master, checkout https://github.com/go-gorm/playground for details. it will be closed in 30 days if no further activity occurs. if you are asking question, please use the Question
template, most likely your question already answered https://github.com/go-gorm/gorm/issues or described in the document https://gorm.io ✨ Search Before Asking ✨
Comment From: github-actions[bot]
The issue has been automatically marked as stale as it missing playground pull request link, which is important to help others understand your issue effectively and make sure the issue hasn't been fixed on latest master, checkout https://github.com/go-gorm/playground for details. it will be closed in 30 days if no further activity occurs. if you are asking question, please use the Question
template, most likely your question already answered https://github.com/go-gorm/gorm/issues or described in the document https://gorm.io ✨ Search Before Asking ✨