Winston HTTP Stream Transport

raw JSON →
0.1.4 verified Thu Apr 23 auth: no javascript abandoned

This package, `winston-transport-http-stream`, provides a custom transport for the Winston logging library, designed to stream log messages to an external HTTP endpoint. It is currently at version 0.1.4, with its last release dating back seven years (April 2019). Due to its age and lack of maintenance, it is highly likely incompatible with modern versions of Winston (v3 and above), which introduced significant breaking changes to the transport API and logger instantiation. Unlike the built-in HTTP transport in Winston, this package has not seen updates to adapt to these changes, nor does it appear to offer unique differentiators beyond basic HTTP streaming of logs. Its primary function is to push log data as JSON to a configured URL, with a notable behavior of silently dropping logs if the HTTP request fails, rather than retrying or emitting an error event.

error TypeError: winston.Logger is not a constructor
cause Attempting to instantiate a logger with `new winston.Logger()` in Winston v3+ environments.
fix
Replace new winston.Logger() with winston.createLogger({...}) to align with Winston v3's API. However, this transport itself will likely still be incompatible with Winston v3's transport API.
error Logs are not appearing on my HTTP endpoint, but local file logs are working.
cause The `winston-transport-http-stream` silently drops logs if the HTTP request fails (e.g., network error, DNS resolution failure, endpoint returns non-2xx status, server not reachable).
fix
Verify the url option is correct and the target HTTP endpoint is reachable and correctly configured to receive logs. Monitor network activity from your application. Consider adding an 'error' listener to the transport instance if its API supports it to catch underlying network errors, or wrap it in a custom transport that adds retry logic and error reporting.
error Error: Transport must be a function or an object with a log method.
cause This error occurs in newer Winston versions when an incompatible object is passed as a transport, indicating the `winston-transport-http-stream` is not adhering to the current transport interface.
fix
This package is likely not compatible with the winston-transport base class used in Winston v3+. You will need to either downgrade Winston to v2.x or rewrite/replace this transport with one compatible with Winston v3+.
breaking This package was last updated in April 2019 and is highly unlikely to be compatible with Winston v3.x or newer without significant modifications. Winston v3 introduced breaking changes to the transport API, including how transports are defined and how formatting works.
fix Consider using Winston's built-in `winston.transports.Http` transport (available in Winston v3+) or a more actively maintained community transport for HTTP logging. If you must use this package, you will likely be locked into Winston v2.x.
gotcha The README explicitly states, 'When the request fails the logging request won't be send again.' This means logs can be silently dropped if the HTTP request to the endpoint fails, leading to potential data loss without explicit error handling or retries.
fix Implement custom error handling for the transport (if its API allows it, like listening to `warn` events as suggested in some Winston contexts) or use a more robust transport that includes retry mechanisms and failure notifications. For critical logs, ensure redundancy with other transports.
gotcha The package is effectively unmaintained, with no updates in seven years. This poses risks related to unpatched bugs, security vulnerabilities in its transitive dependencies, or incompatibilities with newer Node.js versions.
fix Migrate to an actively maintained logging solution or a more current Winston transport. Regularly review the dependencies of any unmaintained package for known vulnerabilities.
gotcha While it can send logs to a URL, explicit handling for HTTPS (SSL/TLS options) might be less robust or clear compared to Winston's built-in `Http` transport, which has a dedicated `ssl` option. Misconfiguration could lead to insecure HTTP connections to sensitive endpoints.
fix When using HTTPS, thoroughly review the Node.js `http.request` options documentation to ensure secure configuration (e.g., `rejectUnauthorized`, `ca`, `cert`, `key`). Consider using `axios` or `node-fetch` within a custom Winston transport for more control over HTTP/S requests.
npm install winston-transport-http-stream
yarn add winston-transport-http-stream
pnpm add winston-transport-http-stream

This example demonstrates how to configure Winston with the `HttpStreamTransport` to send logs to a specified HTTP endpoint, including important compatibility caveats regarding Winston versions and basic error handling.

const winston = require('winston');
const HttpStreamTransport = require('winston-transport-http-stream');

// IMPORTANT: This transport is likely only compatible with Winston v2.
// The logger setup below uses Winston v3+ API (winston.createLogger).
// You may need to adapt your Winston setup or use a compatible Winston version (e.g., v2.x).
const logger = winston.createLogger({
  level: 'info',
  format: winston.format.json(),
  transports: [
    new winston.transports.Console(), // Add Console transport for visibility
    new winston.transports.File({ filename: 'error.log', level: 'error' }),
    new winston.transports.File({ filename: 'combined.log' }),
    new HttpStreamTransport({
      url: 'https://yourdomain.com/log', // Replace with your actual log endpoint
      // Additional HTTP options can be passed, see Node.js http.request options.
      // For HTTPS, ensure proper 'agent' or 'https' module options are configured.
      // Example with basic auth (Node.js http options):
      // auth: 'user:password'
    })
  ]
});

logger.info('Hello from winston-transport-http-stream!');
logger.warn('This is a warning log.');
logger.error('An error occurred while testing the HTTP stream.');

// Example of how to listen for 'warn' events on the transport itself
// if it fails to send logs (behavior may vary based on transport implementation).
const httpTransportInstance = logger.transports.find(t => t instanceof HttpStreamTransport);
if (httpTransportInstance) {
  httpTransportInstance.on('warn', (err) => {
    console.error('HTTP Transport Warning/Error:', err);
  });
}