A middleware for js-log, which sends logs to an API endpoint.
Execute the following command from your project folder, where your package.json
file is stored:
npm install --save @egomobile/api-log
The following modules are defined in peerDependencies and have to be installed manually:
-
Configure with environment variables. Add the following environment variables to your file.
ENVIRONMENT=<env> LOGS_SERVICE_URL=<url> LOGS_SERVICE_KEY=<key> LOGS_SERVICE_CLIENT=<client>
-
Pass an object of type IUseApiLoggerOptions to
useApiLogger
import log, { consoleLogger, useFallback } from '@egomobile/log';
import { useApiLogger } from "@egomobile/api-log";
// reset the logger to configure it from scratch.
log.reset();
// use api logger as first middleware and console logger as a fallback.
log.use(useFallback(
useApiLogger(),
consoleLogger()
));
/**
* add environment and severity properties and send request to logs-service.
*/
log.debug({
message: 'some message',
details: 'some details'
});
/**
* since version 0.2.0, this package supports plain strings.
*
* if only string is passed, it will be converted into an object.
*
* example: 'a random string' becomes
*
* {
* message: 'a random string',
* details: 'a random string'
* }
*/
log.debug('a random string');
The API documentation can be found here.