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

@onflow/util-logger

Package Overview
Dependencies
Maintainers
12
Versions
33
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@onflow/util-logger - npm Package Compare versions

Comparing version 1.3.0-alpha.0 to 1.3.0-typescript.0

.eslintrc.json

11

CHANGELOG.md
# @onflow/util-logger
## 1.3.0-alpha.0
## 1.3.0-typescript.0
### Minor Changes
- TS build
- [#1801](https://github.com/onflow/fcl-js/pull/1801) [`9fca84a3`](https://github.com/onflow/fcl-js/commit/9fca84a3151d7f6aeb33870a302e9793f024516b) Thanks [@nialexsan](https://github.com/nialexsan)! - Convert to Typescript
- [#1801](https://github.com/onflow/fcl-js/pull/1801) [`86ce9f75`](https://github.com/onflow/fcl-js/commit/86ce9f75b5542a6bce76012e36a7a3d4fb6867f2) Thanks [@nialexsan](https://github.com/nialexsan)! - TS build
## 1.2.2
### Patch Changes
- Updated dependencies []:
- @onflow/config@1.2.0-alpha.0
- [#1771](https://github.com/onflow/fcl-js/pull/1771) [`5edbd823`](https://github.com/onflow/fcl-js/commit/5edbd823b1a6d25eb7bb52dc55338f95beae73b1) Thanks [@jribbink](https://github.com/jribbink)! - Fix @onflow/util-logger <-> @onflow/config circular dependency

@@ -14,0 +17,0 @@ ## 1.2.1

@@ -5,78 +5,35 @@ 'use strict';

var config = require('@onflow/config');
// Config dependency injected into logger to break circular dependency
let config = null;
const setConfig = _config => {
config = _config;
};
/******************************************************************************
Copyright (c) Microsoft Corporation.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
***************************************************************************** */
function __awaiter(thisArg, _arguments, P, generator) {
function adopt(value) {
return value instanceof P ? value : new P(function (resolve) {
resolve(value);
});
}
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) {
try {
step(generator.next(value));
} catch (e) {
reject(e);
}
}
function rejected(value) {
try {
step(generator["throw"](value));
} catch (e) {
reject(e);
}
}
function step(result) {
result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
}
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
}
/**
* The levels of the logger
*
* @typedef {Object} LEVELS
* @property {number} debug - The debug level
* @property {number} info - The info level
* @property {number} log - The log level
* @property {number} warn - The warn level
* @property {number} error - The error level
*
*/
const LEVELS = Object.freeze({
debug: 5,
info: 4,
log: 3,
warn: 2,
error: 1,
});
let LEVELS = /*#__PURE__*/function (LEVELS) {
LEVELS[LEVELS["debug"] = 5] = "debug";
LEVELS[LEVELS["info"] = 4] = "info";
LEVELS[LEVELS["log"] = 3] = "log";
LEVELS[LEVELS["warn"] = 2] = "warn";
LEVELS[LEVELS["error"] = 1] = "error";
return LEVELS;
}({});
/**
* Builds a message formatted for the logger
*
* @param {Object} options - The options for the log
* @param {string} options.title - The title of the log
* @param {string} options.message - The message of the log
* @returns {Array<string>} - The message formatted for the logger
*
* @param options - The options for the log
* @param options.title - The title of the log
* @param options.message - The message of the log
* @returns The message formatted for the logger
* @example
* buildLoggerMessageArgs({ title: "My Title", message: "My Message" })
*/
const buildLoggerMessageArgs = ({ title, message }) => {
return [
`
const buildLoggerMessageArgs = options => {
const {
title,
message
} = options;
return [`
%c${title}

@@ -88,84 +45,92 @@ ============================

============================
`
.replace(/\n[^\S\r\n]+/g, "\n")
.trim(),
,
"font-weight:bold;font-family:monospace;",
];
`.replace(/\n[^\S\r\n]+/g, "\n").trim(), "font-weight:bold;font-family:monospace;"];
};
/**
* Logs messages based on the level of the message and the level set in the config
*
* @param {Object} options - The options for the log
* @param {string} options.title - The title of the log
* @param {string} options.message - The message of the log
* @param {number} options.level - The level of the log
* @param {boolean} options.always - Whether to always show the log
* @returns {Promise<void>}
*
* @param options - The options for the log
* @param options.title - The title of the log
* @param options.message - The message of the log
* @param options.level - The level of the log
* @param options.always - Whether to always show the log
* @example
* log({ title: "My Title", message: "My Message", level: LEVELS.warn, always: false })
*
*/
const log = ({ title, message, level, always = false }) => __awaiter(void 0, void 0, void 0, function* () {
const configLoggerLevel = yield config.config.get("logger.level", LEVELS.warn);
// If config level is below message level then don't show it
if (!always && configLoggerLevel < level)
return;
const loggerMessageArgs = buildLoggerMessageArgs({ title, message });
switch (level) {
case LEVELS.debug:
console.debug(...loggerMessageArgs);
break;
case LEVELS.info:
console.info(...loggerMessageArgs);
break;
case LEVELS.warn:
console.warn(...loggerMessageArgs);
break;
case LEVELS.error:
console.error(...loggerMessageArgs);
break;
default:
console.log(...loggerMessageArgs);
}
});
const log = async options => {
const {
title,
message,
level,
always
} = options;
const configLoggerLevel = await config.get("logger.level", LEVELS.warn);
// If config level is below message level then don't show it
if (!always && configLoggerLevel < level) return;
const loggerMessageArgs = buildLoggerMessageArgs({
title,
message
});
switch (level) {
case LEVELS.debug:
console.debug(...loggerMessageArgs);
break;
case LEVELS.info:
console.info(...loggerMessageArgs);
break;
case LEVELS.warn:
console.warn(...loggerMessageArgs);
break;
case LEVELS.error:
console.error(...loggerMessageArgs);
break;
default:
console.log(...loggerMessageArgs);
}
};
/**
* Logs a deprecation notice
*
* @param {Object} options - The options for the log
* @param {string} options.pkg - The package that is being deprecated
* @param {string} options.subject - The subject of the deprecation
* @param {string} options.transition - The transition path for the deprecation
* @param {number} options.level - The level of the log
* @param {string} options.message - The message of the log
* @param {Function} options.callback - A callback to run after the log
* @returns {Promise<void>}
*
* Logs a deprecation notice. If a callback is provided this function returns a function that will call the callback and log the deprecation notice, otherwise it just logs the deprecation notice.
* @param options - The options for the log
* @param options.pkg - The package that is being deprecated
* @param options.subject - The subject of the deprecation
* @param options.transition - The transition path for the deprecation
* @param options.level - The level of the log
* @param options.message - The message of the log
* @param options.callback - A callback to run after the log
* @returns A function that will call the callback and log the deprecation notice if the callback is provided
* @example
* // Logs a deprecation notice
* log.deprecate({ pkg: "@onflow/fcl", subject: "Some item", transition: "https://github.com/onflow/flow-js-sdk", message: "Descriptive message", level: LEVELS.warn, callback: () => {} })
*
* @example
* function someFunction() { ... }
* const deprecatedFunction = log.deprecate({ pkg: "@onflow/fcl", subject: "Some item", transition: "https://github.com/foo/bar/TRANSITIONS.md", message: "Descriptive message", level: LEVELS.warn, callback: someFunction })
* deprecatedFunction() // Calls someFunction and logs the deprecation notice
*/
log.deprecate = ({ pkg, subject, transition, level = LEVELS.warn, message = "", callback = null, }) => {
const capitalizeFirstLetter = string => {
return string.charAt(0).toUpperCase() + string.slice(1);
log.deprecate = options => {
const {
pkg,
subject,
transition,
level = LEVELS.warn,
message = "",
callback = null
} = options;
const capitalizeFirstLetter = str => {
return str.charAt(0).toUpperCase() + str.slice(1);
};
const logMessage = () => log({
title: `${pkg ? pkg + " " : ""}Deprecation Notice`,
message: `
${subject ? `${capitalizeFirstLetter(subject)} is deprecated and will cease to work in future releases${pkg ? " of " + pkg : ""}.` : ""}${message ? "\n" + message : ""}${transition ? `\nYou can learn more (including a guide on common transition paths) here: ${transition}` : ""}
`.trim(),
level
});
if (typeof callback === "function") {
return async function () {
await logMessage();
return await callback(...arguments);
};
const logMessage = () => log({
title: `${pkg ? pkg + " " : ""}Deprecation Notice`,
message: `
${subject
? `${capitalizeFirstLetter(subject)} is deprecated and will cease to work in future releases${pkg ? " of " + pkg : ""}.`
: ""}${message ? "\n" + message : ""}${transition
? `\nYou can learn more (including a guide on common transition paths) here: ${transition}`
: ""}
`.trim(),
level,
});
if (typeof callback === "function") {
return (...args) => __awaiter(void 0, void 0, void 0, function* () {
yield logMessage();
return yield callback(...args);
});
}
return logMessage();
}
return logMessage();
};

@@ -175,2 +140,3 @@

exports.log = log;
exports.setConfig = setConfig;
//# sourceMappingURL=util-logger.js.map

@@ -1,77 +0,34 @@

import { config } from '@onflow/config';
// Config dependency injected into logger to break circular dependency
let config = null;
const setConfig = _config => {
config = _config;
};
/******************************************************************************
Copyright (c) Microsoft Corporation.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
***************************************************************************** */
function __awaiter(thisArg, _arguments, P, generator) {
function adopt(value) {
return value instanceof P ? value : new P(function (resolve) {
resolve(value);
});
}
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) {
try {
step(generator.next(value));
} catch (e) {
reject(e);
}
}
function rejected(value) {
try {
step(generator["throw"](value));
} catch (e) {
reject(e);
}
}
function step(result) {
result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
}
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
}
/**
* The levels of the logger
*
* @typedef {Object} LEVELS
* @property {number} debug - The debug level
* @property {number} info - The info level
* @property {number} log - The log level
* @property {number} warn - The warn level
* @property {number} error - The error level
*
*/
const LEVELS = Object.freeze({
debug: 5,
info: 4,
log: 3,
warn: 2,
error: 1,
});
let LEVELS = /*#__PURE__*/function (LEVELS) {
LEVELS[LEVELS["debug"] = 5] = "debug";
LEVELS[LEVELS["info"] = 4] = "info";
LEVELS[LEVELS["log"] = 3] = "log";
LEVELS[LEVELS["warn"] = 2] = "warn";
LEVELS[LEVELS["error"] = 1] = "error";
return LEVELS;
}({});
/**
* Builds a message formatted for the logger
*
* @param {Object} options - The options for the log
* @param {string} options.title - The title of the log
* @param {string} options.message - The message of the log
* @returns {Array<string>} - The message formatted for the logger
*
* @param options - The options for the log
* @param options.title - The title of the log
* @param options.message - The message of the log
* @returns The message formatted for the logger
* @example
* buildLoggerMessageArgs({ title: "My Title", message: "My Message" })
*/
const buildLoggerMessageArgs = ({ title, message }) => {
return [
`
const buildLoggerMessageArgs = options => {
const {
title,
message
} = options;
return [`
%c${title}

@@ -83,87 +40,95 @@ ============================

============================
`
.replace(/\n[^\S\r\n]+/g, "\n")
.trim(),
,
"font-weight:bold;font-family:monospace;",
];
`.replace(/\n[^\S\r\n]+/g, "\n").trim(), "font-weight:bold;font-family:monospace;"];
};
/**
* Logs messages based on the level of the message and the level set in the config
*
* @param {Object} options - The options for the log
* @param {string} options.title - The title of the log
* @param {string} options.message - The message of the log
* @param {number} options.level - The level of the log
* @param {boolean} options.always - Whether to always show the log
* @returns {Promise<void>}
*
* @param options - The options for the log
* @param options.title - The title of the log
* @param options.message - The message of the log
* @param options.level - The level of the log
* @param options.always - Whether to always show the log
* @example
* log({ title: "My Title", message: "My Message", level: LEVELS.warn, always: false })
*
*/
const log = ({ title, message, level, always = false }) => __awaiter(void 0, void 0, void 0, function* () {
const configLoggerLevel = yield config.get("logger.level", LEVELS.warn);
// If config level is below message level then don't show it
if (!always && configLoggerLevel < level)
return;
const loggerMessageArgs = buildLoggerMessageArgs({ title, message });
switch (level) {
case LEVELS.debug:
console.debug(...loggerMessageArgs);
break;
case LEVELS.info:
console.info(...loggerMessageArgs);
break;
case LEVELS.warn:
console.warn(...loggerMessageArgs);
break;
case LEVELS.error:
console.error(...loggerMessageArgs);
break;
default:
console.log(...loggerMessageArgs);
}
});
const log = async options => {
const {
title,
message,
level,
always
} = options;
const configLoggerLevel = await config.get("logger.level", LEVELS.warn);
// If config level is below message level then don't show it
if (!always && configLoggerLevel < level) return;
const loggerMessageArgs = buildLoggerMessageArgs({
title,
message
});
switch (level) {
case LEVELS.debug:
console.debug(...loggerMessageArgs);
break;
case LEVELS.info:
console.info(...loggerMessageArgs);
break;
case LEVELS.warn:
console.warn(...loggerMessageArgs);
break;
case LEVELS.error:
console.error(...loggerMessageArgs);
break;
default:
console.log(...loggerMessageArgs);
}
};
/**
* Logs a deprecation notice
*
* @param {Object} options - The options for the log
* @param {string} options.pkg - The package that is being deprecated
* @param {string} options.subject - The subject of the deprecation
* @param {string} options.transition - The transition path for the deprecation
* @param {number} options.level - The level of the log
* @param {string} options.message - The message of the log
* @param {Function} options.callback - A callback to run after the log
* @returns {Promise<void>}
*
* Logs a deprecation notice. If a callback is provided this function returns a function that will call the callback and log the deprecation notice, otherwise it just logs the deprecation notice.
* @param options - The options for the log
* @param options.pkg - The package that is being deprecated
* @param options.subject - The subject of the deprecation
* @param options.transition - The transition path for the deprecation
* @param options.level - The level of the log
* @param options.message - The message of the log
* @param options.callback - A callback to run after the log
* @returns A function that will call the callback and log the deprecation notice if the callback is provided
* @example
* // Logs a deprecation notice
* log.deprecate({ pkg: "@onflow/fcl", subject: "Some item", transition: "https://github.com/onflow/flow-js-sdk", message: "Descriptive message", level: LEVELS.warn, callback: () => {} })
*
* @example
* function someFunction() { ... }
* const deprecatedFunction = log.deprecate({ pkg: "@onflow/fcl", subject: "Some item", transition: "https://github.com/foo/bar/TRANSITIONS.md", message: "Descriptive message", level: LEVELS.warn, callback: someFunction })
* deprecatedFunction() // Calls someFunction and logs the deprecation notice
*/
log.deprecate = ({ pkg, subject, transition, level = LEVELS.warn, message = "", callback = null, }) => {
const capitalizeFirstLetter = string => {
return string.charAt(0).toUpperCase() + string.slice(1);
log.deprecate = options => {
const {
pkg,
subject,
transition,
level = LEVELS.warn,
message = "",
callback = null
} = options;
const capitalizeFirstLetter = str => {
return str.charAt(0).toUpperCase() + str.slice(1);
};
const logMessage = () => log({
title: `${pkg ? pkg + " " : ""}Deprecation Notice`,
message: `
${subject ? `${capitalizeFirstLetter(subject)} is deprecated and will cease to work in future releases${pkg ? " of " + pkg : ""}.` : ""}${message ? "\n" + message : ""}${transition ? `\nYou can learn more (including a guide on common transition paths) here: ${transition}` : ""}
`.trim(),
level
});
if (typeof callback === "function") {
return async function () {
await logMessage();
return await callback(...arguments);
};
const logMessage = () => log({
title: `${pkg ? pkg + " " : ""}Deprecation Notice`,
message: `
${subject
? `${capitalizeFirstLetter(subject)} is deprecated and will cease to work in future releases${pkg ? " of " + pkg : ""}.`
: ""}${message ? "\n" + message : ""}${transition
? `\nYou can learn more (including a guide on common transition paths) here: ${transition}`
: ""}
`.trim(),
level,
});
if (typeof callback === "function") {
return (...args) => __awaiter(void 0, void 0, void 0, function* () {
yield logMessage();
return yield callback(...args);
});
}
return logMessage();
}
return logMessage();
};
export { LEVELS, log };
export { LEVELS, log, setConfig };
//# sourceMappingURL=util-logger.module.js.map
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@onflow/config')) :
typeof define === 'function' && define.amd ? define(['exports', '@onflow/config'], factory) :
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["onflowUtil-logger"] = {}, global.config));
})(this, (function (exports, config) { 'use strict';
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
typeof define === 'function' && define.amd ? define(['exports'], factory) :
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["onflowUtil-logger"] = {}));
})(this, (function (exports) { 'use strict';
/******************************************************************************
Copyright (c) Microsoft Corporation.
// Config dependency injected into logger to break circular dependency
let config = null;
const setConfig = _config => {
config = _config;
};
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted.
/**
* The levels of the logger
*/
let LEVELS = /*#__PURE__*/function (LEVELS) {
LEVELS[LEVELS["debug"] = 5] = "debug";
LEVELS[LEVELS["info"] = 4] = "info";
LEVELS[LEVELS["log"] = 3] = "log";
LEVELS[LEVELS["warn"] = 2] = "warn";
LEVELS[LEVELS["error"] = 1] = "error";
return LEVELS;
}({});
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
***************************************************************************** */
function __awaiter(thisArg, _arguments, P, generator) {
function adopt(value) {
return value instanceof P ? value : new P(function (resolve) {
resolve(value);
});
}
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) {
try {
step(generator.next(value));
} catch (e) {
reject(e);
}
}
function rejected(value) {
try {
step(generator["throw"](value));
} catch (e) {
reject(e);
}
}
function step(result) {
result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
}
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
}
/**
* The levels of the logger
*
* @typedef {Object} LEVELS
* @property {number} debug - The debug level
* @property {number} info - The info level
* @property {number} log - The log level
* @property {number} warn - The warn level
* @property {number} error - The error level
*
*/
const LEVELS = Object.freeze({
debug: 5,
info: 4,
log: 3,
warn: 2,
error: 1,
});
/**
* Builds a message formatted for the logger
*
* @param {Object} options - The options for the log
* @param {string} options.title - The title of the log
* @param {string} options.message - The message of the log
* @returns {Array<string>} - The message formatted for the logger
*
* @example
* buildLoggerMessageArgs({ title: "My Title", message: "My Message" })
*/
const buildLoggerMessageArgs = ({ title, message }) => {
return [
`
/**
* Builds a message formatted for the logger
* @param options - The options for the log
* @param options.title - The title of the log
* @param options.message - The message of the log
* @returns The message formatted for the logger
* @example
* buildLoggerMessageArgs({ title: "My Title", message: "My Message" })
*/
const buildLoggerMessageArgs = options => {
const {
title,
message
} = options;
return [`
%c${title}

@@ -87,92 +46,101 @@ ============================

============================
`
.replace(/\n[^\S\r\n]+/g, "\n")
.trim(),
,
"font-weight:bold;font-family:monospace;",
];
`.replace(/\n[^\S\r\n]+/g, "\n").trim(), "font-weight:bold;font-family:monospace;"];
};
/**
* Logs messages based on the level of the message and the level set in the config
* @param options - The options for the log
* @param options.title - The title of the log
* @param options.message - The message of the log
* @param options.level - The level of the log
* @param options.always - Whether to always show the log
* @example
* log({ title: "My Title", message: "My Message", level: LEVELS.warn, always: false })
*/
const log = async options => {
const {
title,
message,
level,
always
} = options;
const configLoggerLevel = await config.get("logger.level", LEVELS.warn);
// If config level is below message level then don't show it
if (!always && configLoggerLevel < level) return;
const loggerMessageArgs = buildLoggerMessageArgs({
title,
message
});
switch (level) {
case LEVELS.debug:
console.debug(...loggerMessageArgs);
break;
case LEVELS.info:
console.info(...loggerMessageArgs);
break;
case LEVELS.warn:
console.warn(...loggerMessageArgs);
break;
case LEVELS.error:
console.error(...loggerMessageArgs);
break;
default:
console.log(...loggerMessageArgs);
}
};
/**
* Logs a deprecation notice. If a callback is provided this function returns a function that will call the callback and log the deprecation notice, otherwise it just logs the deprecation notice.
* @param options - The options for the log
* @param options.pkg - The package that is being deprecated
* @param options.subject - The subject of the deprecation
* @param options.transition - The transition path for the deprecation
* @param options.level - The level of the log
* @param options.message - The message of the log
* @param options.callback - A callback to run after the log
* @returns A function that will call the callback and log the deprecation notice if the callback is provided
* @example
* // Logs a deprecation notice
* log.deprecate({ pkg: "@onflow/fcl", subject: "Some item", transition: "https://github.com/onflow/flow-js-sdk", message: "Descriptive message", level: LEVELS.warn, callback: () => {} })
* @example
* function someFunction() { ... }
* const deprecatedFunction = log.deprecate({ pkg: "@onflow/fcl", subject: "Some item", transition: "https://github.com/foo/bar/TRANSITIONS.md", message: "Descriptive message", level: LEVELS.warn, callback: someFunction })
* deprecatedFunction() // Calls someFunction and logs the deprecation notice
*/
log.deprecate = options => {
const {
pkg,
subject,
transition,
level = LEVELS.warn,
message = "",
callback = null
} = options;
const capitalizeFirstLetter = str => {
return str.charAt(0).toUpperCase() + str.slice(1);
};
/**
* Logs messages based on the level of the message and the level set in the config
*
* @param {Object} options - The options for the log
* @param {string} options.title - The title of the log
* @param {string} options.message - The message of the log
* @param {number} options.level - The level of the log
* @param {boolean} options.always - Whether to always show the log
* @returns {Promise<void>}
*
* @example
* log({ title: "My Title", message: "My Message", level: LEVELS.warn, always: false })
*
*/
const log = ({ title, message, level, always = false }) => __awaiter(void 0, void 0, void 0, function* () {
const configLoggerLevel = yield config.config.get("logger.level", LEVELS.warn);
// If config level is below message level then don't show it
if (!always && configLoggerLevel < level)
return;
const loggerMessageArgs = buildLoggerMessageArgs({ title, message });
switch (level) {
case LEVELS.debug:
console.debug(...loggerMessageArgs);
break;
case LEVELS.info:
console.info(...loggerMessageArgs);
break;
case LEVELS.warn:
console.warn(...loggerMessageArgs);
break;
case LEVELS.error:
console.error(...loggerMessageArgs);
break;
default:
console.log(...loggerMessageArgs);
}
const logMessage = () => log({
title: `${pkg ? pkg + " " : ""}Deprecation Notice`,
message: `
${subject ? `${capitalizeFirstLetter(subject)} is deprecated and will cease to work in future releases${pkg ? " of " + pkg : ""}.` : ""}${message ? "\n" + message : ""}${transition ? `\nYou can learn more (including a guide on common transition paths) here: ${transition}` : ""}
`.trim(),
level
});
/**
* Logs a deprecation notice
*
* @param {Object} options - The options for the log
* @param {string} options.pkg - The package that is being deprecated
* @param {string} options.subject - The subject of the deprecation
* @param {string} options.transition - The transition path for the deprecation
* @param {number} options.level - The level of the log
* @param {string} options.message - The message of the log
* @param {Function} options.callback - A callback to run after the log
* @returns {Promise<void>}
*
* @example
* log.deprecate({ pkg: "@onflow/fcl", subject: "Some item", transition: "https://github.com/onflow/flow-js-sdk", message: "Descriptive message", level: LEVELS.warn, callback: () => {} })
*
*/
log.deprecate = ({ pkg, subject, transition, level = LEVELS.warn, message = "", callback = null, }) => {
const capitalizeFirstLetter = string => {
return string.charAt(0).toUpperCase() + string.slice(1);
};
const logMessage = () => log({
title: `${pkg ? pkg + " " : ""}Deprecation Notice`,
message: `
${subject
? `${capitalizeFirstLetter(subject)} is deprecated and will cease to work in future releases${pkg ? " of " + pkg : ""}.`
: ""}${message ? "\n" + message : ""}${transition
? `\nYou can learn more (including a guide on common transition paths) here: ${transition}`
: ""}
`.trim(),
level,
});
if (typeof callback === "function") {
return (...args) => __awaiter(void 0, void 0, void 0, function* () {
yield logMessage();
return yield callback(...args);
});
}
return logMessage();
};
if (typeof callback === "function") {
return async function () {
await logMessage();
return await callback(...arguments);
};
}
return logMessage();
};
exports.LEVELS = LEVELS;
exports.log = log;
exports.LEVELS = LEVELS;
exports.log = log;
exports.setConfig = setConfig;
Object.defineProperty(exports, '__esModule', { value: true });
Object.defineProperty(exports, '__esModule', { value: true });
}));
//# sourceMappingURL=util-logger.umd.js.map
{
"name": "@onflow/util-logger",
"version": "1.3.0-alpha.0",
"version": "1.3.0-typescript.0",
"description": "Logger for FCL-JS",

@@ -16,3 +16,9 @@ "license": "Apache-2.0",

"devDependencies": {
"@onflow/fcl-bundle": "^1.4.0-alpha.0",
"@babel/preset-typescript": "^7.22.5",
"@onflow/fcl-bundle": "^1.4.0-typescript.0",
"@types/jest": "^29.5.3",
"@typescript-eslint/eslint-plugin": "^6.4.0",
"@typescript-eslint/parser": "^6.4.0",
"eslint": "^8.47.0",
"eslint-plugin-jsdoc": "^46.4.6",
"jest": "^29.5.0"

@@ -24,2 +30,3 @@ },

"unpkg": "dist/util-logger.umd.js",
"types": "dist/util-logger.d.ts",
"scripts": {

@@ -33,5 +40,12 @@ "prepublishOnly": "npm test && npm run build",

"dependencies": {
"@babel/runtime": "^7.18.6",
"@onflow/config": "^1.2.0-alpha.0"
"@babel/runtime": "^7.18.6"
},
"peerDependencies": {
"@onflow/util-config": ">1.1.1"
},
"peerDependenciesMeta": {
"@onflow/util-config": {
"optional": true
}
}
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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