Winston HTTP Stream Transport
raw JSON →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.
Common errors
error TypeError: winston.Logger is not a constructor ↓
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. ↓
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. ↓
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+. Warnings
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. ↓
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. ↓
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. ↓
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. ↓
Install
npm install winston-transport-http-stream yarn add winston-transport-http-stream pnpm add winston-transport-http-stream Imports
- HttpStreamTransport wrong
import { HttpStreamTransport } from 'winston-transport-http-stream';correctconst HttpStreamTransport = require('winston-transport-http-stream'); - winston wrong
import winston from 'winston';correctconst winston = require('winston'); - winston.createLogger wrong
const logger = new winston.Logger({...});correctconst logger = winston.createLogger({...});
Quickstart
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);
});
}