Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

logging-utils

Package Overview
Dependencies
Maintainers
1
Versions
54
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

logging-utils - npm Package Compare versions

Comparing version 2.0.0 to 2.0.1

27

logging.js

@@ -45,3 +45,3 @@ 'use strict';

/** Returns a logging settings object constructed from given or default logging options and the given underlyingLogger */
getLoggingSettingsOrDefaults: getLoggingSettingsOrDefaults,
getDefaultLoggingSettings: getDefaultLoggingSettings,

@@ -158,3 +158,3 @@ // Constants for Log Levels

const underlyingLogger = settings && typeof settings === 'object' ? settings.underlyingLogger : undefined;
const loggingSettings = getLoggingSettingsOrDefaults(settings, underlyingLogger);
const loggingSettings = getDefaultLoggingSettings(settings, underlyingLogger);

@@ -205,6 +205,6 @@ const logLevel = loggingSettings.logLevel;

/**
* Configures the default logging functionality on the given target object, but ONLY if no logging functionality is
* already configured on the target.
* Configures the default logging functionality on the given target object partially overridden by the given logging
* options (if any), but ONLY if no logging functionality is already configured on the target.
*
* The default configuration uses the following settings:
* The default logging configuration uses the following settings:
* - Log level is set to the local config.loggingOptions.logLevel (if any) or INFO.

@@ -216,2 +216,3 @@ * - Use level prefixes is set to the local config.loggingOptions.useLevelPrefixes (if any) or true.

* @param {Object} target - the target object to which to add default logging functionality
* @param {LoggingOptions|undefined} [options] - optional logging options to use to override the default options
* @param {Object|undefined} [underlyingLogger] - the optional underlying logger to use to do the actual logging

@@ -222,14 +223,14 @@ * @param {boolean|undefined} [forceConfiguration] - whether or not to force configuration of the default logging

*/
function configureDefaultLogging(target, underlyingLogger, forceConfiguration) {
const defaultSettings = getLoggingSettingsOrDefaults(undefined, underlyingLogger);
return configureLogging(target, defaultSettings, forceConfiguration);
function configureDefaultLogging(target, options, underlyingLogger, forceConfiguration) {
const settings = getDefaultLoggingSettings(options, underlyingLogger);
return configureLogging(target, settings, forceConfiguration);
}
/**
* Returns a logging settings object constructed from the given logging options (if any) and the given underlyingLogger
* (if any), preferring any options in the given options object over the default options.
* Returns the default logging settings either partially or fully overridden by the given logging options (if any) and
* the given underlyingLogger (if any).
*
* This function is used internally by both {@linkcode configureLogging} and {@linkcode configureDefaultLogging}, but
* could also be used in custom configurations to get the default settings as a base overridden with your own
* customisations before calling {@linkcode configureLogging}.
* could also be used in custom configurations to get the default settings as a base to be overridden with your custom
* settings before calling {@linkcode configureLogging}.
*

@@ -240,3 +241,3 @@ * @param {LoggingOptions|undefined} [options] - optional logging options to use to override the default options

*/
function getLoggingSettingsOrDefaults(options, underlyingLogger) {
function getDefaultLoggingSettings(options, underlyingLogger) {
const logger = isValidLogger(underlyingLogger) ? underlyingLogger : console;

@@ -243,0 +244,0 @@

{
"name": "logging-utils",
"description": "Utilities for configuring simple log level based logging functionality on an object",
"version": "2.0.0",
"version": "2.0.1",
"author": "Byron du Preez",

@@ -6,0 +6,0 @@ "license": "Apache-2.0",

@@ -1,2 +0,2 @@

# logging-utils v2.0.0
# logging-utils v2.0.1
Utilities for configuring simple log level based logging functionality on an object.

@@ -36,3 +36,3 @@

const isLoggingConfigured = logging.isLoggingConfigured;
const getLoggingSettingsOrDefaults = logging.getLoggingSettingsOrDefaults;
const getDefaultLoggingSettings = logging.getDefaultLoggingSettings;

@@ -69,2 +69,3 @@ // Log level constants

```
* To configure simple default logging on a new object

@@ -74,9 +75,10 @@ ```js

```
* To configure default logging on an existing object with an explicit logger and forceConfiguration true
* To configure default logging on an existing object with overriding options, an explicit logger and forceConfiguration true
```js
configureDefaultLogging(context, console, true);
const options = undefined; // ... or any LoggingOptions you want to use to partially or fully override the default logging settings
configureDefaultLogging(context, options, console, true);
// Alternatives specifying only underlying logger or forceConfiguration
configureDefaultLogging(context, console);
configureDefaultLogging(context, undefined, true);
configureDefaultLogging(context, options, console);
configureDefaultLogging(context, options, undefined, true);
```

@@ -87,4 +89,6 @@

const config = { loggingOptions: { logLevel: DEBUG, useLevelPrefixes: true, useConsoleTrace: false } }; // replace with your own config object
const loggingSettings = getLoggingSettingsOrDefaults(config.loggingOptions);
const loggingSettings = getDefaultLoggingSettings(config.loggingOptions);
configureLogging(context, loggingSettings);
// or as an alternative to the above 2 lines, just use the following:
configureDefaultLogging(context, config.loggingOptions);

@@ -99,4 +103,6 @@ // Alternatives specifying only optional underlying logger or forceConfiguration

const options = { logLevel: DEBUG, useLevelPrefixes: true, useConsoleTrace: false }; // replace with your own config object
const loggingSettings = getLoggingSettingsOrDefaults(options);
const loggingSettings = getDefaultLoggingSettings(options);
configureLogging(context, loggingSettings);
// or as an alternative to the above 2 lines, just use the following:
configureDefaultLogging(context, options);
```

@@ -154,2 +160,8 @@

### 2.0.1
- Changes to `logging.js` module:
- Changed `configureDefaultLogging` function to accept a new `options` argument of type `LoggingOptions`
to enable optional, partial overriding of default logging settings
- Renamed `getLoggingSettingsOrDefaults` function to `getDefaultLoggingSettings`
### 2.0.0

@@ -156,0 +168,0 @@ - Changed `logging-utils` configuration API to synchronize with similar changes done to `aws-core-utils/stages`

@@ -22,3 +22,3 @@ 'use strict';

const configureDefaultLogging = logging.configureDefaultLogging;
const getLoggingSettingsOrDefaults = logging.getLoggingSettingsOrDefaults;
const getDefaultLoggingSettings = logging.getDefaultLoggingSettings;

@@ -28,3 +28,3 @@ const booleans = require('core-functions/booleans');

const defaultSettings = logging.getLoggingSettingsOrDefaults();
const defaultSettings = logging.getDefaultLoggingSettings();

@@ -656,6 +656,7 @@ function testLogger(logLevel, useConsole, t) {

// =====================================================================================================================
// Test configureDefaultLogging on existing object with test logger to validate methods
// Test configureDefaultLogging without options on existing object with test logger to validate methods
// =====================================================================================================================
test('configureDefaultLogging on existing object with test logger & defaults', t => {
test('configureDefaultLogging without options on existing object with test logger & defaults', t => {
const options = undefined;
const logLevel = defaultSettings.logLevel;

@@ -666,3 +667,3 @@ const logger = testLogger(logLevel, false, t);

const context = {abc: 123};
configureDefaultLogging(context, logger, false);
configureDefaultLogging(context, options, logger, false);

@@ -684,3 +685,3 @@ t.equal(context.abc, 123, 'context must still be intact');

// Now do NOT override with default logging configuration when NOT using force
configureDefaultLogging(context, logger, false);
configureDefaultLogging(context, options, logger, false);

@@ -691,3 +692,3 @@ checkEnabledsBasedOnLogLevel(t, context, overrideLogLevel);

// Now override with default logging configuration using force
configureDefaultLogging(context, logger, true);
configureDefaultLogging(context, options, logger, true);

@@ -702,2 +703,47 @@ t.equal(context.abc, 123, 'context must still be intact');

// =====================================================================================================================
// Test configureDefaultLogging with overridden options on existing object with test logger to validate methods
// =====================================================================================================================
test('configureDefaultLogging with overridden options on existing object with test logger & defaults', t => {
const logLevel = defaultSettings.logLevel !== TRACE ? TRACE : ERROR;
const options = {logLevel: logLevel};
t.notEqual(options.logLevel, defaultSettings.logLevel, `options logLevel (${options.logLevel}) must differ from default (${defaultSettings.logLevel})`);
const logger = testLogger(logLevel, false, t);
// Configure default logging when no logging configured yet (without force)
const context = {abc: 123};
configureDefaultLogging(context, options, logger, false);
t.equal(context.abc, 123, 'context must still be intact');
checkEnabledsBasedOnLogLevel(t, context, logLevel);
logOneOfEach(context, logLevel);
// Now override with something else entirely using force (to change away from previous config settings)
const overrideLogLevel = logLevel !== ERROR ? ERROR : TRACE;
const overrideSettings = {
logLevel: overrideLogLevel,
useLevelPrefixes: !defaultSettings.useLevelPrefixes,
useConsoleTrace: !defaultSettings.useConsoleTrace,
underlyingLogger: testLogger(overrideLogLevel, false, t)
};
configureLogging(context, overrideSettings, true);
// Now do NOT override with default logging configuration when NOT using force
configureDefaultLogging(context, options, logger, false);
checkEnabledsBasedOnLogLevel(t, context, overrideLogLevel);
logOneOfEach(context, overrideLogLevel);
// Now override with default logging configuration using force
configureDefaultLogging(context, options, logger, true);
t.equal(context.abc, 123, 'context must still be intact');
checkEnabledsBasedOnLogLevel(t, context, logLevel);
logOneOfEach(context, logLevel);
t.end();
});
// =====================================================================================================================
// Test configureLogging on existing object with test logger to validate methods

@@ -751,6 +797,6 @@ // =====================================================================================================================

// =====================================================================================================================
// Test configureLogging with default getLoggingSettingsOrDefaults
// Test configureLogging with default getDefaultLoggingSettings
// =====================================================================================================================
test('configureDefaultLogging on existing object with test logger & defaults', t => {
test('configureLogging with default getDefaultLoggingSettings on existing object with test logger & defaults', t => {
const logLevel = defaultSettings.logLevel;

@@ -761,3 +807,3 @@ const logger = testLogger(logLevel, false, t);

const context = {abc: 123};
const defaults = getLoggingSettingsOrDefaults(undefined, logger);
const defaults = getDefaultLoggingSettings(undefined, logger);
configureLogging(context, defaults, false);

@@ -796,6 +842,6 @@

// =====================================================================================================================
// Test configureLogging with non-default getLoggingSettingsOrDefaults
// Test configureLogging with non-default getDefaultLoggingSettings
// =====================================================================================================================
test('configureLogging with getLoggingSettingsOrDefaults on existing object with test logger & config.logLevel etc.', t => {
test('configureLogging with getDefaultLoggingSettings on existing object with test logger & config.logLevel etc.', t => {
const logLevel = defaultSettings.logLevel !== TRACE ? TRACE : ERROR;

@@ -811,3 +857,3 @@ const logger = testLogger(logLevel, false, t);

};
const settings = getLoggingSettingsOrDefaults(options, logger);
const settings = getDefaultLoggingSettings(options, logger);
configureLogging(context, settings, false);

@@ -826,3 +872,3 @@

};
const overrideSettings = getLoggingSettingsOrDefaults(overrideOptions, testLogger(overrideLogLevel, false, t));
const overrideSettings = getDefaultLoggingSettings(overrideOptions, testLogger(overrideLogLevel, false, t));
configureLogging(context, overrideSettings, true);

@@ -829,0 +875,0 @@

{
"name": "logging-utils-tests",
"description": "Unit tests for logging-utils",
"version": "2.0.0",
"version": "2.0.1",
"author": "Byron du Preez",

@@ -6,0 +6,0 @@ "license": "Apache-2.0",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc