Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
.key]: InvocationLoggingInterceptor,
};
if (loggingConfig.enableHttpAccessLog) {
this.providers[
LoggingBindings.WINSTON_HTTP_ACCESS_LOGGER.key
] = HttpAccessLogInterceptor;
}
if (loggingConfig.enableFluent) {
this.providers[LoggingBindings.FLUENT_SENDER.key] = FluentSenderProvider;
// Only create fluent transport if it's configured
this.bindings = [
Binding.bind(LoggingBindings.WINSTON_TRANSPORT_FLUENT)
.toProvider(FluentTransportProvider)
.apply(extensionFor(WINSTON_TRANSPORT)),
];
}
}
}
it('creates a winston logger with formats', async () => {
ctx.bind(LoggingBindings.WINSTON_LOGGER).toProvider(WinstonLoggerProvider);
ctx.configure(LoggingBindings.WINSTON_LOGGER).to({
level: 'info',
defaultMeta: {framework: 'LoopBack'},
});
const logs: WinstonLogRecord[] = [];
const myFormat: WinstonFormat = format((info, opts) => {
logs.push(info);
return false;
})();
ctx
.bind('logging.winston.formats.myFormat')
.to(myFormat)
.apply(extensionFor(WINSTON_FORMAT));
ctx
.bind('logging.winston.formats.colorize')
.to(format.colorize())
.apply(extensionFor(WINSTON_FORMAT));
const logger = await ctx.get(LoggingBindings.WINSTON_LOGGER);
logger.log('info', 'Hello, LoopBack!');
expect(logs).to.eql([{level: 'info', message: 'Hello, LoopBack!'}]);
});
it('creates a winston logger with transports', async () => {
ctx.bind(LoggingBindings.WINSTON_LOGGER).toProvider(WinstonLoggerProvider);
ctx.configure(LoggingBindings.WINSTON_LOGGER).to({
level: 'info',
format: format.json(),
defaultMeta: {framework: 'LoopBack'},
});
const consoleTransport = new WinstonTransports.Console({
level: 'info',
format: format.combine(format.colorize(), format.simple()),
});
ctx
.bind('logging.winston.transports.console')
.to(consoleTransport)
.apply(extensionFor(WINSTON_TRANSPORT));
const logger = await ctx.get(LoggingBindings.WINSTON_LOGGER);
expect(logger.transports).to.eql([consoleTransport]);
});
export const asGreeter: BindingTemplate = binding => {
extensionFor(GREETER_EXTENSION_POINT_NAME)(binding);
binding.tag({namespace: 'greeters'});
};
export const asModelApiBuilder: BindingTemplate = binding => {
extensionFor(MODEL_API_BUILDER_PLUGINS)(binding);
binding.tag({namespace: 'model-api-builders'});
};
const asRecommenderService: BindingTemplate = binding => {
extensionFor(RECOMMENDER_SERVICE)(binding);
binding.tag({protocol}).inScope(BindingScope.SINGLETON);
};
return asRecommenderService;