babel-plugin-logger

Babel Plugin Logger

Usage no npm install needed!

<script type="module">
  import babelPluginLogger from 'https://cdn.skypack.dev/babel-plugin-logger';
</script>

README

babel-plugin-logger

NPM version Build Status Dependency Status Coverage percentage

🚀 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

group-sample-browser

â–¼ default log template in command line

!default-sample-cli

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!

License

MIT © Ryan Yang