@bizcuit/logger
TypeScript icon, indicating that this package has built-in type declarations

2.0.1 • Public • Published

logger

Logger using Pino, use with lambdas

Usage

import { log, sniff, logFatalAndReturn } from '@bizcuit/logger';

// Logger basic useage
log.trace({ logData }, 'Logging some important string we need');        // Level 10
log.debug({ logData }, 'Logging some important string we need');        // Level 20
log.info({ logData }, 'Logging some important string we need');         // Level 30
log.warn({ logData }, 'Logging some important string we need');         // Level 40

// Error should always take as first argument an Error object
// (or a custom Error message which inherits from Error)
log.error(new Error('My err message'), 'Extra message if desired')      // Level 50
// OR
(new Promise((res, rej) => rej(new Error('My err'))))
    .catch(err => log.error(err, 'Extra message if desired'));          // Level 50

log.fatal({ logData }, 'Logging some important string we need');        // Level 60

/**
 * @note
  * The format of this message in a `log.event` call is **EXCEPTIONALLY** important
  * It is the message that is entered here that will be what other parts of the system
  * will filter on to receive the event generated by this lambda.
  * If it's not in this format it will simply be discarded
  * Similarly the event **must** be called `event` and wrapped in an object, else discarded
  */
log.event({ event }, 'SERVICE|FUNCTION');

// Sniffing out data from inside promise chains
const spicyDataPromise = new Promise.resolve({ spicyData: '🌶' });

spicyDataPromise.then(sniff('debug', 'Logging the contents of SpicyDataPromise', 'spicyData'))
  .then(doSomethingElse);

// LogFatalAndReturn
const { SHOULD_NOT_BE_UNDEFINED } = process.env;

if (isUndefined(SHOULD_NOT_BE_UNDEFINED)) logFatalAndReturn('A required env var was not present');

Readme

Keywords

none

Package Sidebar

Install

npm i @bizcuit/logger

Weekly Downloads

0

Version

2.0.1

License

MIT

Unpacked Size

10.2 kB

Total Files

14

Last publish

Collaborators

  • catalinbizcuit
  • santiago-bizcuit
  • bizcuit-operations
  • giedrius-bizcuit
  • jlp-bizcuit
  • guillermo.l
  • elad-tsruya-bizcuit
  • younesea