Skip to content

Commit

Permalink
feat: provide default logger without logging
Browse files Browse the repository at this point in the history
  • Loading branch information
Velmisov committed Jul 8, 2020
1 parent 0f05023 commit 397af89
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 32 deletions.
63 changes: 31 additions & 32 deletions src/lib/global-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { ConfigParser } from './parser';
import { ConfigFactory } from './factory';
import { ConfigValidator } from './validator';
import { CONFIG_LOGGER, CONFIG_OPTIONS } from '../tokens';
import { ConfigLogger } from './logger';

@Global()
@Module({
Expand Down Expand Up @@ -53,42 +54,40 @@ export class ConfigGlobalModule {
if (!providers.find((provider) => provider.provide === CONFIG_LOGGER)) {
providers.push({
provide: CONFIG_LOGGER,
useValue: console,
useClass: ConfigLogger,
});
}

providers.push(
...[
{
provide: CONFIG_OPTIONS,
useValue: options,
},
{
provide: ConfigFacade,
inject: [
ConfigExtractor,
ConfigParser,
ConfigFactory,
ConfigValidator,
CONFIG_LOGGER,
],
useFactory: (
configExtractor: ConfigExtractor,
configParser: ConfigParser,
configFactory: ConfigFactory,
configValidator: ConfigValidator,
logger: LoggerService,
) =>
new ConfigFacade(
configExtractor,
configParser,
configFactory,
configValidator,
logger,
options.fromFile,
),
},
],
{
provide: CONFIG_OPTIONS,
useValue: options,
},
{
provide: ConfigFacade,
inject: [
ConfigExtractor,
ConfigParser,
ConfigFactory,
ConfigValidator,
CONFIG_LOGGER,
],
useFactory: (
configExtractor: ConfigExtractor,
configParser: ConfigParser,
configFactory: ConfigFactory,
configValidator: ConfigValidator,
logger: LoggerService,
) =>
new ConfigFacade(
configExtractor,
configParser,
configFactory,
configValidator,
logger,
options.fromFile,
),
},
);

return {
Expand Down
14 changes: 14 additions & 0 deletions src/lib/logger.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/* eslint-disable */
import { LoggerService } from '@nestjs/common';

export class ConfigLogger implements LoggerService {
log(message: any, context?: string): any {}

error(message: any, trace?: string, context?: string): any {}

warn(message: any, context?: string): any {}

debug(message: any, context?: string): any {}

verbose(message: any, context?: string): any {}
}

0 comments on commit 397af89

Please sign in to comment.