Socket
Socket
Sign inDemoInstall

@okrahq/logger

Package Overview
Dependencies
189
Maintainers
7
Versions
3
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @okrahq/logger

Custom logger based on winston logging library. This library empowers projects to define their own format for printing the logs.


Version published
Maintainers
7
Created

Readme

Source

logger

Logger is Okra's custom logger built on top of Winston logger. Logger is written in typescript and is available for the typescript and javascript repositories. It allows developers to define a log transformation function to transform the logs in a particular format. This format can include metadata like requestId, customerId, partnerId, and many more.

Usage

Without log transform function:
// import logger 
const Logger = require('@okra/logger').default;
    
const logger = new Logger(logTransform, metadata);
logger.info('We welcome you to Okra!');   // logs We welcome you to Okra! to terminal in green color.
logger.debug('We welcome you to Okra!');  // logs We welcome you to Okra! to terminal in blue color.
logger.warn('We welcome you to Okra!');   // logs We welcome you to Okra! to terminal in yellow color.
logger.error('We welcome you to Okra!');  // logs We welcome you to Okra! to terminal in red color.

With log transform function:
// import logger 
const Logger = require('@okra/logger').default;

// declare metadata. Metadata can be any JSON object that holds the necessary details required in log format. 
const metadata = {
    customerId: 121321324,
    requestId: OKR-JN2323424,
};

// define logTransform() to return the desired format for logs.
const logTransform = (message: string, metadata: Metadata): string =>
    `customerId: ${metadata.customerId} | requestId: ${metadata.requestId} | message: ${message}`;
    
const logger = new Logger(logTransform, metadata);
logger.info('We welcome you to Okra!');   // 2022-02-02T14:19:08+05:30 - INFO: timestamp: 2022-02-02T14:19:08+05:30 | customerId: 121321324 | requestId: OKR-JN2323424 | message: We welcome you to Okra! (in green color)
logger.debug('We welcome you to Okra!');  // 2022-02-02T14:19:08+05:30 - INFO: timestamp: 2022-02-02T14:19:08+05:30 | customerId: 121321324 | requestId: OKR-JN2323424 | message: We welcome you to Okra! (in blue color)
logger.warn('We welcome you to Okra!');   // 2022-02-02T14:19:08+05:30 - INFO: timestamp: 2022-02-02T14:19:08+05:30 | customerId: 121321324 | requestId: OKR-JN2323424 | message: We welcome you to Okra! (in yellow color)
logger.error('We welcome you to Okra!');  // 2022-02-02T14:19:08+05:30 - INFO: timestamp: 2022-02-02T14:19:08+05:30 | customerId: 121321324 | requestId: OKR-JN2323424 | message: We welcome you to Okra! (in red color)

Keywords

FAQs

Last updated on 08 Aug 2022

Did you know?

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc