Security News
Weekly Downloads Now Available in npm Package Search Results
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
logging-utils
Advanced tools
Utilities for configuring simple log level based logging functionality on an object
Utilities for configuring simple log level based logging functionality on an object.
The log levels supported are the following:
Main module:
This module is exported as a Node.js module.
Using npm:
$ npm i --save logging-utils
// To use the logging utilities
const logging = require('logging-utils');
// Valid logging levels
const LogLevel = logging.LogLevel;
// Logging configuration functions
const isLoggingConfigured = logging.isLoggingConfigured;
const configureLogging = logging.configureLogging;
// Convenience logging function
const log = logging.log;
const context = {}; // replace with your own target object to be configured
configureLogging(context);
// which is equivalent to:
configureLogging(context, {logLevel: LogLevel.INFO});
configureLogging(context, {logLevel: LogLevel.WARN});
const settings = {logLevel: LogLevel.DEBUG, useLevelPrefixes: false, useConsoleTrace: false, underlyingLogger: console}; // or your own settings
configureLogging(context, settings);
// OR with explicit forceConfiguration false
configureLogging(context, settings, undefined, false);
configureLogging(context, settings, undefined, true);
const log = configureLogging({});
configureLogging(context, undefined, options, true);
// Alternatively ...
configureLogging(context, options, undefined, true);
const options = undefined; // ... or any LoggingOptions you want to use to partially or fully override the default logging settings
configureLogging(context, {underlyingLogger: console}, options);
const CustomLogger = {/* ... */}; // implement your own custom logger if required
configureLogging(context, {underlyingLogger: CustomLogger}, options, true);
const options = { logLevel: LogLevel.DEBUG, useLevelPrefixes: true, useConsoleTrace: false }; // replace with your own options
configureLogging(context, undefined, options);
// OR just ...
configureLogging(context, options);
configureLogging(context, settings, options);
// OR with explicit forceConfiguration false ...
configureLogging(context, settings, options, false);
configureLogging(context, settings, options, true);
logLevel
setting or option during runtime configuration, set a logging level on
the environment variable named by the envLogLevelName
setting, which is also configurable and defaults to 'LOG_LEVEL'
.
Any valid logLevel
found with process.env[envLogLevelName]
will take precedence over any other logLevel
setting or option.// For unit testing, set the `LOG_LEVEL` environment variable programmatically
process.env.LOG_LEVEL = LogLevel.DEBUG;
// Alternatively, if you configured your own `envLogLevelName` as 'MyLogLevel', e.g.
configureLogging(context, {envLogLevelName: 'MyLogLevel'});
// then for unit testing, set your `MyLogLevel` environment variable programmatically
process.env.MyLogLevel = LogLevel.TRACE;
// Log an error with a strack trace
context.error('Error message 1', new Error('Boom').stack);
// Log an error without a stack trace
context.error('Error message 2');
// Log a warning (or do nothing when warnings are disabled)
context.warn('Warning message 1');
// To avoid building the warning message (when warnings are disabled)
if (context.warnEnabled) context.warn('Warning message 2');
// Log an info message (or do nothing when info messages are disabled)
context.info('Info message 1');
// To avoid building the info message (when info messages are disabled)
if (context.infoEnabled) context.info('Info message 2');
// Log a debug message (or do nothing when debug messages are disabled)
context.debug('Debug message 1');
// To avoid building the debug message (when debug messages are disabled)
if (context.debugEnabled) context.debug('Debug message 2');
// To log a trace message (or do nothing when trace messages are disabled)
context.trace('Trace message 1');
// To avoid building the trace message (when trace messages are disabled)
if (context.traceEnabled) context.trace('Trace message 2');
log
method):// To log a message at LogLevel.TRACE (or do nothing when trace messages are disabled)
context.log(LogLevel.ERROR, 'Error message 1', new Error('Boom').stack);
// Note that this will also work with console, but you won't get any suppression according to log level
console.log(LogLevel.TRACE, 'Trace message 1');
log
function):// Alternatively using log function
log(context, LogLevel.DEBUG, 'Debug message 1');
// Note that this will also work with console (and undefined), but you won't get any suppression according to log level
log(console, LogLevel.WARN, 'Warn message 1');
log(undefined, LogLevel.ERROR, 'Error message 1', new Error('Boom 2').stack);
This module's unit tests were developed with and must be run with tape. The unit tests have been tested on Node.js v4.3.2.
See the package source for more details.
See release_notes.md
4.0.14
error.stack
with logging of just the errorcore-functions
dependency to version 3.0.15FAQs
Utilities for configuring simple log level based logging functionality on an object
The npm package logging-utils receives a total of 48 weekly downloads. As such, logging-utils popularity was classified as not popular.
We found that logging-utils 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
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
Security News
A Stanford study reveals 9.5% of engineers contribute almost nothing, costing tech $90B annually, with remote work fueling the rise of "ghost engineers."
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.