Research
Security News
Malicious npm Package Targets Solana Developers and Hijacks Funds
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
The log-driver npm package is a simple and lightweight logging utility for Node.js applications. It provides a straightforward API for logging messages at different levels (e.g., info, warn, error) and can be easily integrated into any Node.js project.
Basic Logging
This feature allows you to log messages at different levels such as info, warn, and error. The code sample demonstrates how to create a logger instance and log messages at various levels.
const log = require('log-driver')();
log.info('This is an info message');
log.warn('This is a warning message');
log.error('This is an error message');
Custom Log Levels
This feature allows you to define custom log levels. The code sample shows how to create a logger instance with custom levels and log messages at those levels.
const log = require('log-driver')({ levels: ['debug', 'info', 'warn', 'error', 'fatal'] });
log.debug('This is a debug message');
log.fatal('This is a fatal message');
Log Formatting
This feature allows you to customize the format of log messages. The code sample demonstrates how to create a logger instance with a custom format function that prepends a timestamp to each log message.
const log = require('log-driver')({ format: function() { return new Date().toISOString() + ' - ' + arguments[0]; } });
log.info('This is a formatted info message');
Winston is a versatile and feature-rich logging library for Node.js. It supports multiple transports (e.g., console, file, HTTP) and allows for extensive customization of log formats and levels. Compared to log-driver, Winston offers more advanced features and greater flexibility.
Bunyan is a simple and fast JSON logging library for Node.js. It is designed for high-performance logging and provides a CLI tool for pretty-printing logs. Bunyan's focus on JSON output and performance makes it a good choice for applications that require structured logging, whereas log-driver is more lightweight and simpler to use.
Pino is a low-overhead logging library for Node.js that is designed for speed. It provides a fast and efficient way to log messages and supports JSON output. Pino's emphasis on performance and minimal overhead makes it suitable for high-throughput applications, while log-driver is more focused on simplicity and ease of use.
Logdriver is a node.js logger that only logs to stdout.
node yourapp.js 2>&1 | node ircloggerbot.js
node yourapp.js 2>&1 >> somefile.log
NB: If you're logging to a file, Logrotate is probably going to be your best friend.
node yourapp.js 2>&1 | logger
Getting the default logger:
var logger = require('log-driver').logger;
This logger has levels 'error', 'warn', 'info', 'debug', and 'trace'. If you don't like those levels, change the default:
var logger = require('log-driver')({
levels: ['superimportant', 'checkthisout', 'whocares' ]
});
logger.whocares("brangelina in lover's quarrel!");
Specifying what log level to log at to make logs less chatty:
var logger = require('log-driver')({ level: "info" });
logger.info("info test");
logger.warn("warn test");
logger.error("error test");
logger.trace("trace test");
output:
[info] "2013-03-26T18:30:14.570Z" 'info test'
[warn] "2013-03-26T18:30:14.573Z" 'warn test'
[error] "2013-03-26T18:30:14.574Z" 'error test'
(notice the trace() call was omitted because it's less than the info level.
Turning off all log output (sometimes nice for automated tests to keep output clean):
var logger = require('log-driver')({ level: false });
Using the same logger everywhere: The last logger you created is always available this way:
var logger = require('log-driver').logger;
This way, if you use only one logger in your application (like most applications), you can just configure it once, and get it this way everywhere else.
Don't like the logging format? Just change it by passing a new formatting function like so:
var logger = require('log-driver')({
format: function() {
// let's do pure JSON:
return JSON.stringify(arguments);
}
});
FAQs
log-driver is a simple logging framework for logging to stdout
The npm package log-driver receives a total of 2,146,779 weekly downloads. As such, log-driver popularity was classified as popular.
We found that log-driver demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer 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.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.