Security News
GitHub Removes Malicious Pull Requests Targeting Open Source Repositories
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
winston-transport
Advanced tools
The winston-transport package is a base prototype for all transports in the winston logger, a popular logging library for Node.js. Transports are essentially storage devices for your logs. Each instance of a winston logger can have multiple transports configured at different levels, allowing you to control the logging output. The winston-transport package provides the necessary tools to create custom transports, enabling developers to extend logging capabilities to various outputs like files, databases, third-party services, etc.
Custom Transport Creation
This feature allows developers to create custom transports by extending the TransportStream class. The custom transport can then be used to log messages in any way or format, such as sending logs to a remote logging service, writing to a file in a custom format, or even logging to a database. The code sample demonstrates how to create a basic custom transport that logs messages to the console.
const { TransportStream } = require('winston-transport');
class CustomTransport extends TransportStream {
constructor(opts) {
super(opts);
// Initialization logic here
}
log(info, callback) {
// Perform the writing to the specified output
console.log(info);
if (callback) {
callback();
}
this.emit('logged', info);
}
}
Bunyan is a simple and fast JSON logging library for Node.js services. Like winston, it supports multiple streams with different log levels for each stream. However, Bunyan's focus on JSON as the primary log output format makes it particularly well-suited for processing logs with log management tools. It differs from winston-transport in that it is a complete logging solution with its own set of transports, rather than a base for creating custom transports.
Pino is a very low overhead Node.js logger, designed for speed and minimal memory consumption. It also focuses on JSON logging and offers a rich set of features, including child loggers and custom serializers. While Pino provides its own transports through a separate module (pino-transport), it shares the concept of extensible logging through transports with winston-transport. Pino and its transport system are optimized for performance, which is a key difference from the more flexible and feature-rich approach of winston-transport.
The base TransportStream
implementation for winston >= 3
. Use these to
write ecosystem Transports for winston
.
const Transport = require('winston-transport');
const util = require('util');
//
// Inherit from `winston-transport` so you can take advantage
// of the base functionality and `.exceptions.handle()`.
//
module.exports = class CustomTransport extends Transport {
constructor(opts) {
super(opts);
//
// Consume any custom options here. e.g.:
// - Connection information for databases
// - Authentication information for APIs (e.g. loggly, papertrail,
// logentries, etc.).
//
}
log(info, callback) {
setImmediate(() => {
this.emit('logged', info);
});
// Perform the writing to the remote service
callback();
}
};
Tests are written with mocha
, nyc
, assume
, and
abstract-winston-transport
. They can be run with npm
:
npm test
FAQs
Base stream implementations for winston@3 and up.
The npm package winston-transport receives a total of 4,960,096 weekly downloads. As such, winston-transport popularity was classified as popular.
We found that winston-transport demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.