
Research
Security News
Lazarus Strikes npm Again with New Wave of Malicious Packages
The Socket Research Team has discovered six new malicious npm packages linked to North Korea’s Lazarus Group, designed to steal credentials and deploy backdoors.
winston-log-space
Advanced tools
Per-module wrapper over a winston v3 logger
Winston is a great logger platform, but it lacks abilities to provide different subloggers with different loglevels, as one can find in, for example, log4j
Thus, I decided to see if such a thing would be easy to do on top of the freshly-released winston v3
winston-log-space (wls henceforth) works in the following way:
Let us have a test.js
file:
var Log = require ('winston-log-space');
Log.init ((err) => {
if (err) return console.error(err)
l1 = Log.logger ('s1');
l2 = Log.logger ('s2:s3:s4');
l1.info ('this is l1 on info %s, %d', 'ggg', 666);
l1.verbose ('this is l1 on verbose %s, %d', 'ggg', 666);
l2.info ('this is l2 on info %s, %d', 'ggg', 666);
l2.verbose ('this is l2 on verbose %s, %d', 'ggg', 666);
});
then, running it with various command line options we get:
$ node test.js
2018-06-27T15:17:09.554Z [s1] info: this is l1 on info ggg, 666
2018-06-27T15:17:09.556Z [s2:s3:s4] info: this is l2 on info ggg, 666
$ node test.js --log__level__s1=debug
2018-06-27T15:17:12.331Z [s1] info: this is l1 on info ggg, 666
2018-06-27T15:17:12.333Z [s1] verbose: this is l1 on verbose ggg, 666
2018-06-27T15:17:12.333Z [s2:s3:s4] info: this is l2 on info ggg, 666
$ node test.js --log__level__s2=debug
2018-06-27T15:17:18.415Z [s1] info: this is l1 on info ggg, 666
2018-06-27T15:17:18.417Z [s2:s3:s4] info: this is l2 on info ggg, 666
2018-06-27T15:17:18.417Z [s2:s3:s4] verbose: this is l2 on verbose ggg, 666
Alternatively, we can use env vars:
$ LOG_level__s1=debug node test.js
2018-06-27T15:19:39.274Z [s1] info: this is l1 on info ggg, 666
2018-06-27T15:19:39.276Z [s1] verbose: this is l1 on verbose ggg, 666
2018-06-27T15:19:39.277Z [s2:s3:s4] info: this is l2 on info ggg, 666
$ LOG_level__s2=debug node test.js
2018-06-27T15:20:15.196Z [s1] info: this is l1 on info ggg, 666
2018-06-27T15:20:15.199Z [s2:s3:s4] info: this is l2 on info ggg, 666
2018-06-27T15:20:15.199Z [s2:s3:s4] verbose: this is l2 on verbose ggg, 666
All of the configuration magic inside init()
is done using cascade-config, using the following config cascade:
defaults
objectopts
object passed as first param to init()
if anyprefix: LOG_
prefix: log.
process.cwd() + '/log.js'
process.cwd() + '/log-{env}.js'
wlsconfig
init(opts, cb)
As stated, you can inline your confi, or extra defults, by passing them to init()
:
var Log = require ('../');
var winston = require ('winston');
var config = {
level: {
s1: 'silly'
},
format: winston.format.combine(
winston.format.timestamp(),
winston.format.splat(),
winston.format.printf(info => `${info.timestamp} | ${info.area} | ${info.level} | ${info.message}`)
),
transports: [
new winston.transports.Console(),
new winston.transports.File({filename: 'test.log'})
]
};
Log.init (config, (err) => {
if (err) return console.error(err)
l1 = Log.logger ('s1');
l2 = Log.logger ('s2:s3:s4');
l1.info ('this is l1 on info %s, %d', 'ggg', 666);
l1.verbose ('this is l1 on verbose %s, %d', 'ggg', 666);
l2.info ('this is l2 on info %s, %d', 'ggg', 666);
l2.verbose ('this is l2 on verbose %s, %d', 'ggg', 666);
});
This will get you:
$ node inline-config.js
2018-06-28T06:23:02.817Z | s1 | info | this is l1 on info ggg, 666
2018-06-28T06:23:02.819Z | s1 | verbose | this is l1 on verbose ggg, 666
2018-06-28T06:23:02.820Z | s2:s3:s4 | info | this is l2 on info ggg, 666
$ cat test.log
2018-06-28T06:23:02.817Z | s1 | info | this is l1 on info ggg, 666
2018-06-28T06:23:02.819Z | s1 | verbose | this is l1 on verbose ggg, 666
2018-06-28T06:23:02.820Z | s2:s3:s4 | info | this is l2 on info ggg, 666
Creating a log.js
file in your PWD is also a way:
var winston = require ('winston');
module.exports = {
level: {
s1: 'silly'
},
format: winston.format.combine(
winston.format.timestamp(),
winston.format.splat(),
winston.format.printf(info => `${info.timestamp} | ${info.area} | ${info.level} | ${info.message}`)
),
transports: [
new winston.transports.Console(),
new winston.transports.File({filename: 'test.log'})
]
};
so, running your js in the same directory:
$ node basic.js
2018-06-28T06:25:56.812Z | s1 | info | this is l1 on info ggg, 666
2018-06-28T06:25:56.815Z | s1 | verbose | this is l1 on verbose ggg, 666
2018-06-28T06:25:56.815Z | s2:s3:s4 | info | this is l2 on info ggg, 666
You can also pass any file, not just ./log.js
as source for your config; simply specify anywhere in your config sources a key wlsconfig
which should contain the filename (as an absolute path). For example, passing it via cli:
$ node basic.js --log__wlsconfig=$PWD/config-log.js
2018-06-28T06:29:15.413Z | s1 | info | this is l1 on info ggg, 666
2018-06-28T06:29:15.415Z | s1 | verbose | this is l1 on verbose ggg, 666
2018-06-28T06:29:15.416Z | s2:s3:s4 | info | this is l2 on info ggg, 666
FAQs
per-module wrapper over a winston v3 logger
We found that winston-log-space 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
The Socket Research Team has discovered six new malicious npm packages linked to North Korea’s Lazarus Group, designed to steal credentials and deploy backdoors.
Security News
Socket CEO Feross Aboukhadijeh discusses the open web, open source security, and how Socket tackles software supply chain attacks on The Pair Program podcast.
Security News
Opengrep continues building momentum with the alpha release of its Playground tool, demonstrating the project's rapid evolution just two months after its initial launch.