Coder Social home page Coder Social logo

nuxt-browser-console's Introduction

nuxt-browser-console

npm version npm downloads Github Actions CI Codecov License

receive server-side and client-side logs/errors/warnings inside the browser console

โš ๏ธ If you are using nuxt 3, see the next branch

With this module, you can use browser console methods. No matter you are using this module inside the server or client, the messages are always shown in the browser console. A good and cheap way to monitoring server events in the production environment (for example, Axios request and response information can be logged into the browser console).

๐Ÿ“– Release Notes

Setup

  1. Add nuxt-browser-console dependency with yarn or npm to your project
yarn add nuxt-browser-console # or npm install nuxt-browser-console
  1. Add nuxt-browser-console to the modules section of nuxt.config.js
{
  modules: [
    // Simple usage
    'nuxt-browser-console',

    // With options
    ['nuxt-browser-console', { /* module options */ }]
  ],
  browserConsole: {
    /* module options */
  }
}

Options

Module default options:

Option Default Description
namespace console the namespace of the module. this.$console.log(...) or $console.log(...) inserted fom nuxt context
{
  browserConsole: {
    namespace: 'console'
  }
}

Usage

You can simply use this module through this or context $console almost every where in your Nuxt app.

  this.$console.log(...args)

Available methods:

$console.log(obj1 [, obj2, ..., objN])
$console.info(obj1 [, obj2, ..., objN])
$console.warn(obj1 [, obj2, ..., objN])
$console.error(obj1 [, obj2, ..., objN])
$console.clear()
$console.groupCollapsed([label])
$console.groupEnd()

An example to show how to use this module to log some data inside the browser (no matter server-side/client-side).

export default function ({$axios, $console}) {

  const style = "background: #d32f2f;border-radius: 0.5em;color: white;font-weight: bold;padding: 2px 0.5em;";

  $axios.interceptors.response.use((x) => {
    $console.groupCollapsed('', `%cRequest to ${x.config.url.split("?")[0]}`, style);

    $console.info('URL:', `${x.config.baseURL}${x.config.url}`);

    $console.info('Method:', x.config.method.toUpperCase());

    $console.info('Status:', `${x.statusText || 'OK'} (${x.status})`);
    
    $console.groupEnd();

    return x;
  });
}

Development

  1. Clone this repository
  2. Install dependencies using yarn install or npm install
  3. Start development server using yarn dev or npm run dev

Todo

  • error stack trace correction
  • module separation

License

MIT License

Copyright (c) Mohammad Saleh Fadaei (@ms-fadaei)

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.