Socket
Book a DemoInstallSign in
Socket

@genie-solutions/genie-logger

Package Overview
Dependencies
Maintainers
9
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@genie-solutions/genie-logger

Reusable Node.js logger for platform Lambda services.

latest
npmnpm
Version
1.0.2
Version published
Maintainers
9
Created
Source

Genie logger Library for Node.js services

Reusable Node.js logger for platform Lambda services.

Installing

To install this library into your project

$ npm i @genie-solutions/genie-logger

Dependencies

This library is built using uuid, winston and winston-transport

Basic Examples

    import { createLoggerFromContext } from "./services/logging";
  
    const createLogger = createLoggerFromContext(APP_NAME, STAGE, LOG_LEVEL);

    const logger = createLogger(context.awsRequestId);

    logger.info({
      type: EventType.CreditAssessed,
      payload: {
        threadId,
        tenantId,
        creditBalance,
        calculatedCost: cost
      }
    });

    logger.error({
      type: EventType.CreditServiceError,
      error: { message: error.message }
    });

    logger.warn({
      type: EventType.CreditServiceWarning,
      error: { message: error.message }
    });
    logger.debug({
      type: EventType.CreditServiceDebug,
      error: { message: error.message }
    });

Profiling Examples

    //
    // Start profile of 'test'
    //
    logger.profile('test');
    
    setTimeout(function () {
      //
      // Stop profile of 'test'. Logging will now take place:
      //   '17 Jan 21:00:00 - info: test duration=1000ms'
      //
      logger.profile('test');
    }, 1000);

This will output {"level":"info","durationMs":2311,"message":"test"} in the log

Profiling Timer example

     // Returns an object corresponding to a specific timing. When done
     // is called the timer will finish and log the duration. e.g.:
     //
     const profiler = logger.startTimer();
     setTimeout(function () {
       profiler.done({ message: 'Logging message' });
     },

This will output {"message":"Logging message","level":"info","durationMs":14990} in the log

Extra metadata inthe log

The default logger will include the three parameter metadata(APP_NAME, STAGE, LOG_LEVEL) in the log, to extend this with extra metadata, use the extend function

  const logger = createLogger(context.awsRequestId).extend(
    pick({ requestId: "451" })
  );

  logger.info("Child logging");

This will output following log:

{"requestId":"451","message":"Child logging","level":"info"}

Keywords

Genie

FAQs

Package last updated on 21 Dec 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts