chore(server): setup winston logger (#9561)

There is no impact on the existing logger, as the current logger is used with `new Logger(Context)` and does not utilize dependency injection. In the next phase, gradually replace and supplement the existing `Logger`.
This commit is contained in:
Brooooooklyn
2025-01-07 09:15:07 +00:00
parent 5e51018c03
commit 482b534a90
10 changed files with 518 additions and 16 deletions
@@ -0,0 +1,30 @@
import { LoggingWinston } from '@google-cloud/logging-winston';
import { ConsoleLogger, LoggerService, Provider, Scope } from '@nestjs/common';
import { createLogger, transports } from 'winston';
import { Config } from '../config';
import { AFFiNELogger } from './logger';
export const loggerProvider: Provider<LoggerService> = {
provide: AFFiNELogger,
useFactory: (config: Config) => {
if (config.NODE_ENV !== 'production') {
return new ConsoleLogger();
}
const loggingWinston = new LoggingWinston();
// Create a Winston logger that streams to Cloud Logging
const instance = createLogger({
level: config.affine.stable ? 'log' : 'verbose',
transports: [
new transports.Console(),
// Add Cloud Logging
loggingWinston,
],
});
return new AFFiNELogger(instance);
},
inject: [Config],
// use transient to make sure the logger is created for each di context
// to make the `setContext` method works as expected
scope: Scope.TRANSIENT,
};