fn-logger
v1.0.4
Published
a logging utility that extends console.log by adding the function name from where the log was called from with an assigned pretty color
Downloads
13
Readme
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')
/** using script tag **/
<script src="node_modules/fn-logger/index.js"></script>
function animal(type) {
logger(type)
}
animal({type: 'cat', color: 'black'})
Browser
Node
Or import at the root of your project and then save to window to use without having to import it into every file:
/** using es6 modules in browser environment **/
import logger from 'fn-logger'
window.logger = logger //or window.whateverName = logger
/** using commonJS in node environment **/
const logger= require('fn-logger')
global.logger = 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
Node