P
Prisma•7d ago
Spyda

Logging with Prisma v7

Hey all, given Prisma v7 now requires we use adapters when connecting to a database (see here - https://www.prisma.io/docs/orm/more/upgrade-guides/upgrading-versions/upgrading-to-prisma-7#driver-adapters-and-client-instantiation), how do we continue to use logging via emitted events i.e. the example here https://www.prisma.io/docs/orm/prisma-client/observability-and-logging/logging ? Thestdout option works fine (outputs logs to stdout), but it seems like the below example snippet from the docs no longer works i.e. doesn't trigger an event and then console.log output. As a result, it's no longer possible to have a custom logger.
prisma.$on('query', (e) => {
console.log('Query: ' + e.query)
console.log('Params: ' + e.params)
console.log('Duration: ' + e.duration + 'ms')
})
prisma.$on('query', (e) => {
console.log('Query: ' + e.query)
console.log('Params: ' + e.params)
console.log('Duration: ' + e.duration + 'ms')
})
Logging | Prisma Documentation
Learn how to configure Prisma Client to log the raw SQL queries it sends to the database and other information.
Upgrade to Prisma ORM 7 | Prisma Documentation
Guide on how to upgrade to Prisma ORM 7
7 Replies
Prisma AI Help
Prisma AI Help•7d ago
Salutations, traveler! I'm the Prisma AI Help Bot. You've reached a fork in the road: one path leads to the wisdom of the human sages (ETA: sometime today), and the other to my instantaneous insights. Which way shall we go?
Aman
Aman•7d ago
Hey @Spyda I just tried it and it seems to be working 🤔
No description
Spyda
SpydaOP•7d ago
I see you’re using the PG adapter. I wonder if this is a MySQL / MariaDB thing? If you whack the MySQL adapter in, does it still work? My TS was yelling at me well and truly before runtime, so even if you don’t have a DB handy
Aman
Aman•7d ago
checking...
Aman
Aman•7d ago
worked with mariadb adpater too
No description
Aman
Aman•7d ago
🤔
Spyda
SpydaOP•6d ago
By passing in just the log levels, and not the "emit" type, the default output type is stdout, which still works (per the post above). Quote from the docs is:
const prisma = new PrismaClient({ log: ['query', 'info', 'warn', 'error'], }) This is the short form of passing in an array of LogDefinition objects where the value of emit is always stdout:
To replicate, you need to enable the "emit: event". That's on me for not providing a full snippet example. That being said... I've booted up my dev environment this morning and it's working, so I don't know what was going on yesterday.... Typescript is still mad, but functionality is there... Any suggestions around the TS errors?
No description

Did you find this page helpful?