logging
This commit is contained in:
@@ -8,23 +8,46 @@ import { AuthModule } from './auth/auth.module';
|
||||
import { ListTemplatesModule } from './list-templates/list-templates.module';
|
||||
import { ListsModule } from './lists/lists.module';
|
||||
import { MailModule } from './mail/mail.module';
|
||||
import {
|
||||
databaseLoggerOptionsFromEnv,
|
||||
parseDatabaseLogging,
|
||||
slowQueryThresholdFromEnv,
|
||||
} from './database/database-logging.config';
|
||||
import { DatabaseLogger } from './database/database.logger';
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
ConfigModule.forRoot({ isGlobal: true }),
|
||||
TypeOrmModule.forRootAsync({
|
||||
inject: [ConfigService],
|
||||
useFactory: (configService: ConfigService) => ({
|
||||
type: 'mysql',
|
||||
host: configService.get<string>('DB_HOST', 'localhost'),
|
||||
port: Number(configService.get<string>('DB_PORT', '3306')),
|
||||
username: configService.get<string>('DB_USERNAME', 'root'),
|
||||
password: configService.get<string>('DB_PASSWORD', ''),
|
||||
database: configService.get<string>('DB_DATABASE', 'listify'),
|
||||
autoLoadEntities: true,
|
||||
synchronize: false,
|
||||
logging: configService.get<string>('DB_LOGGING', 'false') === 'true',
|
||||
}),
|
||||
useFactory: (configService: ConfigService) => {
|
||||
const env = {
|
||||
DB_LOGGING: configService.get<string>('DB_LOGGING', 'false'),
|
||||
DB_LOG_PARAMETERS: configService.get<string>('DB_LOG_PARAMETERS', 'false'),
|
||||
DB_LOG_MAX_PARAM_LENGTH: configService.get<string>(
|
||||
'DB_LOG_MAX_PARAM_LENGTH',
|
||||
'500',
|
||||
),
|
||||
DB_SLOW_QUERY_THRESHOLD_MS: configService.get<string>(
|
||||
'DB_SLOW_QUERY_THRESHOLD_MS',
|
||||
'500',
|
||||
),
|
||||
};
|
||||
|
||||
return {
|
||||
type: 'mysql',
|
||||
host: configService.get<string>('DB_HOST', 'localhost'),
|
||||
port: Number(configService.get<string>('DB_PORT', '3306')),
|
||||
username: configService.get<string>('DB_USERNAME', 'root'),
|
||||
password: configService.get<string>('DB_PASSWORD', ''),
|
||||
database: configService.get<string>('DB_DATABASE', 'listify'),
|
||||
autoLoadEntities: true,
|
||||
synchronize: false,
|
||||
logging: parseDatabaseLogging(env.DB_LOGGING),
|
||||
logger: new DatabaseLogger(databaseLoggerOptionsFromEnv(env)),
|
||||
maxQueryExecutionTime: slowQueryThresholdFromEnv(env),
|
||||
};
|
||||
},
|
||||
}),
|
||||
EventEmitterModule.forRoot(),
|
||||
AuthModule,
|
||||
@@ -35,8 +58,4 @@ import { MailModule } from './mail/mail.module';
|
||||
controllers: [AppController],
|
||||
providers: [AppService],
|
||||
})
|
||||
export class AppModule {
|
||||
constructor(configService: ConfigService) {
|
||||
console.log(configService.get<string>('DB_HOST', 'localhost'))
|
||||
}
|
||||
}
|
||||
export class AppModule {}
|
||||
|
||||
Reference in New Issue
Block a user