Skip to content
This repository has been archived by the owner on May 22, 2024. It is now read-only.

egomobile/api-log

Repository files navigation

npm last build PRs Welcome

@egomobile/api-log

A middleware for js-log, which sends logs to an API endpoint.

Install

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:

Configuration

  1. 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>
  2. Pass an object of type IUseApiLoggerOptions to useApiLogger

Usage

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');

Documentation

The API documentation can be found here.