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

fix(logging): knex should use pino logger and not compile sql on error in production #2743

Merged
merged 1 commit into from
Aug 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions packages/server/knexfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const {
ignoreMissingMigrations,
postgresMaxConnections
} = require('@/modules/shared/helpers/envHelper')
const { dbLogger: logger } = require('./logging/logging')

function walk(dir) {
let results = []
Expand Down Expand Up @@ -75,6 +76,22 @@ const commonConfig = {
loadExtensions: isTestEnv() ? ['.js', '.ts'] : ['.js'],
directory: migrationDirs
},
log: {
warn(message) {
logger.warn(message)
},
error(message) {
logger.error(message)
},
deprecate(message) {
logger.info(message)
},
debug(message) {
logger.debug(message)
}
},
// we wish to avoid leaking sql queries in the logs: https://knexjs.org/guide/#compilesqlonerror
compileSqlOnError: false,
pool: { min: 0, max: postgresMaxConnections() }
}

Expand All @@ -86,6 +103,7 @@ const config = {
connectionString: connectionUri || 'postgres://127.0.0.1/speckle2_test',
application_name: 'speckle_server'
},
compileSqlOnError: true,
asyncStackTraces: true
},
development: {
Expand All @@ -94,6 +112,7 @@ const config = {
connectionString: connectionUri || 'postgres://127.0.0.1/speckle2_dev',
application_name: 'speckle_server'
},
compileSqlOnError: true,
asyncStackTraces: true
},
production: {
Expand Down