Feature/use log levels to conditionally log prisma query events (#4003)
* Use LOG_LEVELS for prisma query events * Update changelog
This commit is contained in:
parent
10e725b51a
commit
db53ef54c4
@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
|
|
||||||
## Unreleased
|
## Unreleased
|
||||||
|
|
||||||
|
### Added
|
||||||
|
|
||||||
|
- Added support for log levels (`LOG_LEVELS`) to conditionally log `prisma` query events (`debug` or `verbose`)
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
|
|
||||||
- Restructured the resources page
|
- Restructured the resources page
|
||||||
|
@ -1,9 +1,10 @@
|
|||||||
import { PrismaService } from '@ghostfolio/api/services/prisma/prisma.service';
|
import { PrismaService } from '@ghostfolio/api/services/prisma/prisma.service';
|
||||||
|
|
||||||
import { Module } from '@nestjs/common';
|
import { Module } from '@nestjs/common';
|
||||||
|
import { ConfigService } from '@nestjs/config';
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
providers: [PrismaService],
|
exports: [PrismaService],
|
||||||
exports: [PrismaService]
|
providers: [ConfigService, PrismaService]
|
||||||
})
|
})
|
||||||
export class PrismaModule {}
|
export class PrismaModule {}
|
||||||
|
@ -1,16 +1,38 @@
|
|||||||
import {
|
import {
|
||||||
Injectable,
|
Injectable,
|
||||||
Logger,
|
Logger,
|
||||||
|
LogLevel,
|
||||||
OnModuleDestroy,
|
OnModuleDestroy,
|
||||||
OnModuleInit
|
OnModuleInit
|
||||||
} from '@nestjs/common';
|
} from '@nestjs/common';
|
||||||
import { PrismaClient } from '@prisma/client';
|
import { ConfigService } from '@nestjs/config';
|
||||||
|
import { Prisma, PrismaClient } from '@prisma/client';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class PrismaService
|
export class PrismaService
|
||||||
extends PrismaClient
|
extends PrismaClient
|
||||||
implements OnModuleInit, OnModuleDestroy
|
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() {
|
public async onModuleInit() {
|
||||||
try {
|
try {
|
||||||
await this.$connect();
|
await this.$connect();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user