@matrixai/logger
Advanced tools
Comparing version 2.2.1 to 2.2.2
@@ -21,2 +21,4 @@ "use strict"; | ||
exports.trace = trace; | ||
const hasCaptureStackTrace = 'captureStackTrace' in Error; | ||
const hasStackTraceLimit = 'stackTraceLimit' in Error; | ||
function format(strings, ...values) { | ||
@@ -49,27 +51,19 @@ return (record) => { | ||
else if (value === trace) { | ||
if ('stackTraceLimit' in Error && 'captureStackTrace' in Error) { | ||
let stack; | ||
if (hasCaptureStackTrace && hasStackTraceLimit) { | ||
Error.stackTraceLimit++; | ||
const newError = {}; | ||
// @ts-ignore: protected property | ||
Error.captureStackTrace(newError, Logger_1.default.prototype.log); | ||
const error = {}; | ||
// @ts-ignore: protected `Logger.prototype.log` | ||
Error.captureStackTrace(error, Logger_1.default.prototype.log); | ||
Error.stackTraceLimit--; | ||
const errorStack = newError.stack; | ||
if (errorStack != null) { | ||
const formattedStack = errorStack.split('\n').splice(2).join('\n'); | ||
result += '\n' + formattedStack; | ||
} | ||
else { | ||
result += ''; | ||
} | ||
stack = error.stack; | ||
// Remove the stack title and the first stack line for `Logger.prototype.log` | ||
stack = stack.slice(stack.indexOf('\n', stack.indexOf('\n') + 1) + 1); | ||
} | ||
else { | ||
const errorStack = new Error().stack; | ||
if (errorStack != null) { | ||
const formattedStack = errorStack.split('\n').splice(1).join('\n'); | ||
result += '\n' + formattedStack; | ||
} | ||
else { | ||
result += ''; | ||
} | ||
stack = new Error().stack ?? ''; | ||
stack = stack.slice(stack.indexOf('\n') + 1); | ||
} | ||
if (stack !== '') | ||
result += '\n' + stack; | ||
} | ||
@@ -76,0 +70,0 @@ else { |
@@ -9,2 +9,3 @@ "use strict"; | ||
emit(output) { | ||
// eslint-disable-next-line no-console | ||
console.error(output); | ||
@@ -11,0 +12,0 @@ } |
{ | ||
"name": "@matrixai/logger", | ||
"version": "2.2.1", | ||
"version": "2.2.2", | ||
"author": "Scott Morris", | ||
@@ -15,3 +15,4 @@ "description": "Python-like JavaScript Logger", | ||
"prepare": "tsc -p ./tsconfig.build.json", | ||
"build": "rm -r ./dist || true; tsc -p ./tsconfig.build.json", | ||
"build": "rimraf ./dist && tsc -p ./tsconfig.build.json", | ||
"postversion": "npm install --package-lock-only --ignore-scripts --silent", | ||
"ts-node": "ts-node -r tsconfig-paths/register", | ||
@@ -21,3 +22,3 @@ "test": "jest", | ||
"lintfix": "eslint '{src,tests}/**/*.{js,ts}' --fix", | ||
"docs": "rm -r ./docs || true; typedoc --gitRevision master --tsconfig ./tsconfig.build.json --out ./docs src" | ||
"docs": "rimraf ./docs && typedoc --gitRevision master --tsconfig ./tsconfig.build.json --out ./docs src" | ||
}, | ||
@@ -34,3 +35,5 @@ "devDependencies": { | ||
"jest": "^27.2.5", | ||
"jest-junit": "^13.2.0", | ||
"prettier": "^2.6.2", | ||
"rimraf": "^3.0.2", | ||
"ts-jest": "^27.0.5", | ||
@@ -37,0 +40,0 @@ "ts-node": "^10.4.0", |
# js-logger | ||
[![pipeline status](https://gitlab.com/MatrixAI/open-source/js-logger/badges/master/pipeline.svg)](https://gitlab.com/MatrixAI/open-source/js-logger/commits/master) | ||
staging:[![pipeline status](https://gitlab.com/MatrixAI/open-source/js-logger/badges/staging/pipeline.svg)](https://gitlab.com/MatrixAI/open-source/js-logger/commits/staging) | ||
master:[![pipeline status](https://gitlab.com/MatrixAI/open-source/js-logger/badges/master/pipeline.svg)](https://gitlab.com/MatrixAI/open-source/js-logger/commits/master) | ||
@@ -5,0 +6,0 @@ This library provies a JavaScript logger that is similar to the Python logger. |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
36448
51
17
411
1