diff --git a/packages/server/src/node/di/app-module.ts b/packages/server/src/node/di/app-module.ts index 8404d62..eec57d6 100644 --- a/packages/server/src/node/di/app-module.ts +++ b/packages/server/src/node/di/app-module.ts @@ -16,7 +16,7 @@ import { BindingContext } from '@eclipse-glsp/protocol/lib/di'; import { ContainerModule } from 'inversify'; import * as winston from 'winston'; -import { InjectionContainer, LogLevel, Logger, LoggerFactory, getRequestParentName } from '../../common'; +import { InjectionContainer, LogLevel, Logger, LoggerFactory, NullLogger, getRequestParentName } from '../../common'; import { LaunchOptions } from '../launch/cli-parser'; import { WinstonLogger } from './winston-logger'; @@ -74,7 +74,6 @@ export function configureWinstonLogger( rebind = true, baseLoggerCreator: (launchOptions: T) => winston.Logger = createWinstonInstance ): void { - const baseLogger = baseLoggerCreator(options); if (rebind) { if (context.isBound(Logger)) { context.unbind(Logger); @@ -83,11 +82,19 @@ export function configureWinstonLogger( context.unbind(LoggerFactory); } } - - context.bind(Logger).toDynamicValue(dynamicContext => new WinstonLogger(baseLogger, getRequestParentName(dynamicContext))); context.bind(LoggerFactory).toFactory(dynamicContext => (caller: string) => { const logger = dynamicContext.container.get(Logger); logger.caller = caller; return logger; }); + + // if no logging is enabled, bind the NullLogger + if (!options.consoleLog && !options.fileLog) { + context.bind(Logger).to(NullLogger).inSingletonScope(); + return; + } + + const baseLogger = baseLoggerCreator(options); + + context.bind(Logger).toDynamicValue(dynamicContext => new WinstonLogger(baseLogger, getRequestParentName(dynamicContext))); }