@meteor-it/logger
Advanced tools
Comparing version 2.2.11 to 2.3.2
@@ -1,2 +0,1 @@ | ||
import './colors'; | ||
export declare enum LOGGER_ACTIONS { | ||
@@ -20,4 +19,4 @@ IDENT = 0, | ||
export declare class BasicReceiver { | ||
logger: any; | ||
setLogger(logger: any): void; | ||
logger: typeof Logger; | ||
setLogger(logger: typeof Logger): void; | ||
write(data: any): void; | ||
@@ -27,18 +26,21 @@ } | ||
static nameLength: number; | ||
static repeatCount: any; | ||
static lastProvider: any; | ||
static repeatCount: number; | ||
static lastProvider: string; | ||
static lastMessage: any; | ||
static lastType: any; | ||
static receivers: any[]; | ||
name: any; | ||
identation: any[]; | ||
identationTime: any[]; | ||
times: {}; | ||
static setNameLength(length: any): void; | ||
constructor(name: any); | ||
timeStart(name: any): void; | ||
timeEnd(name: any): void; | ||
ident(name: any): void; | ||
static lastType: string; | ||
static receivers: BasicReceiver[]; | ||
name: string; | ||
identation: string[]; | ||
identationTime: number[]; | ||
times: { | ||
[key: string]: number; | ||
}; | ||
static setNameLength(length: number): void; | ||
constructor(name: string); | ||
timeStart(name: string): void; | ||
timeEnd(name: string): void; | ||
ident(name: string): void; | ||
deent(): void; | ||
deentAll(): void; | ||
isDebugging(): boolean; | ||
log(...params: any[]): void; | ||
@@ -51,9 +53,21 @@ info(...params: any[]): void; | ||
debug(...params: any[]): void; | ||
progress(name: any, progress: boolean | number, info?: string): void; | ||
progress(name: string, progress: boolean | number, info?: string): void; | ||
static noReceiversWarned: boolean; | ||
write(data: any): void; | ||
static _write(what: any): void; | ||
static resetRepeating(provider: any, message: any, type: any): void; | ||
static isRepeating(provider: any, message: any, type: any): boolean; | ||
static addReceiver(receiver: any): void; | ||
private static _write(what); | ||
private static resetRepeating(provider, message, type); | ||
private static isRepeating(provider, message, type); | ||
static addReceiver(receiver: BasicReceiver): void; | ||
static from(name: string | Logger): Logger; | ||
} | ||
export declare type logFunc = (...params: any[]) => undefined; | ||
declare global { | ||
interface Console { | ||
_log: logFunc; | ||
_error: logFunc; | ||
_warn: logFunc; | ||
_err: logFunc; | ||
_warning: logFunc; | ||
} | ||
} | ||
export {}; |
19
index.js
"use strict"; | ||
require("./colors"); | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const DEBUG = process.env.DEBUG || ''; | ||
@@ -98,2 +98,6 @@ var LOGGER_ACTIONS; | ||
} | ||
isDebugging() { | ||
return DEBUG === '*' || DEBUG.split(',').indexOf(this.name) !== -1; | ||
} | ||
// LOG | ||
log(...params) { | ||
@@ -113,2 +117,3 @@ this.write({ | ||
} | ||
// WARNING | ||
warning(...params) { | ||
@@ -142,3 +147,6 @@ this.write({ | ||
} | ||
// DEBUG | ||
debug(...params) { | ||
//if(DEBUG === '-') | ||
// return; | ||
if (DEBUG === '*' || ~DEBUG.split(',').indexOf(this.name)) | ||
@@ -151,2 +159,3 @@ this.write({ | ||
} | ||
// Progress | ||
progress(name, progress, info) { | ||
@@ -229,2 +238,7 @@ if (progress === true) { | ||
} | ||
static from(name) { | ||
if (name instanceof Logger) | ||
return name; | ||
return new Logger(name); | ||
} | ||
} | ||
@@ -234,3 +248,2 @@ Logger.nameLength = 12; | ||
Logger.noReceiversWarned = false; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.default = Logger; | ||
@@ -240,3 +253,3 @@ consoleLogger = new Logger('console'); | ||
if (!console._patchedByLogger) { | ||
for (let method of ['log', 'error', 'warn', 'err', 'warning']) { | ||
for (let method of ['log', 'error', 'warn', 'err', 'warning', 'info']) { | ||
console['_' + method] = console[method]; | ||
@@ -243,0 +256,0 @@ console[method] = (...args) => consoleLogger[method](...args); |
{ | ||
"name": "@meteor-it/logger", | ||
"version": "2.2.11", | ||
"version": "2.3.2", | ||
"description": "Most powerfull logger for node.js", | ||
@@ -13,5 +13,6 @@ "main": "index.js", | ||
"dependencies": { | ||
"@meteor-it/terminal": "latest", | ||
"@meteor-it/utils": "latest" | ||
} | ||
} | ||
"@meteor-it/terminal": "^0.5.6", | ||
"@meteor-it/utils": "^1.3.2" | ||
}, | ||
"gitHead": "7d0b20950a168a6ae5dbbe7dd47629af7ce02ea2" | ||
} |
import { BasicReceiver } from '../'; | ||
export default class BrowserConsoleReceiver extends BasicReceiver { | ||
nameLimit: any; | ||
nameLimit: number; | ||
constructor(nameLimit?: number); | ||
write(data: any): void; | ||
} |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const _1 = require("../"); | ||
@@ -31,12 +32,11 @@ const utils_1 = require("@meteor-it/utils"); | ||
}; | ||
function extractColors(line) { | ||
let r = []; | ||
let nl = line.replace(/{(\/?)([^}]+)}/g, (...d) => { | ||
if (!colors[d[2]]) | ||
return d[0]; | ||
r.push(colors[d[2]][d[1] === '/' ? 1 : 0]); | ||
return '%c'; | ||
}); | ||
return [r, nl]; | ||
} | ||
// function extractColors(line:string) { | ||
// let r:string[]=[]; | ||
// let nl=line.replace(/{(\/?)([^}]+)}/g, (...d:string[]) => { | ||
// if (!colors[d[2]])return d[0]; | ||
// r.push(colors[d[2]][d[1] === '/' ? 1 : 0]); | ||
// return '%c'; | ||
// }); | ||
// return [r,nl]; | ||
// } | ||
class BrowserConsoleReceiver extends _1.BasicReceiver { | ||
@@ -49,3 +49,3 @@ constructor(nameLimit = 8) { | ||
let line = [data.line, ...data.params]; | ||
let name = utils_1.fixLength(data.name, this.nameLimit, true, ' '); | ||
data.name = utils_1.fixLength(data.name, this.nameLimit, true, ' '); | ||
switch (data.type) { | ||
@@ -79,6 +79,6 @@ case _1.LOGGER_ACTIONS.IDENT: | ||
} | ||
//console._log(data); | ||
} | ||
} | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.default = BrowserConsoleReceiver; | ||
//# sourceMappingURL=browser.js.map |
import { BasicReceiver } from '../'; | ||
export default class NodeConsoleReceiver extends BasicReceiver { | ||
nameLimit: any; | ||
nameLimit: number; | ||
constructor(nameLimit?: number); | ||
write(data: any): void; | ||
} |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const util_1 = require("util"); | ||
@@ -32,21 +33,45 @@ const _1 = require("../"); | ||
}; | ||
if (!process.env.NODE_CONSOLE_DONT_CLEAR) | ||
terminal_1.clearScreen(); | ||
function stringifyIdent(nameLimit, count, symbolNeeded = undefined) { | ||
return `${' '.repeat(count)}${symbolNeeded ? symbolNeeded : ' '}`; | ||
} | ||
// function writeDate(date) { | ||
// // writeEscape('36m'); | ||
// // writeStdout((new Date(date)).toLocaleTimeString()); | ||
// // writeEscape('0m'); | ||
// } | ||
function stringifyName(nameLimit, limit, name, escapeCode = '44m') { | ||
return `\u001B[${escapeCode}\u001B[1m${nameLimit === 0 ? '' : name.toString().padStart(nameLimit, ' ')}\u001B[0m`; | ||
} | ||
// function writeRepeats(count, none = false) { | ||
// // if(process.env.NO_COLLAPSE)none=true; | ||
// // if (none) { | ||
// // writeStdout(' '); | ||
// // } else { | ||
// // count += 1; | ||
// // if (count >= 20) writeEscape('31m'); else if (count >= 5) writeEscape('33m'); else if (count >= 2) writeEscape('32m'); else | ||
// // writeEscape('90m'); | ||
// // if (count >= 999) writeStdout('x999+ '); else if (count === 1) writeStdout(' '); else | ||
// // writeStdout('x' + fixLength(count.toString(10), 3, false, ' ') + ' '); | ||
// // writeEscape('0m'); | ||
// // } | ||
// } | ||
function stringifyIdentData(nameLimit, provider, data) { | ||
return ` ${stringifyName(nameLimit, provider.nameLimit, data.name)} \u001B[35m${stringifyIdent(nameLimit, data.identationLength - 1, '>')}\u001B[1m ${data.identName}\u001B[0m\n`; | ||
// writeRepeats(0, true); | ||
// writeDate(data.time); | ||
return ` ${stringifyName(nameLimit, provider.nameLimit, data.name)} \u001B[35m${stringifyIdent(nameLimit, data.identationLength - 1, '>')}\u001B[1m ${data.identName}\u001B[0m`; | ||
} | ||
function stringifyDeentData(nameLimit, provider, data) { | ||
return ` ${stringifyName(nameLimit, provider.nameLimit, data.name)} \u001B[35m${stringifyIdent(nameLimit, data.identationLength, '<')}\u001B[1m ${data.identName}\u001B[22m (Done in ${data.identTime}ms)\u001B[0m\n`; | ||
// writeRepeats(0, true); | ||
// writeDate(data.time); | ||
return ` ${stringifyName(nameLimit, provider.nameLimit, data.name)} \u001B[35m${stringifyIdent(nameLimit, data.identationLength, '<')}\u001B[1m ${data.identName}\u001B[22m (Done in ${data.identTime}ms)\u001B[0m`; | ||
} | ||
function stringifyTimeStartData(nameLimit, provider, data) { | ||
return ` \u001B[35m${stringifyName(nameLimit, provider.nameLimit, data.name, '1m')}\u001B[33m${stringifyIdent(nameLimit, data.identationLength)} T Started ${data.timeName}\n`; | ||
// writeRepeats(0, true); | ||
// writeDate(data.time); | ||
return ` \u001B[35m${stringifyName(nameLimit, provider.nameLimit, data.name, '1m')}\u001B[33m${stringifyIdent(nameLimit, data.identationLength)} T Started ${data.timeName}`; | ||
} | ||
function stringifyTimeEndData(nameLimit, provider, data) { | ||
return ` \u001B[35m${stringifyName(nameLimit, provider.nameLimit, data.name, '1m')}\u001B[34m${stringifyIdent(nameLimit, data.identationLength)} T Finished ${data.timeName}\u001B[1m in ${data.timeTime}ms\u001B[0m\n`; | ||
// writeRepeats(0, true); | ||
// writeDate(data.time); | ||
return ` \u001B[35m${stringifyName(nameLimit, provider.nameLimit, data.name, '1m')}\u001B[34m${stringifyIdent(nameLimit, data.identationLength)} T Finished ${data.timeName}\u001B[1m in ${data.timeTime}ms\u001B[0m`; | ||
} | ||
@@ -61,8 +86,11 @@ function stringifyData(nameLimit, data) { | ||
} | ||
const STRIPPED_DATE = (new Date()).toLocaleTimeString().replace(/./g, ' '); | ||
// const STRIPPED_DATE=(new Date()).toLocaleTimeString().replace(/./g, ' '); | ||
function stringifyCommonData(nameLimit, escapeCode, provider, data) { | ||
// writeRepeats(data.repeats, false); | ||
// writeDate(data.time); | ||
const strings = data.string.split('\n'); | ||
let ret = ` \u001B[40m${stringifyName(nameLimit, provider.nameLimit, data.name, escapeCode)}\u001B[0m${stringifyIdent(nameLimit, data.identationLength)}${strings.shift()}\n`; | ||
let ret = ` \u001B[40m${stringifyName(nameLimit, provider.nameLimit, data.name, escapeCode)}\u001B[0m${stringifyIdent(nameLimit, data.identationLength)}${strings.shift()}`; | ||
for (let string of strings) { | ||
ret += ` \u001B[40m${stringifyName(nameLimit, provider.nameLimit, '|', escapeCode)}\u001B[0m${stringifyIdent(nameLimit, data.identationLength)}${string}\n`; | ||
ret += ` \n\u001B[40m${stringifyName(nameLimit, provider.nameLimit, '|', escapeCode)}\u001B[0m${stringifyIdent(nameLimit, data.identationLength)}${string}`; | ||
//`${stringifyIdent(data.identationLength)}${stringifyName(provider.nameLimit,'|',escapeCode)} ${string}\n`; | ||
} | ||
@@ -72,12 +100,12 @@ return ret; | ||
function writeLogData(nameLimit, provider, data) { | ||
terminal_1.writeStdout(stringifyCommonData(nameLimit, '34m', provider, data)); | ||
terminal_1.writeStdout('\n' + stringifyCommonData(nameLimit, '34m', provider, data)); | ||
} | ||
function writeErrorData(nameLimit, provider, data) { | ||
terminal_1.writeStdout(stringifyCommonData(nameLimit, '31m', provider, data)); | ||
terminal_1.writeStdout('\n' + stringifyCommonData(nameLimit, '31m', provider, data)); | ||
} | ||
function writeWarningData(nameLimit, provider, data) { | ||
terminal_1.writeStdout(stringifyCommonData(nameLimit, '33m', provider, data)); | ||
terminal_1.writeStdout('\n' + stringifyCommonData(nameLimit, '33m', provider, data)); | ||
} | ||
function writeDebugData(nameLimit, provider, data) { | ||
terminal_1.writeStdout(stringifyCommonData(nameLimit, '90m', provider, data)); | ||
terminal_1.writeStdout('\n' + stringifyCommonData(nameLimit, '90m', provider, data)); | ||
} | ||
@@ -109,2 +137,10 @@ const progresses = {}; | ||
terminal_1.writeStdout(`\u001B[34m${progress.name.padStart(nameLimit)} ${(percent + '%').padStart(4, ' ')} ${'|'.repeat(Math.ceil((process.stdout.columns - 1 - 3 - 1 - 1 - nameLimit) / 100 * percent))}`); | ||
// writeEscape('34m'); | ||
// writeStdout((<IProgressItem>progress).name.padStart(18,' ')); | ||
// writeStdout(' '); | ||
// writeDate(progress.time); | ||
// writeStdout(' '); | ||
// writeStdout((percent+'%').padStart(4,' ')); | ||
// writeStdout(' '); | ||
// writeStdout('|'.repeat(Math.ceil(((<any>process.stdout).columns-1-3-1-8-1-18)/100*percent))); | ||
i++; | ||
@@ -125,8 +161,15 @@ } | ||
data.string = stringifyData(nameLimit, data); | ||
// if (data.repeated) { | ||
// if(!process.env.NO_COLLAPSE){ | ||
// save(); | ||
// writeEscape(data.string.split('\n').length + 'A'); | ||
// //data.repeats | ||
// } | ||
// } | ||
switch (data.type) { | ||
case _1.LOGGER_ACTIONS.IDENT: | ||
terminal_1.writeStdout(stringifyIdentData(nameLimit, this, data)); | ||
terminal_1.writeStdout('\n' + stringifyIdentData(nameLimit, this, data)); | ||
break; | ||
case _1.LOGGER_ACTIONS.DEENT: | ||
terminal_1.writeStdout(stringifyDeentData(nameLimit, this, data)); | ||
terminal_1.writeStdout('\n' + stringifyDeentData(nameLimit, this, data)); | ||
break; | ||
@@ -146,6 +189,6 @@ case _1.LOGGER_ACTIONS.LOG: | ||
case _1.LOGGER_ACTIONS.TIME_START: | ||
terminal_1.writeStdout(stringifyTimeStartData(nameLimit, this, data)); | ||
terminal_1.writeStdout('\n' + stringifyTimeStartData(nameLimit, this, data)); | ||
break; | ||
case _1.LOGGER_ACTIONS.TIME_END: | ||
terminal_1.writeStdout(stringifyTimeEndData(nameLimit, this, data)); | ||
terminal_1.writeStdout('\n' + stringifyTimeEndData(nameLimit, this, data)); | ||
break; | ||
@@ -164,2 +207,6 @@ case _1.LOGGER_ACTIONS.PROGRESS_START: | ||
} | ||
// if (data.repeated) { | ||
// if(!process.env.NO_COLLAPSE)restore(); | ||
// } | ||
// TODO: Support for non-tty terminals | ||
if (Object.values(progresses).length !== 0) { | ||
@@ -171,11 +218,17 @@ renderProgress(nameLimit); | ||
} | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.default = NodeConsoleReceiver; | ||
let terminalLogger = new _1.default('terminal'); | ||
process.on('uncaughtException', e => { | ||
terminalLogger.err('UncaughtException:'); | ||
terminalLogger.err(e.stack); | ||
// process.exit(0); | ||
}); | ||
process.on('unhandledRejection', e => { | ||
terminalLogger.err('UnhandledRejection:'); | ||
terminalLogger.err(e.stack); | ||
// process.exit(0); | ||
}); | ||
// process.on('warning', e => { | ||
// terminalLogger.warn(e.stack); | ||
// }); | ||
//# sourceMappingURL=node.js.map |
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
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
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 2 instances in 1 package
60598
1205
1
1
+ Added@meteor-it/terminal@0.5.25(transitive)
+ Added@meteor-it/utils@1.3.33(transitive)
- Removed@meteor-it/terminal@0.6.0(transitive)
- Removed@meteor-it/utils@2.1.0(transitive)
Updated@meteor-it/terminal@^0.5.6
Updated@meteor-it/utils@^1.3.2