mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-25 22:38:56 +08:00
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:
@@ -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,
|
||||
};
|
||||
Reference in New Issue
Block a user