
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
Mag is the streaming logger for NodeJS
$ npm install mag --save
If you have something to show in the terminal, use the mag as well as you used console.log before.
var logger = require('mag')();
logger.info('my great application is running!');
logger.debug('process pid is %s', process.pid);
//01:27:36.427 <INFO> my great application is running!
//01:27:36.429 <DEBUG> process pid is 29860
You get well formatted message with timestamp.
If you need to visually separate the messages from different sources, use the namespace of mag.
var mag = require('mag');
var logger = mag('my-app');
var libLogger = mag('my-lib');
logger.info('my great application is running');
libLogger.debug('my library is running too');
//22:36:24.245 [my-app] <INFO> my great application is running
//22:36:24.246 [my-lib] <DEBUG> my library is running too
If you're thinking about formatting the output messages of your application, just require mag-hub before all mag requires.
mag-hub is passthrough stream. If you require mag-hub then all log objects will be written to this stream. You can read from this stream and make any transformation with your messages before writing them to stdout.
var hub = require('mag-hub');
// Formatters
var info = require('mag-process-info');
var format = require('mag-format-message');
var colored = require('mag-colored-output');
var myCustomFormatter = require('./my-custom-formatter.js');
hub.pipe(info())
.pipe(format())
.pipe(myCustomFormatter())
.pipe(colored())
.pipe(process.stdout);
More information are in mag-hub module.
If you're developing a module and you have something to write to the log, just use the mag.
var mag = require('mag');
var logger = mag('my-module');
var env = process.env.NODE_ENV || 'development';
logger.info('module is running in %s environment', env);
...
myModule.on('heartbeat', function(){
logger.debug('heartbeat of module');
});
myModule.on('error', function(){
logger.critical(new Error('game is over'));
});
You must not to worry about the output message format. (In other loggers you have to think about the message format even if you develop a module - it is bad practice)
If users of your module want to format log of the module they can require mag-hub in their application and format logs as they want. See previous section for app developers for more information.
Warning: mag-hub is designed for use only at the application leyer, do not require it into your modules distributed via npm.
TODO
Specification of internal messages format can be found here: SPEC.md
You can find examples of using mag logger in this reposiory: mag-examples.
There are following branches:
A brief interpretation of The Twelve-Factor App - Logs section:
FAQs
Mag is the streaming logger for NodeJS
The npm package mag receives a total of 44 weekly downloads. As such, mag popularity was classified as not popular.
We found that mag 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.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.