winston-koa-sse
A winston transport for KOA applications that streams logs to your browser leveraging SSE
Installation
$ npm install winston-koa-sseor$ yarn add winston-koa-sse
Usage
On the server-side:
;;;;// Adds the transport to winstonwinston;// Plug logs stream on route /logsconst router = ;router;
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 = streamUrl;const levels = 'debug' 'info' 'warn' 'error' 'fatal';levels;
You can also use a bookmarklet to execute this script. Below the same script in a bookmarklet flavor:
javascript: {const streamUrl = 'http://localhost:3000'; const source = streamUrl; const levels = 'debug' 'info' 'warn' 'error' 'fatal'; levels;};
Disclaimer
- For obvious security concerns, do not activate it in production!
- This is a first basic not opimized implementation, no batching of log messages, etc