Security News
JSR Working Group Kicks Off with Ambitious Roadmap and Plans for Open Governance
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.
@17media/node-logger
Advanced tools
Centralized logger for 17.Media Node.JS projects
... in the fires of Mount Doom, the dark lord Sauron forged, in secret, a master logger to control all others.
"One logger to log them all!"
First of all you have to set up your configs:
import { Level } from '@17media/node-logger';
const loggerConfig = {
// configs shared by all log services
base: {
// minimum level to trigger logger [ERROR|WARN|INFO|DEBUG]
// levels lower than this will not be logged
// it can be overridden in each service specific config
logLevel: Level.INFO,
// project name, preferably 'name' from package.json
project: require('~/package.json').name,
// environment [production|stage|development]
environment: 'production',
},
// configs for slack
Slack: {
// override minimum log level (optional)
logLevel: Level.WARN,
// slack bot access token
slackToken: SLACK_BOT_TOKEN,
// slack channel to log messages to
slackChannel: SLACK_BOT_ALERT_CHANNEL,
},
// configs for log collecting service (fluentD)
Fluentd: {
// override minimum log level (optional)
logLevel: Level.INFO,
// log collector URL
collectorUrl: LOG_COLLECTOR_URL,
},
// configs for logging to console
Console: {
// override minimum log level (optional)
logLevel: Level.ERROR,
},
};
Then, there are two ways to continue, the easy way and the complete way:
This is the simple way and should cover ~90% of the use cases.
const logger = require('@17media/node-logger').createLogger(loggerConfig)('some:label');
logger.debug('track the variable value during development', { info });
logger.info('somehing worth logging for future reference', { additionalInfo });
logger.warn('somehing worth notice', { additionalInfo });
logger.error('somehing terrible happened', new Error());
logger.fatal('somehing disastrous happened', new Error(), { additionalInfo });
Provide configs to initiate the logger:
A log service will be used only when all corresponding configs are provided.
const { Logger } = require('@17media/node-logger');
const logger = new Logger(loggerConfig);
Use the logger like:
const { LogMessage } = require('@17media/node-logger');
logger.Log(
Level.WARN,
new LogMessage('something happened', { additionalInfo }),
'some:label:for:the:message'
);
In most situations you would want to pre-label all the messages logged in a file.
You can do it by:
const labelledLogger = logger.Label('path:to:this:file');
labelledLogger.Log(
Level.WARN,
new LogMessage('something happened', { additionalInfo })
);
You can extend LogMessage
and ErrorMessage
to create customized formatting for your context.
FAQs
Centralized logger for 17.Media Node.JS projects
We found that @17media/node-logger demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers 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
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.
Security News
Research
An advanced npm supply chain attack is leveraging Ethereum smart contracts for decentralized, persistent malware control, evading traditional defenses.
Security News
Research
Attackers are impersonating Sindre Sorhus on npm with a fake 'chalk-node' package containing a malicious backdoor to compromise developers' projects.