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.
@karmaniverous/edge-logger
Advanced tools
A simple logging class that renders nicely-formatted logs and plays nicely with edge networks.
The Next.js Edge Runtime is extremely limited as to the packages it can load.
This can pose a challenge for common logging and utility packages like winston
and lodash
, which will fail when loaded into an edge resource.
Logging is a cross-cutting concern, and shouldn't have to care where it is executed. So this package is a simple, flexible logging utility that...
npm install @karmaniverous/edge-logger
import Logger from `@karmaniverous/edge-logger`;
const logger = new Logger();
logger.emerg('emergency message', { foo: 'bar' }); // rendered with console.error()
logger.alert('alert message'); // rendered with console.error()
logger.crit('critical message'); // rendered with console.error()
logger.error('error message'); // rendered with console.error()
logger.warning('warning message'); // rendered with console.warn()
logger.notice('notice message'); // rendered with console.info()
logger.info('info message'); // rendered with console.info()
logger.debug('debug message'); // rendered with console.debug()
logger.log('log message'); // rendered with console.info()
// emerg: emergency message
// emerg: {
// emerg: "foo": "bar"
// emerg: }
// alert: alert message
// crit: critical message
// error: error message
// warning: warning message
// notice: notice message
// info: info message
// info: log message
// debug level not rendered by default.
// Set LOG_LEVEL to 'debug' to see these.
Set your minimum logging level with environment variable LOG_LEVEL
(by default it is info
).
The optional constructor config
argument has the following keys:
Key | Description |
---|---|
defaultLevel | Default logging level (invoked by the log method). Default value set in levels object (info for default levels ). |
maxLevel | Maximum logging level. Default value set in levels object (info for default levels ). |
levels | An alternate levels definition. See below for details. |
Here is the default levels object:
{
emerg: { value: 0, console: 'error' },
alert: { value: 1, console: 'error' },
crit: { value: 2, console: 'error' },
error: { value: 3, console: 'error' },
warning: { value: 4, console: 'warn' },
notice: { value: 5, console: 'info' },
info: { value: 6, console: 'info', default: true, defaultMax: true },
debug: { value: 7, console: 'debug' },
}
Each key will be rendered as a function on the Logger
instance that takes a list of items, just like console.log()
.
The keys on each log level:
Key | Description |
---|---|
value | Supports setting the logging threshold. |
console | The console function invoked by the log level. |
default | true if the log method should trigger this level. |
defaultMax | true if default max level. |
See more great templates and other tools on my GitHub Profile!
FAQs
A simple logging class that renders nicely-formatted logs and plays nicely with edge networks.
We found that @karmaniverous/edge-logger demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 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.