Git Product home page Git Product logo

Comments (9)

qustavo avatar qustavo commented on August 28, 2024

Did you try implementing the on OnErrorer[1] interface?
[1]: https://github.com/gchaincl/sqlhooks/blob/master/sqlhooks.go#L21

from sqlhooks.

song-without-words avatar song-without-words commented on August 28, 2024

thanks for your response. it worked!

from sqlhooks.

song-without-words avatar song-without-words commented on August 28, 2024

Sorry, now i have a new problem. Sometimes error log will print twice and i can't find the reason.

from sqlhooks.

qustavo avatar qustavo commented on August 28, 2024

can u send the code

from sqlhooks.

song-without-words avatar song-without-words commented on August 28, 2024
func (h *Hooks) OnError(ctx context.Context, err error, query string, args ...interface{}) error {

begin := ctx.Value("begin").(time.Time)
var traceLog string
res := ctx.Value("traceLog")
if res != nil {
	traceLog = res.(string)
} else {
	traceLog, _ = shortid.Generate()
}
l := clog.NewWithCtx(traceLog)
l.Info("SQL | %10s | %s %v", utils.FormatDuration(time.Since(begin)), query, args)
return err
}

then error sql will log twice.

from sqlhooks.

qustavo avatar qustavo commented on August 28, 2024

could you just try to print a single like in the OnError hook?
so that we can be sure that the problem is with the hook and not with your logger?

from sqlhooks.

song-without-words avatar song-without-words commented on August 28, 2024

thanks for your response. now i think the problem is not with the hook. i use sqlx, then whatever sql is right or wrong, sqlx throws a driver.ErrSkip error and OnError func will exec, so if sql is right, it will print twice.Do you know how to solve it?
error: driver: skip fast-path; continue as if unimplemented

from sqlhooks.

qustavo avatar qustavo commented on August 28, 2024

can you fmt.Printf("error: %+v (%T)", err, err) on the hook.
If the errors are different you can act differently depending on the error you get

from sqlhooks.

song-without-words avatar song-without-words commented on August 28, 2024

thanks for your response, but unfortunately, the errors is the same.
error: driver: skip fast-path; continue as if unimplemented (*errors.errorString)

from sqlhooks.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.