It is possible to stop notice logs from appearing?

Hi there. So I'm using postgres and I run execute with table truncate. No matter what I try I always get some stuff spammed into the console. Same applies for migration scripts. Overriding logger or writer doesn't help in this case. Thanks
4 Replies
Dan
Dan16mo ago
what kind of logs?
Andrey Los
Andrey LosOP16mo ago
These kinds:
{
severity_local: 'NOTICE',
severity: 'NOTICE',
code: '42P06',
message: 'schema "drizzle" already exists, skipping',
file: 'schemacmds.c',
line: '131',
routine: 'CreateSchemaCommand'
}
{
severity_local: 'NOTICE',
severity: 'NOTICE',
code: '42P07',
message: 'relation "__drizzle_migrations" already exists, skipping',
file: 'parse_utilcmd.c',
line: '207',
routine: 'transformCreateStmt'
}
{
severity_local: 'NOTICE',
severity: 'NOTICE',
code: '42P06',
message: 'schema "drizzle" already exists, skipping',
file: 'schemacmds.c',
line: '131',
routine: 'CreateSchemaCommand'
}
{
severity_local: 'NOTICE',
severity: 'NOTICE',
code: '42P07',
message: 'relation "__drizzle_migrations" already exists, skipping',
file: 'parse_utilcmd.c',
line: '207',
routine: 'transformCreateStmt'
}
For reference here is the script that triggers it.
import { drizzle } from "drizzle-orm/postgres-js"
import { migrate } from "drizzle-orm/postgres-js/migrator"
import * as console from "node:console"
import postgres from "postgres"
import * as z from "zod"

import { env } from "../src/read-env"

const config = z
.object({
NODE_ENV: z.enum(["development", "test", "production"]),
DB_URL: z.string(),
})
.parse(env)

const migrationConnection = postgres(config.DB_URL, { max: 1 })
const connection = drizzle(migrationConnection)

console.info("Attempting a DB migration")

void migrate(connection, {
migrationsFolder: "./node_modules/@namespace/database-schema/drizzle",
})
.then(() => {
console.info("Migration complete")
})
.catch((error) => {
console.error("Migration failed", error)
process.exit(1)
})
.finally(async () => {
await migrationConnection.end()
console.info("Connection closed")
process.exit(0)
})
import { drizzle } from "drizzle-orm/postgres-js"
import { migrate } from "drizzle-orm/postgres-js/migrator"
import * as console from "node:console"
import postgres from "postgres"
import * as z from "zod"

import { env } from "../src/read-env"

const config = z
.object({
NODE_ENV: z.enum(["development", "test", "production"]),
DB_URL: z.string(),
})
.parse(env)

const migrationConnection = postgres(config.DB_URL, { max: 1 })
const connection = drizzle(migrationConnection)

console.info("Attempting a DB migration")

void migrate(connection, {
migrationsFolder: "./node_modules/@namespace/database-schema/drizzle",
})
.then(() => {
console.info("Migration complete")
})
.catch((error) => {
console.error("Migration failed", error)
process.exit(1)
})
.finally(async () => {
await migrationConnection.end()
console.info("Connection closed")
process.exit(0)
})
If I do, let say
await db.execute(sql`TRUNCATE TABLE organizations CASCADE;`)
await db.execute(sql`TRUNCATE TABLE organizations CASCADE;`)
I also get this logged
{
severity_local: 'NOTICE',
severity: 'NOTICE',
code: '00000',
message: 'truncate cascades to table "usersToOrganizations"',
file: 'tablecmds.c',
line: '1726',
routine: 'ExecuteTruncateGuts'
}
{
severity_local: 'NOTICE',
severity: 'NOTICE',
code: '00000',
message: 'truncate cascades to table "invites"',
file: 'tablecmds.c',
line: '1726',
routine: 'ExecuteTruncateGuts'
}
{
severity_local: 'NOTICE',
severity: 'NOTICE',
code: '00000',
message: 'truncate cascades to table "roles"',
file: 'tablecmds.c',
line: '1726',
routine: 'ExecuteTruncateGuts'
}
{
severity_local: 'NOTICE',
severity: 'NOTICE',
code: '00000',
message: 'truncate cascades to table "usersToOrganizations"',
file: 'tablecmds.c',
line: '1726',
routine: 'ExecuteTruncateGuts'
}
{
severity_local: 'NOTICE',
severity: 'NOTICE',
code: '00000',
message: 'truncate cascades to table "invites"',
file: 'tablecmds.c',
line: '1726',
routine: 'ExecuteTruncateGuts'
}
{
severity_local: 'NOTICE',
severity: 'NOTICE',
code: '00000',
message: 'truncate cascades to table "roles"',
file: 'tablecmds.c',
line: '1726',
routine: 'ExecuteTruncateGuts'
}
I wish I could disable these somehow.
Noahh
Noahh16mo ago
Those logs are directly from the postgres package (which is logging them directly from the database connection) if I remember correctly, not sure if there is a way to disable them logging
Andrey Los
Andrey LosOP16mo ago
In the docs of Drizzle, there is definitely no way to disable them. But I think it figured how it can be disabled.
const sql = postgres('postgres://username:password@host:port/database', {
// ...
onnotice : fn, // Defaults to console.log
// ...
})
const sql = postgres('postgres://username:password@host:port/database', {
// ...
onnotice : fn, // Defaults to console.log
// ...
})
Hence:
const migrationConnection = postgres(config.DB_URL, { max: 1, onnotice: () => {} })
const migrationConnection = postgres(config.DB_URL, { max: 1, onnotice: () => {} })
Worked like a charm, but wondering why original wrapper doesn't somehow redirects that to the logger.
Want results from more Discord servers?
Add your server