When writing logs from sync typeORM NestJS to a file logger: "file", an error occurs

Viewed 27

When writing logs from sync typeORM to a file, an error occurs:

error TS2322: Type '(config: ConfigService) => Promise<{ type: "postgres"; host: string; port: number; password: string; username: string; database: string; logging: string[]; maxQueryExecutionTime: number; logger: string; subscribers: (typeof TruckSubscriber | typeof RequestSubscriber)[]; entities: (typeof Request | ... 14 more ... | ...' is not assignable to type '(...args: any[]) => TypeOrmModuleOptions | Promise<TypeOrmModuleOptions>'



 useFactory: getTypeormConfig, //: Promise<TypeOrmModuleOptions>
     ~~~~~~~~~~
node_modules/@nestjs/typeorm/dist/interfaces/typeorm-options.interface.d.ts:44:5
    44     useFactory?: (...args: any[]) => Promise<TypeOrmModuleOptions> | TypeOrmModuleOptions;
           ~~~~~~~~~~
    The expected type comes from property 'useFactory' which is declared here on type 'TypeOrmModuleAsyncOptions'

From the TypeORM documentation: You can enable any of them in the data source options:

{
    host: "localhost",
    ...
    logging: true,
    logger: "file"
}

This doesn't work for me - exactly logger: "file" doesn't work. logging: true, works successfully logging also doesn't work: ['error', 'schema', 'warn'],

1 Answers

I solved the problem:

     { host: "localhost",
       ...
       logging: ['query'] as LoggerOptions,
       logger: 'file' as const
     }

New issue log file is created in project root and no settings override save file path.

Related