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.2.1 to 1.3.0-alpha.0

dist/types/util-logger.d.ts

11

CHANGELOG.md
# @onflow/util-logger
## 1.3.0-alpha.0
### Minor Changes
- TS build
### Patch Changes
- Updated dependencies []:
- @onflow/config@1.2.0-alpha.0
## 1.2.1

@@ -4,0 +15,0 @@

192

dist/util-logger.js

@@ -7,5 +7,47 @@ 'use strict';

/******************************************************************************
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

@@ -17,15 +59,14 @@ * @property {number} debug - The debug level

* @property {number} error - The error level
*
*
*/
const LEVELS = Object.freeze({
debug: 5,
info: 4,
log: 3,
warn: 2,
error: 1
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

@@ -35,12 +76,9 @@ * @param {string} options.title - The title of the log

* @returns {Array<string>} - The message formatted for the logger
*
*
* @example
* buildLoggerMessageArgs({ title: "My Title", message: "My Message" })
*/
const buildLoggerMessageArgs = _ref => {
let {
title,
message
} = _ref;
return [`
const buildLoggerMessageArgs = ({ title, message }) => {
return [
`
%c${title}

@@ -52,8 +90,12 @@ ============================

============================
`.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

@@ -65,43 +107,33 @@ * @param {string} options.title - The title of the log

* @returns {Promise<void>}
*
*
* @example
* log({ title: "My Title", message: "My Message", level: LEVELS.warn, always: false })
*
*
*/
const log = async _ref2 => {
let {
title,
message,
level,
always = false
} = _ref2;
const configLoggerLevel = await 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 = ({ 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);
}
});
/**
* Logs a deprecation notice
*
*
* @param {Object} options - The options for the log

@@ -115,33 +147,29 @@ * @param {string} options.pkg - The package that is being deprecated

* @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 = _ref3 => {
let {
pkg,
subject,
transition,
level = LEVELS.warn,
message = "",
callback = null
} = _ref3;
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}` : ""}
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 async function () {
await logMessage();
return await callback(...arguments);
};
}
return logMessage();
level,
});
if (typeof callback === "function") {
return (...args) => __awaiter(void 0, void 0, void 0, function* () {
yield logMessage();
return yield callback(...args);
});
}
return logMessage();
};

@@ -148,0 +176,0 @@

import { config } from '@onflow/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

@@ -12,15 +54,14 @@ * @property {number} debug - The debug level

* @property {number} error - The error level
*
*
*/
const LEVELS = Object.freeze({
debug: 5,
info: 4,
log: 3,
warn: 2,
error: 1
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

@@ -30,12 +71,9 @@ * @param {string} options.title - The title of the log

* @returns {Array<string>} - The message formatted for the logger
*
*
* @example
* buildLoggerMessageArgs({ title: "My Title", message: "My Message" })
*/
const buildLoggerMessageArgs = _ref => {
let {
title,
message
} = _ref;
return [`
const buildLoggerMessageArgs = ({ title, message }) => {
return [
`
%c${title}

@@ -47,8 +85,12 @@ ============================

============================
`.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

@@ -60,43 +102,33 @@ * @param {string} options.title - The title of the log

* @returns {Promise<void>}
*
*
* @example
* log({ title: "My Title", message: "My Message", level: LEVELS.warn, always: false })
*
*
*/
const log = async _ref2 => {
let {
title,
message,
level,
always = false
} = _ref2;
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);
}
};
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);
}
});
/**
* Logs a deprecation notice
*
*
* @param {Object} options - The options for the log

@@ -110,33 +142,29 @@ * @param {string} options.pkg - The package that is being deprecated

* @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 = _ref3 => {
let {
pkg,
subject,
transition,
level = LEVELS.warn,
message = "",
callback = null
} = _ref3;
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}` : ""}
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 async function () {
await logMessage();
return await callback(...arguments);
};
}
return logMessage();
level,
});
if (typeof callback === "function") {
return (...args) => __awaiter(void 0, void 0, void 0, function* () {
yield logMessage();
return yield callback(...args);
});
}
return logMessage();
};

@@ -143,0 +171,0 @@

(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));
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';
/**
* 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
});
/******************************************************************************
Copyright (c) Microsoft Corporation.
/**
* 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 = _ref => {
let {
title,
message
} = _ref;
return [`
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,
});
/**
* 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 [
`
%c${title}

@@ -49,102 +87,92 @@ ============================

============================
`.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>}
*
* @example
* log({ title: "My Title", message: "My Message", level: LEVELS.warn, always: false })
*
*/
const log = async _ref2 => {
let {
title,
message,
level,
always = false
} = _ref2;
const configLoggerLevel = await 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
`
.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>}
*
* @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);
}
});
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>}
*
* @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 = _ref3 => {
let {
pkg,
subject,
transition,
level = LEVELS.warn,
message = "",
callback = null
} = _ref3;
const capitalizeFirstLetter = string => {
return string.charAt(0).toUpperCase() + string.slice(1);
/**
* 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();
};
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);
};
}
return logMessage();
};
exports.LEVELS = LEVELS;
exports.log = log;
exports.LEVELS = LEVELS;
exports.log = log;
Object.defineProperty(exports, '__esModule', { value: true });
Object.defineProperty(exports, '__esModule', { value: true });
}));
//# sourceMappingURL=util-logger.umd.js.map
{
"name": "@onflow/util-logger",
"version": "1.2.1",
"version": "1.3.0-alpha.0",
"description": "Logger for FCL-JS",

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

"devDependencies": {
"@onflow/fcl-bundle": "^1.3.1",
"@onflow/fcl-bundle": "^1.4.0-alpha.0",
"jest": "^29.5.0"
},
"source": "src/util-logger.js",
"source": "src/util-logger.ts",
"main": "dist/util-logger.js",

@@ -33,4 +33,4 @@ "module": "dist/util-logger.module.js",

"@babel/runtime": "^7.18.6",
"@onflow/config": "^1.1.1"
"@onflow/config": "^1.2.0-alpha.0"
}
}

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