feat: add prisma logging

This commit is contained in:
Isaac 2023-06-25 13:43:10 +01:00
parent ff8e66638a
commit 3b5e58c1fe
No known key found for this signature in database
GPG Key ID: 0DE40AE37BBA5C33
2 changed files with 15 additions and 1 deletions

View File

@ -52,8 +52,21 @@ module.exports = class Client extends FrameworkClient {
}
async login(token) {
const levels = ['error', 'info', 'warn'];
if (this.config.logs.level === 'debug') levels.push('query');
/** @type {PrismaClient} */
this.prisma = new PrismaClient();
this.prisma = new PrismaClient({
log: levels.map(level => ({
emit: 'event',
level,
})),
});
this.prisma.$on('error', e => this.log.error.prisma(`${e.target} ${e.message}`));
this.prisma.$on('info', e => this.log.info.prisma(`${e.target} ${e.message}`));
this.prisma.$on('warn', e => this.log.warn.prisma(`${e.target} ${e.message}`));
this.prisma.$on('query', e => this.log.debug.prisma(e));
if (process.env.DB_PROVIDER === 'sqlite') {
// rewrite queries that use unsupported features

View File

@ -58,6 +58,7 @@ module.exports = config => {
'listeners',
'menus',
'modals',
'prisma',
'settings',
'tickets',
],