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

@probe.gl/log

Package Overview
Dependencies
Maintainers
3
Versions
23
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@probe.gl/log - npm Package Compare versions

Comparing version 3.5.0-alpha.4 to 3.5.0-alpha.5

79

dist/es5/log.js

@@ -46,12 +46,2 @@ "use strict";

function getTableHeader(table) {
for (const key in table) {
for (const title in table[key]) {
return title || 'untitled';
}
}
return 'empty';
}
class Log {

@@ -68,5 +58,5 @@ constructor() {

(0, _defineProperty2.default)(this, "_deltaTs", (0, _hiResTimestamp.getHiResTimestamp)());
(0, _defineProperty2.default)(this, "LOG_THROTTLE_TIMEOUT", 0);
(0, _defineProperty2.default)(this, "_storage", void 0);
(0, _defineProperty2.default)(this, "userData", {});
(0, _defineProperty2.default)(this, "LOG_THROTTLE_TIMEOUT", 0);
this.id = id;

@@ -134,2 +124,20 @@ this._storage = new _localStorage.default("__probe-".concat(this.id, "__"), DEFAULT_SETTINGS);

get(setting) {
return this._storage.config[setting];
}
set(setting, value) {
this._storage.updateConfiguration({
[setting]: value
});
}
settings() {
if (console.table) {
console.table(this._storage.config);
} else {
console.log(this._storage.config);
}
}
assert(condition, message) {

@@ -171,2 +179,6 @@ (0, _assert.default)(condition, message);

once(logLevel, message) {
for (var _len = arguments.length, args = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
args[_key - 2] = arguments[_key];
}
return this._getLogFunction(logLevel, message, originalConsole.debug || originalConsole.info, arguments, ONCE);

@@ -209,20 +221,2 @@ }

settings() {
if (console.table) {
console.table(this._storage.config);
} else {
console.log(this._storage.config);
}
}
get(setting) {
return this._storage.config[setting];
}
set(setting, value) {
this._storage.updateConfiguration({
[setting]: value
});
}
time(logLevel, message) {

@@ -244,3 +238,3 @@ return this._getLogFunction(logLevel, message, console.time ? console.time : console.info);

};
opts = normalizeArguments({
const options = normalizeArguments({
logLevel,

@@ -253,4 +247,4 @@ message,

} = opts;
opts.method = (collapsed ? console.groupCollapsed : console.group) || console.info;
return this._getLogFunction(opts);
options.method = (collapsed ? console.groupCollapsed : console.group) || console.info;
return this._getLogFunction(options);
}

@@ -289,6 +283,3 @@

_getLogFunction(logLevel, message, method) {
let args = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : [];
let opts = arguments.length > 4 ? arguments[4] : undefined;
_getLogFunction(logLevel, message, method, args, opts) {
if (this._shouldLog(logLevel)) {

@@ -362,4 +353,2 @@ opts = normalizeArguments({

opts.args = args;
switch (typeof logLevel) {

@@ -388,3 +377,5 @@ case 'string':

(0, _assert.default)(messageType === 'string' || messageType === 'object');
return Object.assign(opts, opts.opts);
return Object.assign(opts, {
args
}, opts.opts);
}

@@ -461,2 +452,12 @@

}
function getTableHeader(table) {
for (const key in table) {
for (const title in table[key]) {
return title || 'untitled';
}
}
return 'empty';
}
//# sourceMappingURL=log.js.map

@@ -27,13 +27,2 @@ import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";

};
function getTableHeader(table) {
for (const key in table) {
for (const title in table[key]) {
return title || 'untitled';
}
}
return 'empty';
}
export default class Log {

@@ -55,4 +44,2 @@ constructor() {

_defineProperty(this, "LOG_THROTTLE_TIMEOUT", 0);
_defineProperty(this, "_storage", void 0);

@@ -62,2 +49,4 @@

_defineProperty(this, "LOG_THROTTLE_TIMEOUT", 0);
this.id = id;

@@ -125,2 +114,20 @@ this._storage = new LocalStorage("__probe-".concat(this.id, "__"), DEFAULT_SETTINGS);

get(setting) {
return this._storage.config[setting];
}
set(setting, value) {
this._storage.updateConfiguration({
[setting]: value
});
}
settings() {
if (console.table) {
console.table(this._storage.config);
} else {
console.log(this._storage.config);
}
}
assert(condition, message) {

@@ -162,2 +169,6 @@ assert(condition, message);

once(logLevel, message) {
for (var _len = arguments.length, args = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
args[_key - 2] = arguments[_key];
}
return this._getLogFunction(logLevel, message, originalConsole.debug || originalConsole.info, arguments, ONCE);

@@ -200,20 +211,2 @@ }

settings() {
if (console.table) {
console.table(this._storage.config);
} else {
console.log(this._storage.config);
}
}
get(setting) {
return this._storage.config[setting];
}
set(setting, value) {
this._storage.updateConfiguration({
[setting]: value
});
}
time(logLevel, message) {

@@ -235,3 +228,3 @@ return this._getLogFunction(logLevel, message, console.time ? console.time : console.info);

};
opts = normalizeArguments({
const options = normalizeArguments({
logLevel,

@@ -244,4 +237,4 @@ message,

} = opts;
opts.method = (collapsed ? console.groupCollapsed : console.group) || console.info;
return this._getLogFunction(opts);
options.method = (collapsed ? console.groupCollapsed : console.group) || console.info;
return this._getLogFunction(options);
}

@@ -280,6 +273,3 @@

_getLogFunction(logLevel, message, method) {
let args = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : [];
let opts = arguments.length > 4 ? arguments[4] : undefined;
_getLogFunction(logLevel, message, method, args, opts) {
if (this._shouldLog(logLevel)) {

@@ -352,4 +342,2 @@ opts = normalizeArguments({

opts.args = args;
switch (typeof logLevel) {

@@ -378,3 +366,5 @@ case 'string':

assert(messageType === 'string' || messageType === 'object');
return Object.assign(opts, opts.opts);
return Object.assign(opts, {
args
}, opts.opts);
}

@@ -451,2 +441,12 @@

}
function getTableHeader(table) {
for (const key in table) {
for (const title in table[key]) {
return title || 'untitled';
}
}
return 'empty';
}
//# sourceMappingURL=log.js.map
import LocalStorage from './utils/local-storage';
declare function noop(): void;
declare type LogFunction = () => void;
export default class Log {

@@ -9,29 +9,49 @@ static VERSION: any;

_deltaTs: number;
LOG_THROTTLE_TIMEOUT: number;
_storage: LocalStorage;
userData: {};
LOG_THROTTLE_TIMEOUT: number;
constructor({ id }?: {
id: string;
});
set level(newLevel: any);
get level(): any;
isEnabled(): any;
getLevel(): any;
set level(newLevel: number);
get level(): number;
isEnabled(): boolean;
getLevel(): number;
/** @return {Number} milliseconds, with fractions */
getTotal(): number;
/** @return {Number} milliseconds, with fractions */
getDelta(): number;
set priority(newPriority: any);
get priority(): any;
getPriority(): any;
/** @deprecated use logLevel */
set priority(newPriority: number);
/** @deprecated use logLevel */
get priority(): number;
/** @deprecated use logLevel */
getPriority(): number;
enable(enabled?: boolean): this;
setLevel(level: any): this;
assert(condition: any, message: any): void;
warn(message: any): any;
error(message: any): any;
deprecated(oldUsage: any, newUsage: any): any;
removed(oldUsage: any, newUsage: any): any;
probe(logLevel: any, message?: any): any;
log(logLevel: any, message?: any): any;
info(logLevel: any, message?: any): any;
once(logLevel: any, message?: any): any;
table(logLevel: any, table: any, columns: any): any;
setLevel(level: number): this;
/** return the current status of the setting */
get(setting: string): any;
set(setting: string, value: any): void;
/** Logs the current settings as a table */
settings(): void;
assert(condition: unknown, message?: string): void;
/** Warn, but only once, no console flooding */
warn(message: string, ...args: any[]): LogFunction;
/** Print an error */
error(message: string, ...args: any[]): LogFunction;
/** Print a deprecation warning */
deprecated(oldUsage: string, newUsage: string): LogFunction;
/** Print a removal warning */
removed(oldUsage: string, newUsage: string): LogFunction;
/** Log to a group */
probe(logLevel: any, message?: any, ...args: any[]): LogFunction;
/** Log a debug message */
log(logLevel: any, message?: any, ...args: any[]): LogFunction;
/** Log a normal message */
info(logLevel: any, message?: any, ...args: any[]): LogFunction;
/** Log a normal message, but only once, no console flooding */
once(logLevel: any, message?: any, ...args: any[]): LogFunction;
/** Logs an object as a table */
table(logLevel: any, table?: any, columns?: any): LogFunction;
/** logs an image under Chrome */
image({ logLevel, priority, image, message, scale }: {

@@ -43,21 +63,36 @@ logLevel: any;

scale?: number;
}): typeof noop;
settings(): void;
get(setting: any): any;
set(setting: any, value: any): void;
time(logLevel: any, message: any): any;
timeEnd(logLevel: any, message: any): any;
timeStamp(logLevel: any, message?: any): any;
}): LogFunction;
time(logLevel: any, message: any): LogFunction;
timeEnd(logLevel: any, message: any): LogFunction;
timeStamp(logLevel: any, message?: any): LogFunction;
group(logLevel: any, message: any, opts?: {
collapsed: boolean;
}): any;
groupCollapsed(logLevel: any, message: any, opts?: {}): any;
groupEnd(logLevel: any): any;
withGroup(logLevel: any, message: any, func: any): void;
}): LogFunction;
groupCollapsed(logLevel: any, message: any, opts?: {}): LogFunction;
groupEnd(logLevel: any): LogFunction;
withGroup(logLevel: number, message: string, func: Function): void;
trace(): void;
_shouldLog(logLevel: any): boolean;
_getLogFunction(logLevel: any, message: any, method: any, args?: any[], opts?: Record<string, any>): any;
/** Deduces log level from a variety of arguments */
_shouldLog(logLevel: unknown): boolean;
_getLogFunction(logLevel: unknown, message?: unknown, method?: Function, args?: IArguments, opts?: Record<string, any>): LogFunction;
}
export declare function normalizeArguments(opts: any): any;
/**
* "Normalizes" the various argument patterns into an object with known types
* - log(logLevel, message, args) => {logLevel, message, args}
* - log(message, args) => {logLevel: 0, message, args}
* - log({logLevel, ...}, message, args) => {logLevel, message, args}
* - log({logLevel, message, args}) => {logLevel, message, args}
*/
export declare function normalizeArguments(opts: {
logLevel: any;
message: any;
collapsed?: boolean;
args?: IArguments;
opts?: any;
}): {
logLevel: number;
message: string;
args: any[];
};
export {};
//# sourceMappingURL=log.d.ts.map

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

// Copyright (c) 2017 Uber Technologies, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
// probe.gl, MIT license
/* eslint-disable no-console */

@@ -28,3 +10,2 @@ import { VERSION, isBrowser } from '@probe.gl/env';

import { getHiResTimestamp } from './utils/hi-res-timestamp';
/* eslint-disable no-console */
// Instrumentation in other packages may override console methods, so preserve them here

@@ -45,37 +26,2 @@ const originalConsole = {

const ONCE = { once: true };
/*
function throttle(tag, timeout) {
const prevTime = cache[tag];
const time = Date.now();
if (!prevTime || (time - prevTime > timeout)) {
cache[tag] = time;
return true;
}
return false;
}
// Assertions don't generate standard exceptions and don't print nicely
function checkForAssertionErrors(args) {
const isAssertion =
args &&
args.length > 0 &&
typeof args[0] === 'object' &&
args[0] !== null &&
args[0].name === 'AssertionError';
if (isAssertion) {
args = Array.prototype.slice.call(args);
args.unshift(`assert(${args[0].message})`);
}
return args;
}
*/
function getTableHeader(table) {
for (const key in table) {
for (const title in table[key]) {
return title || 'untitled';
}
}
return 'empty';
}
// A console wrapper

@@ -87,5 +33,5 @@ export default class Log {

this._deltaTs = getHiResTimestamp();
this.userData = {};
// TODO - fix support from throttling groups
this.LOG_THROTTLE_TIMEOUT = 0; // Time before throttled messages are logged again
this.userData = {};
this.id = id;

@@ -110,17 +56,19 @@ this._storage = new LocalStorage(`__probe-${this.id}__`, DEFAULT_SETTINGS);

}
// @return {Number} milliseconds, with fractions
/** @return {Number} milliseconds, with fractions */
getTotal() {
return Number((getHiResTimestamp() - this._startTs).toPrecision(10));
}
// @return {Number} milliseconds, with fractions
/** @return {Number} milliseconds, with fractions */
getDelta() {
return Number((getHiResTimestamp() - this._deltaTs).toPrecision(10));
}
// Deprecated
/** @deprecated use logLevel */
set priority(newPriority) {
this.level = newPriority;
}
/** @deprecated use logLevel */
get priority() {
return this.level;
}
/** @deprecated use logLevel */
getPriority() {

@@ -138,2 +86,19 @@ return this.level;

}
/** return the current status of the setting */
get(setting) {
return this._storage.config[setting];
}
// update the status of the setting
set(setting, value) {
this._storage.updateConfiguration({ [setting]: value });
}
/** Logs the current settings as a table */
settings() {
if (console.table) {
console.table(this._storage.config);
}
else {
console.log(this._storage.config);
}
}
// Unconditional logging

@@ -143,12 +108,9 @@ assert(condition, message) {

}
// Warn, but only once, no console flooding
warn(message) {
// @ts-expect-error
return this._getLogFunction(0, message, originalConsole.warn, arguments, ONCE);
}
// Print an error
error(message) {
// @ts-expect-error
return this._getLogFunction(0, message, originalConsole.error, arguments);
}
/** Print a deprecation warning */
deprecated(oldUsage, newUsage) {

@@ -158,9 +120,7 @@ return this.warn(`\`${oldUsage}\` is deprecated and will be removed \

}
/** Print a removal warning */
removed(oldUsage, newUsage) {
return this.error(`\`${oldUsage}\` has been removed. Use \`${newUsage}\` instead`);
}
// Conditional logging
// Log to a group
probe(logLevel, message) {
// @ts-expect-error
return this._getLogFunction(logLevel, message, originalConsole.log, arguments, {

@@ -171,21 +131,15 @@ time: true,

}
// Log a debug message
log(logLevel, message) {
// @ts-expect-error
return this._getLogFunction(logLevel, message, originalConsole.debug, arguments);
}
// Log a normal message
info(logLevel, message) {
// @ts-expect-error
return this._getLogFunction(logLevel, message, console.info, arguments);
}
// Log a normal message, but only once, no console flooding
once(logLevel, message) {
return this._getLogFunction(logLevel, message, originalConsole.debug || originalConsole.info,
// @ts-expect-error
arguments, ONCE);
once(logLevel, message, ...args) {
return this._getLogFunction(logLevel, message, originalConsole.debug || originalConsole.info, arguments, ONCE);
}
// Logs an object as a table
/** Logs an object as a table */
table(logLevel, table, columns) {
if (table) {
// @ts-expect-error Not clear how this works, columns being passed as arguments
return this._getLogFunction(logLevel, table, console.table || noop, columns && [columns], {

@@ -197,3 +151,3 @@ tag: getTableHeader(table)

}
// logs an image under Chrome
/** logs an image under Chrome */
image({ logLevel, priority, image, message = '', scale = 1 }) {

@@ -207,19 +161,2 @@ if (!this._shouldLog(logLevel || priority)) {

}
// Logs the current settings as a table
settings() {
if (console.table) {
console.table(this._storage.config);
}
else {
console.log(this._storage.config);
}
}
// logs the current status of the setting
get(setting) {
return this._storage.config[setting];
}
// update the status of the setting
set(setting, value) {
this._storage.updateConfiguration({ [setting]: value });
}
time(logLevel, message) {

@@ -235,8 +172,7 @@ return this._getLogFunction(logLevel, message, console.time ? console.time : console.info);

group(logLevel, message, opts = { collapsed: false }) {
opts = normalizeArguments({ logLevel, message, opts });
const options = normalizeArguments({ logLevel, message, opts });
const { collapsed } = opts;
// @ts-expect-error
opts.method = (collapsed ? console.groupCollapsed : console.group) || console.info;
// @ts-expect-error
return this._getLogFunction(opts);
options.method = (collapsed ? console.groupCollapsed : console.group) || console.info;
return this._getLogFunction(options);
}

@@ -265,6 +201,7 @@ groupCollapsed(logLevel, message, opts = {}) {

// PRIVATE METHODS
/** Deduces log level from a variety of arguments */
_shouldLog(logLevel) {
return this.isEnabled() && this.getLevel() >= normalizeLogLevel(logLevel);
}
_getLogFunction(logLevel, message, method, args = [], opts) {
_getLogFunction(logLevel, message, method, args, opts) {
if (this._shouldLog(logLevel)) {

@@ -300,7 +237,9 @@ // normalized opts + timings

Log.VERSION = VERSION;
// Get logLevel from first argument:
// - log(logLevel, message, args) => logLevel
// - log(message, args) => 0
// - log({logLevel, ...}, message, args) => logLevel
// - log({logLevel, message, args}) => logLevel
/**
* Get logLevel from first argument:
* - log(logLevel, message, args) => logLevel
* - log(message, args) => 0
* - log({logLevel, ...}, message, args) => logLevel
* - log({logLevel, message, args}) => logLevel
*/
function normalizeLogLevel(logLevel) {

@@ -318,2 +257,3 @@ if (!logLevel) {

// TODO - deprecate `priority`
// @ts-expect-error
resolvedLevel = logLevel.logLevel || logLevel.priority || 0;

@@ -328,7 +268,9 @@ break;

}
// "Normalizes" the various argument patterns into an object with known types
// - log(logLevel, message, args) => {logLevel, message, args}
// - log(message, args) => {logLevel: 0, message, args}
// - log({logLevel, ...}, message, args) => {logLevel, message, args}
// - log({logLevel, message, args}) => {logLevel, message, args}
/**
* "Normalizes" the various argument patterns into an object with known types
* - log(logLevel, message, args) => {logLevel, message, args}
* - log(message, args) => {logLevel: 0, message, args}
* - log({logLevel, ...}, message, args) => {logLevel, message, args}
* - log({logLevel, message, args}) => {logLevel, message, args}
*/
export function normalizeArguments(opts) {

@@ -343,7 +285,5 @@ const { logLevel, message } = opts;

const args = opts.args ? Array.from(opts.args) : [];
/* eslint-disable no-empty */
// args should only contain arguments that appear after `message`
// eslint-disable-next-line no-empty
while (args.length && args.shift() !== message) { }
/* eslint-enable no-empty */
opts.args = args;
switch (typeof logLevel) {

@@ -370,3 +310,3 @@ case 'string':

// original opts + normalized opts + opts arg + fixed up message
return Object.assign(opts, opts.opts);
return Object.assign(opts, { args }, opts.opts);
}

@@ -381,3 +321,3 @@ function decorateMessage(id, message, opts) {

}
// Use the asciify module to log an image under node.js
/** Use the asciify module to log an image under node.js */
function logImageInNode({ image, message = '', scale = 1 }) {

@@ -420,1 +360,9 @@ // Note: Runtime load of the "asciify-image" module, avoids including in browser bundles

}
function getTableHeader(table) {
for (const key in table) {
for (const title in table[key]) {
return title || 'untitled';
}
}
return 'empty';
}

@@ -5,3 +5,3 @@ {

"license": "MIT",
"version": "3.5.0-alpha.4",
"version": "3.5.0-alpha.5",
"keywords": [

@@ -32,5 +32,5 @@ "javascript",

"@babel/runtime": "^7.0.0",
"@probe.gl/env": "3.5.0-alpha.4"
"@probe.gl/env": "3.5.0-alpha.5"
},
"gitHead": "5f0c4ef4db3b53b0be8ebabcf42e2bc276c7bf44"
"gitHead": "8717b64234cc62be48396c4ffbd614e7d7a42cfe"
}

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

// Copyright (c) 2017 Uber Technologies, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
// probe.gl, MIT license

@@ -30,4 +12,2 @@ /* eslint-disable no-console */

/* eslint-disable no-console */
// Instrumentation in other packages may override console methods, so preserve them here

@@ -42,3 +22,13 @@ const originalConsole = {

const DEFAULT_SETTINGS = {
type Table = Record<string, any>;
type LogFunction = () => void;
type LogSettings = {
enabled?: boolean;
level?: number;
[key: string]: any;
};
const DEFAULT_SETTINGS: Required<LogSettings> = {
enabled: true,

@@ -53,39 +43,2 @@ level: 0

/*
function throttle(tag, timeout) {
const prevTime = cache[tag];
const time = Date.now();
if (!prevTime || (time - prevTime > timeout)) {
cache[tag] = time;
return true;
}
return false;
}
// Assertions don't generate standard exceptions and don't print nicely
function checkForAssertionErrors(args) {
const isAssertion =
args &&
args.length > 0 &&
typeof args[0] === 'object' &&
args[0] !== null &&
args[0].name === 'AssertionError';
if (isAssertion) {
args = Array.prototype.slice.call(args);
args.unshift(`assert(${args[0].message})`);
}
return args;
}
*/
function getTableHeader(table) {
for (const key in table) {
for (const title in table[key]) {
return title || 'untitled';
}
}
return 'empty';
}
// A console wrapper

@@ -100,7 +53,8 @@

_deltaTs: number = getHiResTimestamp();
// TODO - fix support from throttling groups
LOG_THROTTLE_TIMEOUT: number = 0; // Time before throttled messages are logged again
_storage: LocalStorage;
userData = {};
// TODO - fix support from throttling groups
LOG_THROTTLE_TIMEOUT: number = 0; // Time before throttled messages are logged again
constructor({id} = {id: ''}) {

@@ -117,19 +71,19 @@ this.id = id;

set level(newLevel) {
set level(newLevel: number) {
this.setLevel(newLevel);
}
get level() {
get level(): number {
return this.getLevel();
}
isEnabled() {
isEnabled(): boolean {
return this._storage.config.enabled;
}
getLevel() {
getLevel(): number {
return this._storage.config.level;
}
// @return {Number} milliseconds, with fractions
/** @return {Number} milliseconds, with fractions */
getTotal() {

@@ -139,3 +93,3 @@ return Number((getHiResTimestamp() - this._startTs).toPrecision(10));

// @return {Number} milliseconds, with fractions
/** @return {Number} milliseconds, with fractions */
getDelta() {

@@ -145,3 +99,3 @@ return Number((getHiResTimestamp() - this._deltaTs).toPrecision(10));

// Deprecated
/** @deprecated use logLevel */
set priority(newPriority) {

@@ -151,2 +105,3 @@ this.level = newPriority;

/** @deprecated use logLevel */
get priority() {

@@ -156,2 +111,3 @@ return this.level;

/** @deprecated use logLevel */
getPriority() {

@@ -163,3 +119,3 @@ return this.level;

enable(enabled = true) {
enable(enabled: boolean = true): this {
this._storage.updateConfiguration({enabled});

@@ -169,3 +125,3 @@ return this;

setLevel(level) {
setLevel(level: number): this {
this._storage.updateConfiguration({level});

@@ -175,21 +131,41 @@ return this;

/** return the current status of the setting */
get(setting: string): any {
return this._storage.config[setting];
}
// update the status of the setting
set(setting: string, value: any): void {
this._storage.updateConfiguration({[setting]: value});
}
/** Logs the current settings as a table */
settings(): void {
if (console.table) {
console.table(this._storage.config);
} else {
console.log(this._storage.config);
}
}
// Unconditional logging
assert(condition, message) {
assert(condition: unknown, message?: string): void {
assert(condition, message);
}
// Warn, but only once, no console flooding
warn(message) {
// @ts-expect-error
/** Warn, but only once, no console flooding */
warn(message: string, ...args): LogFunction;
warn(message: string): LogFunction {
return this._getLogFunction(0, message, originalConsole.warn, arguments, ONCE);
}
// Print an error
error(message) {
// @ts-expect-error
/** Print an error */
error(message: string, ...args): LogFunction;
error(message: string): LogFunction {
return this._getLogFunction(0, message, originalConsole.error, arguments);
}
deprecated(oldUsage, newUsage) {
/** Print a deprecation warning */
deprecated(oldUsage: string, newUsage: string): LogFunction {
return this.warn(`\`${oldUsage}\` is deprecated and will be removed \

@@ -199,3 +175,4 @@ in a later version. Use \`${newUsage}\` instead`);

removed(oldUsage, newUsage) {
/** Print a removal warning */
removed(oldUsage: string, newUsage: string): LogFunction {
return this.error(`\`${oldUsage}\` has been removed. Use \`${newUsage}\` instead`);

@@ -206,5 +183,5 @@ }

// Log to a group
probe(logLevel, message?) {
// @ts-expect-error
/** Log to a group */
probe(logLevel, message?, ...args): LogFunction;
probe(logLevel, message?): LogFunction {
return this._getLogFunction(logLevel, message, originalConsole.log, arguments, {

@@ -216,16 +193,17 @@ time: true,

// Log a debug message
log(logLevel, message?) {
// @ts-expect-error
/** Log a debug message */
log(logLevel, message?, ...args): LogFunction;
log(logLevel, message?): LogFunction {
return this._getLogFunction(logLevel, message, originalConsole.debug, arguments);
}
// Log a normal message
info(logLevel, message?) {
// @ts-expect-error
/** Log a normal message */
info(logLevel, message?, ...args): LogFunction;
info(logLevel, message?): LogFunction {
return this._getLogFunction(logLevel, message, console.info, arguments);
}
// Log a normal message, but only once, no console flooding
once(logLevel, message?) {
/** Log a normal message, but only once, no console flooding */
once(logLevel, message?, ...args): LogFunction;
once(logLevel, message?, ...args) {
return this._getLogFunction(

@@ -235,3 +213,2 @@ logLevel,

originalConsole.debug || originalConsole.info,
// @ts-expect-error
arguments,

@@ -242,5 +219,6 @@ ONCE

// Logs an object as a table
table(logLevel, table, columns) {
/** Logs an object as a table */
table(logLevel, table?, columns?): LogFunction {
if (table) {
// @ts-expect-error Not clear how this works, columns being passed as arguments
return this._getLogFunction(logLevel, table, console.table || noop, columns && [columns], {

@@ -253,4 +231,4 @@ tag: getTableHeader(table)

// logs an image under Chrome
image({logLevel, priority, image, message = '', scale = 1}) {
/** logs an image under Chrome */
image({logLevel, priority, image, message = '', scale = 1}): LogFunction {
if (!this._shouldLog(logLevel || priority)) {

@@ -264,21 +242,2 @@ return noop;

// Logs the current settings as a table
settings() {
if (console.table) {
console.table(this._storage.config);
} else {
console.log(this._storage.config);
}
}
// logs the current status of the setting
get(setting) {
return this._storage.config[setting];
}
// update the status of the setting
set(setting, value) {
this._storage.updateConfiguration({[setting]: value});
}
time(logLevel, message) {

@@ -301,9 +260,8 @@ return this._getLogFunction(logLevel, message, console.time ? console.time : console.info);

group(logLevel, message, opts = {collapsed: false}) {
opts = normalizeArguments({logLevel, message, opts});
const options = normalizeArguments({logLevel, message, opts});
const {collapsed} = opts;
// @ts-expect-error
opts.method = (collapsed ? console.groupCollapsed : console.group) || console.info;
options.method = (collapsed ? console.groupCollapsed : console.group) || console.info;
// @ts-expect-error
return this._getLogFunction(opts);
return this._getLogFunction(options);
}

@@ -321,3 +279,3 @@

withGroup(logLevel, message, func) {
withGroup(logLevel: number, message: string, func: Function): void {
this.group(logLevel, message)();

@@ -332,3 +290,3 @@

trace() {
trace(): void {
if (console.trace) {

@@ -341,7 +299,14 @@ console.trace();

_shouldLog(logLevel) {
/** Deduces log level from a variety of arguments */
_shouldLog(logLevel: unknown): boolean {
return this.isEnabled() && this.getLevel() >= normalizeLogLevel(logLevel);
}
_getLogFunction(logLevel, message, method, args = [], opts?: Record<string, any>) {
_getLogFunction(
logLevel: unknown,
message?: unknown,
method?: Function,
args?: IArguments,
opts?: Record<string, any>
): LogFunction {
if (this._shouldLog(logLevel)) {

@@ -382,8 +347,10 @@ // normalized opts + timings

// Get logLevel from first argument:
// - log(logLevel, message, args) => logLevel
// - log(message, args) => 0
// - log({logLevel, ...}, message, args) => logLevel
// - log({logLevel, message, args}) => logLevel
function normalizeLogLevel(logLevel) {
/**
* Get logLevel from first argument:
* - log(logLevel, message, args) => logLevel
* - log(message, args) => 0
* - log({logLevel, ...}, message, args) => logLevel
* - log({logLevel, message, args}) => logLevel
*/
function normalizeLogLevel(logLevel: unknown): number {
if (!logLevel) {

@@ -402,2 +369,3 @@ return 0;

// TODO - deprecate `priority`
// @ts-expect-error
resolvedLevel = logLevel.logLevel || logLevel.priority || 0;

@@ -415,10 +383,23 @@ break;

// "Normalizes" the various argument patterns into an object with known types
// - log(logLevel, message, args) => {logLevel, message, args}
// - log(message, args) => {logLevel: 0, message, args}
// - log({logLevel, ...}, message, args) => {logLevel, message, args}
// - log({logLevel, message, args}) => {logLevel, message, args}
export function normalizeArguments(opts) {
/**
* "Normalizes" the various argument patterns into an object with known types
* - log(logLevel, message, args) => {logLevel, message, args}
* - log(message, args) => {logLevel: 0, message, args}
* - log({logLevel, ...}, message, args) => {logLevel, message, args}
* - log({logLevel, message, args}) => {logLevel, message, args}
*/
export function normalizeArguments(opts: {
logLevel;
message;
collapsed?: boolean;
args?: IArguments;
opts?;
}): {
logLevel: number;
message: string;
args: any[];
} {
const {logLevel, message} = opts;
opts.logLevel = normalizeLogLevel(logLevel);
// We use `arguments` instead of rest parameters (...args) because IE

@@ -429,8 +410,6 @@ // does not support the syntax. Rest parameters is transpiled to code with

// TODO - remove when/if IE support is dropped
const args = opts.args ? Array.from(opts.args) : [];
/* eslint-disable no-empty */
const args: any[] = opts.args ? Array.from(opts.args) : [];
// args should only contain arguments that appear after `message`
// eslint-disable-next-line no-empty
while (args.length && args.shift() !== message) {}
/* eslint-enable no-empty */
opts.args = args;

@@ -462,3 +441,3 @@ switch (typeof logLevel) {

// original opts + normalized opts + opts arg + fixed up message
return Object.assign(opts, opts.opts);
return Object.assign(opts, {args}, opts.opts);
}

@@ -475,3 +454,3 @@

// Use the asciify module to log an image under node.js
/** Use the asciify module to log an image under node.js */
function logImageInNode({image, message = '', scale = 1}) {

@@ -517,1 +496,10 @@ // Note: Runtime load of the "asciify-image" module, avoids including in browser bundles

}
function getTableHeader(table: Table): string {
for (const key in table) {
for (const title in table[key]) {
return title || 'untitled';
}
}
return 'empty';
}

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