babel-plugin-simple-logger
v1.1.1
Published
A Babel plugin which provides a convenient syntax for logging from within JavaScript functions.
Downloads
115
Maintainers
Readme
babel-plugin-simple-logger
Special thanks to Michael Jungo for helping me put the first version together.
This Babel plugin looks for the string literal "log"
after the opening bracket of a function and replaces it with console.log(<function name>, <arg1>, <arg2>, etc...)
.
const add = (a, b) => { 'log'
return a + b
}
// becomes...
const add = (a, b) => {
console.log('add', a, b)
return a + b
}
Installation & Usage
Install the package
yarn add babel-plugin-simple-logger --dev
Incorporate the plugin
// .babelrc
...
"env": {
"development": {
"presets": ["react", "env", "stage-0"],
"plugins": ["simple-logger"]
},
...
}
Test it out
function greeter(name='world') { 'log'
return `Hello, ${name}!`
}
greeter("Gus")
// logs...
greeter "Gus"
Note: Arrow functions with implicit returns (e.g. (a, b) => a + b
) aren't candidates for logging with this plugin's syntax.