babel-plugin-logger
v0.23.0
Published
Babel Plugin Logger
Downloads
8
Readme
babel-plugin-logger
🚀 babel-plugin to automatically insert logging code 🚀
Transform
/* BEFORE */
function multiply(n) {
try { } catch (e) {
}
return n * n
}
class A {
division(a, b) {
return a / b
}
}
/* AFTER (automatically insert logging code by babel-plugin-logger) */
function multiply(n) {
console.log('[/path/file.js:1]', '[fn] multiply() called with', 'n = [ ' + n + ' ]');
try {} catch (e) {
console.error('[/path/file.js:3]', '[fn] multiply() catch with', 'e = [ ' + e + ' ]');
}
return n * n;
}
class A {
division(a, b) {
console.log('[/path/file.js:10]', '[A] division() called with', 'a = [ ' + a + ' ],', 'b = [ ' + b + ' ]');
return a / b;
}
}
Sample
▼ group log template in browser
▼ default log template in command line
Installation
npm i -D babel-plugin-logger
# or
yarn add -D babel-plugin-logger
Setup
babel.config.js
module.exports = function (api) {
return {
"plugins": [ "logger" ]
}
}
.babelrc
{
"plugins": [
"logger"
]
}
ToDo
We welcome contributions to babel-plugin-logger in many forms
- [ ] Enable custom logging such as winston or bunyan or any logger through
require
option - [ ] Add a description of the options to the README.md
- [ ] Any feature you suggest!