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
npm install fn-logger --save-dev
/** 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'})
/** 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')