Code Monkey home page Code Monkey logo

nicer-log's Introduction

Nicer-log Build Status npm version

A nicer replacement of console.log.

Used by Shopee ISFE Team and Shopee React Native Team.

  • Prints log with color group labels
  • Logs the status of Promises or asynchronous functions
  • Filters logs in Developer Tools, OR
  • Filters logs by whitelist / blacklist
  • Can be removed completely in production by using Babel/TypeScript transformers

Install

npm install --save nicer-log

Usage

Print a log

import nicerLog from "nicer-log";
const log = nicerLog("App");

log("Initializing...");

Log Promises

import nicerLog from "nicer-log";
import { fetchUserInfo } from "./api";
const log = nicerLog("User");

const promise = fetchUserInfo();
log.async("Fetching user info", promise);

Filter logs

Just use built-in filter features to temporarily filter logs.

Setup whitelist or blacklist

import { setNicerLogBlacklist, setNicerLogWhitelist } from "nicer-log";

setNicerLogWhitelist(["App", "User", "DashboardReducer"]);
setNicerLogBlacklist(["User"]);

Remove nicer-log in Production

nicer-log provides plugins to remove nicer-log for Babel and TypeScript.

Using Babel

Install the babel plugin

npm install --save-dev nicer-log-remover-babel

Edit your .babelrc to enable the plugin

{
  "plugins": ["module:nicer-log-remover-babel"]
}

Using TypeScript

Install the TypeScript plugin

npm install --save-dev nicer-log-remover-typescript

tsc doesn't seem to support custom transformers yet. You might want to use the transformer with third-party loaders. Config for webpack and ts-loader for example:

const nicerLogRemover = require("nicer-log-remover-typescript").default;

module.exports = {
  //...
  module: {
    rules: [
      {
        test: /\.tsx?$/,
        loader: "ts-loader",
        options: {
          getCustomTransformers() {
            return {
              before: [nicerLogRemover]
            };
          }
        }
      }
    ]
  }
  // ...
};

License

MIT License © Zhongliang Wang

nicer-log's People

Contributors

cryrivers 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.