GithubHelp home page GithubHelp logo

isabella232 / console-plus Goto Github PK

View Code? Open in Web Editor NEW

This project forked from avocode/console-plus

0.0 0.0 0.0 111 KB

New levels + colors to Console. Works in both the browser and node.js.

CoffeeScript 100.00%

console-plus's Introduction

Console Plus

npm install cplus

Build Status

  • Adds more console log levels: fatal, error, warn, info, log, debug, trace, silly.

  • Makes the console output pretty, styled and prefixed by the log level:

    Console Output

  • Allows log level limit (option: logLevel). NOTE: This will only work with built-in transports. So if you override it with your own transport (using transport option), you have to handle the logic in there.

    // Only display log levels `warn` and more severe (`error`, `fatal`).
    cplus.install({
      logLevel: cplus.LogLevels.WARN
    })
  • Certain log levels can optionally be left untouched (option: untouchedLogLevels).

    // Do not touch console.error() to keep clickable stack traces.
    cplus.install({
      untouchedLogLevels: [ cplus.LogLevels.ERROR ]
    })
  • You can also pass your own custom transport (option: transport).

    const myCustomTransportInstance = new CustomTransport()
    
    cplus.install({
      transport: myCustomTransportInstance
    })
  • If you want to get built-in transport that is already set-up with default configuration you can use factories createBrowserTransport or createCliTransport to get transport instance (this factory does not take any arguments). This is useful if you still want to use cplus logging but you may wish to capture or modify the incoming data:

    import { createCliTransport } from 'cplus'
    
    
    // ...
    
    class CustomTransport {
      constructor() {
        this._cliTransport = createCliTransport() 
      }
    
      logMessage(logLevel, ...args) {
        // do my own stuff here
        const cleanData = convertData(args)
    
        this._cliTransport.logMessage(logLevel, cleanData)
      }
    }
  • If you want to access built-in transports directly, you can do that. Just import transports object that contains BrowserTransport and CliTransport constructors.

  • If you need to switch from built-in transport for Logger (perhaps after initialization or right after installing cplus), you can do so by calling setTransport:

  import cplus from 'cplus'

  cplus.install({
    untouchedLogLevels: [ cplus.LogLevels.ERROR, cplus.LogLevels.TRACE ],
  })

  // after the installation phase, instance of logger will be avaible in browser
  // like this
  const logger = window.console.logger

  // create your own instance of custom transport
  const customTransport = new CustomTransport()

  // switch from built-in transport to your custom one
  logger.setTransport(customTransport)

Usage

import cplus from 'cplus'

// Plain/default installation:
cplus.install()

// Custom installation:
cplus.install({ /* options */ })

Licence

MIT

console-plus's People

Contributors

comatory avatar jakubzitny avatar jankuca avatar vojtatranta 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.