winston-socket.io
TypeScript icon, indicating that this package has built-in type declarations

1.2.0 • Public • Published

winston-socket.io

Build Status

A socket.io transport for winstonjs. Gives you the ability to log directly to a socket.io server.

See the examples folder for more usage details.

Options

  • host: The hostname of the socket.io server (default: "").
  • port: The port of the socket.io server (default: 3000).
  • url: The url you wish to connect to (will override host and port options) (default: "").
  • secure: Use https for the socket.io server connection (will be overriden by url option) (default: false).
  • namespace: The socket.io namespace to use for the logs (default: "log").
  • log_topic: The topic to send the log messages on (default: "log").
  • log_format: The format in which to log the information.
  • batch: whether or not to batch log messages and send them out in groups instead of immediately when logging (default: false)
  • batch_interval: amount of time in ms to wait after logging to flush log queue and send over the socket (default: 1000)
  • batch_count: maximum number of log messages to queue before sending over the socket (default: 10)
  • max_buffer: The maximum number of messages to queue up for publishing if the client isnt connected to the server or if batching (default: 1000).
  • socket_options: Any options you wish to give to the socket client (default: nothing).

How to use it

  const winston = require('winston');
  require('winston-socket.io');

  let logger = winston.createLogger({
    level: "info",
    transports: [
      new winston.transports.Console(),
      new winston.transports.SocketIO(
        {
          host: "myhost",
          port: 8080
          secure: true,
          namespace: "log",
          log_topic: "log"
        }
      )
    ]
  });  

  logger.log("info", "I'm logging to the socket.io server!!!");
  logger.log("info", "I'm logging something else", {meta: "some additional info"});

Can also be added to Winston as a transport in this method

  const winston = require('winston');
  require('winston-socket.io');

  winston.add(new winston.transports.SocketIO({
    host: "myhost",
    port: 8080
    secure: true,
    namespace: "log",
    log_topic: "log"
  }));

Browser Demo

In the example folder is a demo of winston being used on the client side with both the browser console extension and winston socket.io logging back to the webserver.

If you want to try it out (Assuming you have nodejs installed):

  git clone https://github/jbass86/winston-socket.io
  cd winston-socket.io
  npm install
  npx gulp build-demo
  node examples/demo/app.js

Then open your browser up and navigate to "localhost:8080"

Readme

Keywords

Package Sidebar

Install

npm i winston-socket.io

Weekly Downloads

70

Version

1.2.0

License

MIT

Unpacked Size

26.4 kB

Total Files

13

Last publish

Collaborators

  • jbass86