Skip to content
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

Feature Request: Copy cmdParams to custom error logger #260

Closed
Drejerdk opened this issue Nov 13, 2023 · 2 comments
Closed

Feature Request: Copy cmdParams to custom error logger #260

Drejerdk opened this issue Nov 13, 2023 · 2 comments

Comments

@Drejerdk
Copy link

Drejerdk commented Nov 13, 2023

Sometimes I wish it was easier to get the full query and parameters of a query that is throwing an error.

Could it be considered adding a copy of cmdParam as the 2nd parameter when calling custom loggers with this.opts.logger.error(err) ?

@Drejerdk Drejerdk changed the title Copy cmdParams to custom error handler Feature Request: Copy cmdParams to custom error handler Nov 13, 2023
@Drejerdk Drejerdk changed the title Feature Request: Copy cmdParams to custom error handler Feature Request: Copy cmdParams to custom error logger Nov 13, 2023
@rusher
Copy link
Collaborator

rusher commented Nov 30, 2023

The best would be to clearly have an option 'logParam' and all error have either just :

  • the sql
  • the sql + parameter
    actual implementation doesn't always logged parameters in error.

For debugging, loggin parameters might help a lot, but for security reason, some might not want to have the parameters logged, so that correction will be done.
This might not be exactly what you had in mind, you'll tell.

@rusher
Copy link
Collaborator

rusher commented Dec 20, 2023

3.2.3 that has been released permit finer details on that : 2 options defined what will be logged : debugLen and logParam.

debuglen defined string length of logged message / error or trace
logParam indicate if parameters must be logged by query logger.

example of logParam:
when false, some errors :

SqlError: (conn=-1, no: 45051, SQLState: 22000) Execute fails, prepare command as already been closed
sql: select ?
    at module.exports.createError (C:\projects\mariadb-connector-nodejs\lib\misc\errors.js:64:10)
    at PrepareResultPacket.execute (C:\projects\mariadb-connector-nodejs\lib\cmd\class\prepare-result-packet.js:51:28)
    at Context.<anonymous> (C:\projects\mariadb-connector-nodejs\test\integration\test-execute.js:267:21)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
  sqlMessage: 'Execute fails, prepare command as already been closed',
  sql: 'select ?',
  fatal: false,
  errno: 45051,
  sqlState: '22000',
  code: 'ER_PREPARE_CLOSED'
}

when enable:

SqlError: (conn=-1, no: 45051, SQLState: 22000) Execute fails, prepare command as already been closed
sql: select ? - parameters:['1']
    at module.exports.createError (C:\projects\mariadb-connector-nodejs\lib\misc\errors.js:64:10)
    at PrepareResultPacket.execute (C:\projects\mariadb-connector-nodejs\lib\cmd\class\prepare-result-packet.js:51:28)
    at Context.<anonymous> (C:\projects\mariadb-connector-nodejs\test\integration\test-execute.js:267:21)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
  sqlMessage: 'Execute fails, prepare command as already been closed',
  sql: "select ? - parameters:['1']",
  fatal: false,
  errno: 45051,
  sqlState: '22000',
  code: 'ER_PREPARE_CLOSED'
}

@rusher rusher closed this as completed Dec 20, 2023
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

2 participants