Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
winston-logstash
Advanced tools
A Logstash TCP transport for winston.
// See test cases from test-bench/winston-2x/test/smoke.js
const winston = require("winston");
const transports = require("winston-logstash");
const logger = new winston.Logger({
transports: [
new transports.Logstash({
port: 28777,
node_name: "my node name",
host: "127.0.0.1",
}),
],
});
logger.info("Hello world!");
// See test cases from test-bench/winston-3x/test/smoke.js
const winston = require("winston");
const LogstashTransport = require("winston-logstash/lib/winston-logstash-latest");
const logger = winston.createLogger({
transports: [
new LogstashTransport({
port: 28777,
node_name: "my node name",
host: "127.0.0.1",
}),
],
});
logger.info("Hello world!");
# See example from test-bench/logstash/logstash/pipeline/default.conf
input {
# Sample input over TCP
tcp { port => 28777 type=>"sample" }
}
output {
stdout { debug => true }
}
filter {
json {
source => "message"
}
}
While this is a relatively complex transport with an internal state and IO, I think the current solution is the yet best approach to network failure. Transport is transparent about the errors and lets the user decide what to do in the case of an error. Suppose the developer chooses not to address them, it fallback to a safe default, an exception that stops the process. I think this way; it's simple but not always easy.
You can check the test case from test-bench
folder where is the test case per Winston's version. The simplest ways to write the error logic would be:
For Winston 2.x you have to add the error listener to the transport.
const logstashTransport = new LogstashTransport({...});
logstashTransport.on('error', (error) => {
// Make the decission in here
throw new Error('Stop the press, logging not working');
});
For Winston 3.x you have to add the error listener to the logger. Remember that there might be also other errors which are not originated from LogstashTransport.
const logger = winston.createLogger({
transports: [
new LogstashTransport({
...
max_connect_retries: -1
...
})]});
logger.on('error', (error) => {
// Make the decission in here
throw new Error('Stop the press, logging not working');
});
See documentation from docs/configuration
It's possible to set max_connect_retries to -1 (infinite) so the client keeps trying to connect to the Logstash. So when Logstash is restarted the retry logic will reconnect when it comes back online.
const logger = winston.createLogger({
transports: [
new LogstashTransport({
...
max_connect_retries: -1
...
})]});
npm test
cd test-bench/winston-3x
docker-compose up -d
npm test
See LICENSE for the full license text.
FAQs
A Logstash transport for winston
We found that winston-logstash demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 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
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.