项目作者: ms-fadaei

项目描述 :
See server-side reports inside browser console
高级语言: JavaScript
项目地址: git://github.com/ms-fadaei/nuxt-browser-console.git
创建时间: 2021-04-27T19:13:57Z
项目社区:https://github.com/ms-fadaei/nuxt-browser-console

开源协议:MIT License

下载


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
  1. yarn add nuxt-browser-console # or npm install nuxt-browser-console
  1. Add nuxt-browser-console to the modules section of nuxt.config.js
  1. {
  2. modules: [
  3. // Simple usage
  4. 'nuxt-browser-console',
  5. // With options
  6. ['nuxt-browser-console', { /* module options */ }]
  7. ],
  8. browserConsole: {
  9. /* module options */
  10. }
  11. }

Options

Module default options:

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

Usage

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

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

Available methods:

  1. $console.log(obj1 [, obj2, ..., objN])
  2. $console.info(obj1 [, obj2, ..., objN])
  3. $console.warn(obj1 [, obj2, ..., objN])
  4. $console.error(obj1 [, obj2, ..., objN])
  5. $console.clear()
  6. $console.groupCollapsed([label])
  7. $console.groupEnd()

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

  1. export default function ({$axios, $console}) {
  2. const style = "background: #d32f2f;border-radius: 0.5em;color: white;font-weight: bold;padding: 2px 0.5em;";
  3. $axios.interceptors.response.use((x) => {
  4. $console.groupCollapsed('', `%cRequest to ${x.config.url.split("?")[0]}`, style);
  5. $console.info('URL:', `${x.config.baseURL}${x.config.url}`);
  6. $console.info('Method:', x.config.method.toUpperCase());
  7. $console.info('Status:', `${x.statusText || 'OK'} (${x.status})`);
  8. $console.groupEnd();
  9. return x;
  10. });
  11. }

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)