Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Very simple log class with support for filtering, sprintf style input, custom formatting, and custom message handling.
Very simple log class with support for filtering, sprintf style input, custom formatting, and custom message handling.
This utility is meant to provide the bare minimum of functionality that a logger should have. More functionality can be added by using a custom formatter or handler.
If you publish a Firewood formatter or handler module, please add the firewood tag to the package.
Features:
npm install firewood --save
All methods return a reference to the Firewood instance for chaining.
options
is an object with the following defaults, unless Firewood.defaults
has been modified:
{
level: Firewood.ERROR,
formatter: Firewood.defaultFormatter,
handler: Firewood.defaultHandler
}
Add a log message with a log level corresponding to the method name.
The format
and additional arguments are passed to the sprintf-js module's vsprintf()
function for compilation into a single string, before the string is passed to the Firewood formatter and handler. This mimics the behavior of console.log()
.
level
can be a number, string, or constant.
Valid string/number/constant values:
formatter
can be a function, an object with a format()
method, or false/null.
If formatter
is a function/object, the function will be passed the text of the log message, a numeric log level, and the time of the message as a Date instance. It should return the final log message text, or null to filter out the message completely. If null is returned the message will not be passed to the message handler.
if formatter
is false or null, then messages will be passed to the handler without formatting.
Example (default formatter):
firewood.setFormatter(function(text, level, date) {
return sprintf('[%s] %s - %s', getLevelName(level).toUpperCase(), date.toISOString(), text);
});
handler
can be a function, an object with a handle()
method, or a writable stream.
The function receives the same parameters as the formatter, however it should not modify the text value of the message. Instead it should record or output the message.
Example (default handler):
firewood.setHandler(function(text, level, date) {
switch (level) {
case Firewood.TRACE:
console.log(colors.gray(text));
break;
case Firewood.DEBUG:
console.log(text);
break;
case Firewood.INFO:
console.info(colors.cyan(text));
break;
case Firewood.WARN:
console.warn(colors.yellow(text));
break;
case Firewood.ERROR:
console.error(colors.red(text));
break;
default:
console.log(text);
break;
}
});
Example (writing directly to stdout):
firewood.setHandler(process.stdout);
level
an optional log level or function which accepts a log message and returns a log level. If a level function returns null, then the log message is discarded.
Returns a writable stream that will log all messages written to it.
All log messages will be silently ignored after this method is called.
Log level constants used with the setLevel()
method.
level
can be the log level name or number.
Returns The lower case string name of the log level. If the level is not a valid log level number or name, then an empty string will be returned.
level
can be a log level name or number.
Returns the number value of the log level. If the level is not a valid level number or name, then NaN will be returned;
The default formatter which prepends all messages with the upper case level in square brackets []
, followed by the ISO-8601 timestamp, a hyphen, and then the text of the log message.
Example:
[DEBUG] 2015-01-23T12:34:56.789Z - message
The default handler function which prints all log messages to the console. Trace and debug levels are output using the console.log()
method. All other levels are output using the corresponding console
method. It also color codes the messages using the colors module.
Level/Color:
The default options object for all new Firewood instances. This property can be modified to change the default options for all future Firewood instances.
Initially property has the following default value:
{
level: Firewood.DEBUG,
formatter: Firewood.defaultFormatter,
handler: Firewood.defaultHandler
}
FAQs
Unknown package
The npm package firewood receives a total of 1 weekly downloads. As such, firewood popularity was classified as not popular.
We found that firewood 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
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.