@acteam-it/winston-socket.io

A winston transport that will emit logs to a socket.io server.

Usage no npm install needed!

<script type="module">
  import acteamItWinstonSocketIo from 'https://cdn.skypack.dev/@acteam-it/winston-socket.io';
</script>

README

winston-socket.io

Build Status Dependency 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: http://localhost).
  • port: The port of the socket.io server (default: 3000).
  • secure: Use https for the socket.io server connection (default: false).
  • reconnect: Reconnect to socket.io server connection (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").
  • encrypt: Choose to encrypt winston socket logs or not (default: false)
  • secret: the passphrase to encrypt logs with [needs encrypt to be true to allow changing it ] (default: null)
  • log_format: The format in which to log the information.
  • max_queue_size: The maximum number of messages to queue up for publishing if the client isnt connected to the server (default: 1000).

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: "http://myhost",
          port: 8080
          secure: true,
          reconnect: 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: "http://myhost",
    port: 8080
    secure: true,
    reconnect: true,
    namespace: "log",
    log_topic: "log"
  }));