diff --git a/extensions/logging/README.md b/extensions/logging/README.md index 04e61629ab81..b7e65d942fa6 100644 --- a/extensions/logging/README.md +++ b/extensions/logging/README.md @@ -34,6 +34,74 @@ In the constructor, add the component to your application: this.component(LoggingComponent); ``` +The component contributes bindings with keys listed below: + +- LoggingBindings.FLUENT_SENDER - A fluent sender +- LoggingBindings.WINSTON_LOGGER - A winston logger +- LoggingBindings.WINSTON_TRANSPORT_FLUENT - A fluent transport for winston + +The fluent sender and transport for winston can be configured against +`LoggingBindings.FLUENT_SENDER`: + +```ts +import {LoggingBindings} from '@loopback/extension-logging'; + +app.configure(LoggingBindings.FLUENT_SENDER).to({ + host: process.env.FLUENTD_SERVICE_HOST || 'localhost', + port: +(process.env.FLUENTD_SERVICE_PORT_TCP || 0) || 24224, + timeout: 3.0, + reconnectInterval: 600000, // 10 minutes +}); +``` + +The winston logger can be configured against `LoggingBindings.WINSTON_LOGGER`: + +```ts +import {LoggingBindings} from '@loopback/extension-logging'; + +ctx.configure(LoggingBindings.WINSTON_LOGGER).to({ + level: 'info', + format: format.json(), + defaultMeta: {framework: 'LoopBack'}, +}); +``` + +The winston logger accepts two types of extensions to the following extension +points: + +- WINSTON_TRANSPORT = 'logging.winston.transport' +- WINSTON_FORMAT = 'logging.winston.format' + +```ts +import {extensionFor} from '@loopback/core'; +import {format} from 'winston'; +import {WINSTON_FORMAT, WINSTON_TRANSPORT} from '@loopback/extension-logging'; + +const myFormat: Format = ...; + +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)); +``` + +## Start fluentd as a Docker container for testing + +For mocha tests, we use +[testcontainers](https://github.com/testcontainers/testcontainers-node) to +start/stop the fluentd docker container automatically. + +There are also scripts in `fixtures` directory: + +- start-fluentd.sh +- stop-fluentd.sh + +The fluentd configuration is read from `fixtures/etc/fluentd.conf`. + ## Contributions - [Guidelines](https://github.com/strongloop/loopback-next/blob/master/docs/CONTRIBUTING.md)