Git Product home page Git Product logo

babel-plugin-logger's Introduction

babel-plugin-logger

The babel plugin replaces custom log functions with custom logger invocations.
The first argument would be provided with a code location description. You don't need anymore to write imports and hardcode function names or line numbers.
Comes in handy for ReactNative applications when it's not possible to retrieve code information in runtime.

How to install

npm: npm i -D davinctor/babel-plugin-logger#main
yarn: yarn add 'babel-plugin-logger@https://github.com/davinctor/babel-plugin-logger#head=main'

How to use it?

The plugin transforms invocation from:

function somethingV() {
  logV("hello");
  var x = 2;
}

to (the output would be)

function somethingV() {
  Logger.logV(
    {
      file: "test/fixtures/logger/code.js",
      func: "somethingV",
      line: 4,
    },
    "hello",
    "app"
  );
  var x = 2;
}

This sample requires babel plugin to have the proper configuration. It should have functionsNames plugin configuration property, in this case it should be functionNames: ['logV'] at least.

Configuration

Sample of plugin configuration:

{
  plugins: [
    [
      'logger',
      {
        importPath: "core/logger",
        functionsNames: ["logV", "logI", "logW", "logE"],
        defaultGroupName: "app",
        exclude: ["node_modules"]
      },
    ]
  ]
}

Plugin options

  • importPath - the custom logger implementation file path (could be relative) (required)
  • functionNames - the custom logger implementation methods (required)
  • defaultGroupName - the logger default group name when is not provided (required)
  • isClass - helps plugin to understand how to import log functions. Default value is false.
  • exclude - the list of file patterns should be excluded from traversing (transforming) process

Running the tests

yarn test or npm run test

babel-plugin-logger's People

Contributors

davinctor avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.