
Research
Malicious fezbox npm Package Steals Browser Passwords from Cookies via Innovative QR Code Steganographic Technique
A malicious package uses a QR code as steganography in an innovative technique.
direct-logger
Advanced tools
Logger call API is interoperable with pino logger.
Features:
direct-logger
is dependency free (formatters are not)cli
formatter 🚀$ yarn add direct-logger
const { Logger } = require('direct-logger')
const logger = Logger()
logger.error(new Error('My error message'))
// Thu Apr 16 2015 22:05:27 GMT-0500 (CDT) [error] - {"msg":"Error: My error message\n<STACK TRACE>"}
logger.info('Something happened', {
foo: 'info about what happened'
})
// Thu Apr 16 2015 22:05:27 GMT-0500 (CDT) [info] - {"msg":"Something happened","foo":"info about what happened"}
Each log level can be directed to a different output stream or disabled entirely. The default levels are as follows:
fatal
error
warn
(default)info
debug
trace
Constants are available for setting and referencing the levels and their streams. These constants are the all uppercase version of the level. Here is an example of setting the log level:
const logger = Logger({
level: Logger.DEBUG
})
logger.debug('Foo')
// Thu Apr 16 2015 22:05:27 GMT-0500 (CDT) [debug] - {"msg":"Foo"}
You can fully customize the levels for your purposes. For example, here
we implement pino
compatible levels:
const log = Logger({
level: [ 'trace', 'debug', 'info', 'warn', 'error', 'fatal' ]
})
log.trace('Example trace log')
direct-logger supports formatting via formatter functions. The default
formatter outputs a timestamp, the log level and the messages formatted
as json. But you can provide a custom formatter function with the formatter
options. Formatter functions take three parameters: date
, level
, data
.
Say we want to output the log message with a color based on the level:
const Logger = require('direct-logger')
const chalk = require('chalk')
const logger = Logger({
formatter: (date, level, data) => {
var color
switch (Logger.levels.indexOf(level)) {
case Logger.FATAL:
case Logger.ERROR:
color = chalk.red
break
case Logger.WARN:
color = chalk.yellow
break
case Logger.INFO:
case Logger.DEBUG:
color = chalk.white
break
}
return color(data.msg)
}
})
There are a few built-in in formatters:
default
: Outputs date, level and jsoncli
: Outputs the message and json data, colorized and formattedbunyan
: Compatible format to bunyan
browser
: Relies on console.log
, so just returns the data
For these built-in formatters can specify the string name of the formatter for built-in formatters:
const log = Logger({
formatter: 'cli'
})
To use the cli formatter you can require it and pass the formatter
options:
const log = Logger({
formatter: require('direct-logger/formatters/cli')
})
You can output each level to it's own stream. The method is simple, just pass an
array of streams corresponding to each level as the streams
option. The simplest
way is to just map over Logger.levels
, this is how we set the defaults:
Logger({
streams: Logger.levels.map(function (level, i) {
return i > Logger.WARN ? process.stdin : process.stderr
})
})
The most useful reason to specify an output stream to to redirect logs to files. Here is an example of how to do that:
const logfile = fs.createWriteStream('./logs/stdout.log', {
flags: 'a',
encoding: 'utf8'
})
Logger({
streams: Logger.levels.map(() => logfile)
})
const logger = Logger({
secrets: ["1234"],
secretsHideCharsCount: false, // default false
secretsStringSubstition: "***", // used when secretsHideCharsCount is true
secretsRepeatCharSubstition: "*", // used when secretsHideCharsCount is false
})
logger.info("secret is 123454678") // output "secret is ****5678"
logger.addSecret("5678")
logger.secretsHideCharsCount = true
logger.info("secret is 123454678") // output "secret is ***"
logger.deleteSecret("1234")
logger.info("secret is 123454678") // output "secret is 1234***"
const hasSecret = logger.hasSecret("54678") // hasSecret === true
Arguments orders are reversible.
// classical
logger.debug("Hello world !", { foo: "bar" })
// pino compatible
logger.debug({ foo: "bar" }, "Hello world !")
// string message can be replaced by object having a `toString` method
logger.debug({ foo: "bar" }, new Error("Here is a message"))
logger.debug(new Error("Here is another message"), { foo: "bar" })
logger.setLevel("warn")
logger.minLevel("debug")
logger.maxLevel("info")
FAQs
A simple logger to console or file
The npm package direct-logger receives a total of 118 weekly downloads. As such, direct-logger popularity was classified as not popular.
We found that direct-logger 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
A malicious package uses a QR code as steganography in an innovative technique.
Research
/Security News
Socket identified 80 fake candidates targeting engineering roles, including suspected North Korean operators, exposing the new reality of hiring as a security function.
Application Security
/Research
/Security News
Socket detected multiple compromised CrowdStrike npm packages, continuing the "Shai-Hulud" supply chain attack that has now impacted nearly 500 packages.