Browse Source
Feature/use log levels to conditionally log prisma query events (#4003)
* Use LOG_LEVELS for prisma query events
* Update changelog
pull/4004/head
Thomas Kaul
3 months ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with
30 additions and
3 deletions
-
CHANGELOG.md
-
apps/api/src/services/prisma/prisma.module.ts
-
apps/api/src/services/prisma/prisma.service.ts
|
|
@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 |
|
|
|
|
|
|
|
## Unreleased |
|
|
|
|
|
|
|
### Added |
|
|
|
|
|
|
|
- Added support for log levels (`LOG_LEVELS`) to conditionally log `prisma` query events (`debug` or `verbose`) |
|
|
|
|
|
|
|
### Changed |
|
|
|
|
|
|
|
- Restructured the resources page |
|
|
|
|
|
@ -1,9 +1,10 @@ |
|
|
|
import { PrismaService } from '@ghostfolio/api/services/prisma/prisma.service'; |
|
|
|
|
|
|
|
import { Module } from '@nestjs/common'; |
|
|
|
import { ConfigService } from '@nestjs/config'; |
|
|
|
|
|
|
|
@Module({ |
|
|
|
providers: [PrismaService], |
|
|
|
exports: [PrismaService] |
|
|
|
exports: [PrismaService], |
|
|
|
providers: [ConfigService, PrismaService] |
|
|
|
}) |
|
|
|
export class PrismaModule {} |
|
|
|
|
|
@ -1,16 +1,38 @@ |
|
|
|
import { |
|
|
|
Injectable, |
|
|
|
Logger, |
|
|
|
LogLevel, |
|
|
|
OnModuleDestroy, |
|
|
|
OnModuleInit |
|
|
|
} from '@nestjs/common'; |
|
|
|
import { PrismaClient } from '@prisma/client'; |
|
|
|
import { ConfigService } from '@nestjs/config'; |
|
|
|
import { Prisma, PrismaClient } from '@prisma/client'; |
|
|
|
|
|
|
|
@Injectable() |
|
|
|
export class PrismaService |
|
|
|
extends PrismaClient |
|
|
|
implements OnModuleInit, OnModuleDestroy |
|
|
|
{ |
|
|
|
public constructor(configService: ConfigService) { |
|
|
|
let customLogLevels: LogLevel[]; |
|
|
|
|
|
|
|
try { |
|
|
|
customLogLevels = JSON.parse( |
|
|
|
configService.get<string>('LOG_LEVELS') |
|
|
|
) as LogLevel[]; |
|
|
|
} catch {} |
|
|
|
|
|
|
|
const log: Prisma.LogDefinition[] = |
|
|
|
customLogLevels?.includes('debug') || customLogLevels?.includes('verbose') |
|
|
|
? [{ emit: 'stdout', level: 'query' }] |
|
|
|
: []; |
|
|
|
|
|
|
|
super({ |
|
|
|
log, |
|
|
|
errorFormat: 'colorless' |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
public async onModuleInit() { |
|
|
|
try { |
|
|
|
await this.$connect(); |
|
|
|