Git Product home page Git Product logo

lamlog's Introduction

lamlog

Simple logging solution for Node.js AWS Lambda projects. Focus on brevity, ie a tiny code footprint.

Usage

Child

Gets a child logger that will contain the parent history for each logging statement of that child. This allows you to track the specific path of execution that resulted in the logging statement.

Timer

To measure the amount of time elapsed between to points, first call const myTimer = logger.timer('nameOfTimer) then when you are ready to print out the time to console simply pass the timer as an argument to any of the logging methods such as debug logger.debug('My Timer',myTimer).

Levels

This has a progressive level of logging that allows you to change the verbosity of your application depending on the current runtime needs. For exmaple, you set your logging level to 'error' nothing below that point will be reported to the console.

Each logging statement matches console.log, in that you can pass in a message and an object. In fact, under the covers, it is only using console.log or console.error, just with a bit of formatting help and stops to help with verbosity.

  1. trace() - Intimate application behavior for a specific module.
  2. debug() - Detailed 'general' application behavior.
  3. info() - Configuration information.
  4. log() - Synonym for info, to be consistent with console.
  5. warn() - Problematic behavior that isn't application fatal.
  6. error() - Broken or failed behavior.
const Logger = require('lamlog');
const logger = new Logger({name:'Parent',level:'trace'});

/*
 * Changes the logging level.
 */
logger.setLevel('warn');

logger.trace(`My message ${variable} value.`);
logger.trace('My message',variable);

logger.debug(`My message ${variable} value.`);
logger.debug('My message',variable);

logger.info(`My message ${variable} value.`);
logger.info('My message',variable);

logger.log(`My message ${variable} value.`);
logger.log('My message',variable);

logger.warn(`My message ${variable} value.`);
logger.warn('My message',variable);

logger.error(`My message ${variable} value.`);
logger.error('My message',variable);

Timer

Allows for easy reporting on the duration of execution of code. Each timing is a point in time, so it can be safely passed into paralelle or promise chains to be referenced at multiple points in time.

const Logger = require('lamlog');
const logger = new Logger({name:'Parent',level:'trace'});

function SuperSpecial(_logger) {
  /*
   * Will take on the logging level of its parent logger, and each logging
   *  statement will reflect the object chain.
   */
  const logger = _logger.child({name:'SuperSpecial'});
  
  /*
   * Records the current time, so it can be reported in a logging statement later.
   */
  const timing = logger.timer('NameOfTimer');
  
  /*
   * A timer can be reported directly in a logging statment and 
   *  reported appropriately.
   */
  logger.info(timing);
  //2017-03-18T07:47:03.512Z [info]	Parent.SuperSpecial	NameOfTimer took 0.195009ms
}
import * as Config from 'lamcfg';
const logger = new Logger({name:'Parent',level:'trace'});

class SuperSpecial {

  constructor(_logger){
    this.logger = _logger.child("SuperSpecial");
  }

  superSpecial():void {
      
    /*
    * Records the current time, so it can be reported in a logging statement later.
    */
    const timing = logger.timer('NameOfTimer');
    
    /*
    * A timer can be reported directly in a logging statment and 
    *  reported appropriately.
    */
    logger.info(timing);
    //2017-03-18T07:47:03.512Z [info]	Parent.SuperSpecial	NameOfTimer took 0.195009ms
  }
}

lamlog's People

Contributors

matt-filion avatar

Stargazers

Jacob Montgomery avatar Jens Krefeldt avatar Mohamed Ameen Omar avatar Natan Deitch avatar Igor Goltsov avatar

Watchers

Igor Goltsov avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.