Socket
Socket
Sign inDemoInstall

winston-koa-sse

Package Overview
Dependencies
49
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    winston-koa-sse

winston koa transport based on sse


Version published
Maintainers
1
Created

Readme

Source

winston-koa-sse

A winston transport for KOA applications that streams logs to your browser leveraging SSE

Installation

  $ npm install winston-koa-sse

  or

  $ yarn add winston-koa-sse

Usage

On the server-side:

  import winston from 'winston';
  import Koa from 'koa';
  import KoaRouter from 'koa-router';
  import { KoaSseMiddleware, KoaSseTransport } from 'winston-koa-sse';

  // Adds the transport to winston
  winston.add(KoaSseTransport);

  // Plug logs stream on route /logs
  const router = new KoaRouter();
  router.get('/logs', KoaSseMiddleware);

On the browser-side you need to consume logs using an EventSource object. Below a script that you can include in your page, assuming your node server is reachable at URl http://localhost:3000 :

    const streamUrl = 'http://localhost:3000';
    const source = new EventSource(streamUrl); 
    
    const levels = ['debug', 'info', 'warn', 'error', 'fatal'];
    levels.forEach(level => {
        source.addEventListener(level, function(event) {
            console[level](event.data);
        });
    });

You can also use a bookmarklet to execute this script. Below the same script in a bookmarklet flavor:

javascript: (function(){const streamUrl = 'http://localhost:3000'; const source = new EventSource(streamUrl); const levels = ['debug', 'info', 'warn', 'error', 'fatal']; levels.forEach(level => { source.addEventListener(level, function(event) { console[level](event.data); }); });})();

Disclaimer

  1. For obvious security concerns, do not activate it in production!
  2. This is a first basic not opimized implementation, no batching of log messages, etc

FAQs

Last updated on 18 Jul 2018

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc