mariadb-corporation / mariadb-connector-nodejs

MariaDB Connector/Node.js is used to connect applications developed on Node.js to MariaDB and MySQL databases. MariaDB Connector/Node.js is LGPL licensed.
GNU Lesser General Public License v2.1
363 stars 93 forks source link

Feature Request: Copy cmdParams to custom error logger #260

Closed Drejerdk closed 7 months ago

Drejerdk commented 8 months ago

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) ?

rusher commented 7 months ago

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

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 commented 7 months ago

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'
}