/fn-logger

a logging utility that adds pretty colors and name of function called from

Primary LanguageJavaScript

FUNCTION LOGGER

A JavaScript logging utility that prints the name of the function from where it is called with an assigned pretty color.

  • It works in both node and browser environments;
  • Supported browsers are Chrome and Opera

RUN:

npm install fn-logger --save-dev

USAGE

  /** using es6 modules **/
  import logger from 'fn-logger'
  
  /** using commonJS modules **/
  const logger = require('fn-logger')
  
  function animal(type) {
    logger(type)
  }
    
  animal({type: 'cat', color: 'black'})

Browser
Alt text

Node
Alt text

    /** using es6 modules in browser environment **/  
    import logger from 'fn-logger'    
    
    /** using commonJS in node environment **/ 
    const logger= require('fn-logger')
    
    class Cat{
      constructor(name, age, breed) {
        this.name = name
        this.age = age
        this.breed = breed
      }
      getName() {
        logger('name -->', this.name)
      }
      getAge() {
        logger('age -->', this.age)
      }
      isBreed(type) {
        const isBreed = this.breed === type
        logger(`is breed ${type} ${isBreed}`)
      }
    }
    
    const cat = new Cat('Pippa', 1, 'siamese')
    cat.getName()
    cat.getAge()
    cat.isBreed('siamese')

Browser
Alt text

Node
Alt text