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

@meteor-it/logger

Package Overview
Dependencies
Maintainers
1
Versions
51
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@meteor-it/logger - npm Package Compare versions

Comparing version 2.1.3 to 2.2.6

2

colors.d.ts

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

export declare function emojify(string: any): any;
export declare function addStyle(string: any, style: any): string;

@@ -7,3 +6,2 @@ export declare function resetStyles(string: any): any;

addStyle(style: string): string;
emojify(): string;
resetStyles(): string;

@@ -10,0 +8,0 @@ reset: string;

70

colors.js

@@ -1,49 +0,27 @@

(function (dependencies, factory) {
if (typeof module === 'object' && typeof module.exports === 'object') {
var v = factory(require, exports); if (v !== undefined) module.exports = v;
}
else if (typeof define === 'function' && define.amd) {
define(dependencies, factory);
}
})(["require", "exports", "@meteor-it/emoji"], function (require, exports) {
"use strict";
var emoji_1 = require("@meteor-it/emoji");
function emojify(string) {
var ret = string;
var matches = ret.match(/(:[^:]+:)/g) || [];
matches.forEach(function (match) {
ret = ret.replace(match, emoji_1.default[match.substr(1, match.length - 2)] || match);
"use strict";
function addStyle(string, style) {
return `{${style.replace(/[{}]/g, '')}}${string}{/${style.replace(/[{}]/g, '')}}`;
}
exports.addStyle = addStyle;
function resetStyles(string) {
return string.replace(/{[^}]+}[^{]+{\/[^}]+}/g, '');
}
exports.resetStyles = resetStyles;
String.prototype.addStyle = function (style) {
return addStyle(this, style);
};
String.prototype.resetStyles = function () {
return resetStyles(this);
};
function defineDecorator(color) {
try {
Object.defineProperty(String.prototype, color, {
get: function () {
return this.addStyle(color);
}
});
return ret;
}
exports.emojify = emojify;
function addStyle(string, style) {
return "{" + style.replace(/[{}]/g, '') + "}" + string + "{/" + style.replace(/[{}]/g, '') + "}";
}
exports.addStyle = addStyle;
function resetStyles(string) {
return string.replace(/{[^}]+}[^{]+{\/[^}]+}/g, '');
}
exports.resetStyles = resetStyles;
String.prototype.addStyle = function (style) {
return addStyle(this, style);
};
String.prototype.emojify = function () {
return emojify(this);
};
String.prototype.resetStyles = function () {
return resetStyles(this);
};
function defineDecorator(color) {
try {
Object.defineProperty(String.prototype, color, {
get: function () {
return this.addStyle(color);
}
});
}
catch (e) { }
}
["reset", "bold", "dim", "italic", "underline", "inverse", "hidden", "strikethrough", "black", "red", "green", "yellow", "blue", "magenta", "cyan", "white", "gray", "bgBlack", "bgRed", "bgGreen", "bgYellow", "bgBlue", "bgMagenta", "bgCyan", "bgWhite"].forEach(defineDecorator);
});
catch (e) { }
}
["reset", "bold", "dim", "italic", "underline", "inverse", "hidden", "strikethrough", "black", "red", "green", "yellow", "blue", "magenta", "cyan", "white", "gray", "bgBlack", "bgRed", "bgGreen", "bgYellow", "bgBlue", "bgMagenta", "bgCyan", "bgWhite"].forEach(defineDecorator);
//# sourceMappingURL=colors.js.map

@@ -19,16 +19,2 @@ import './colors';

}
declare global {
interface Global {
__LOGGER: any;
}
interface Console {
_log(...pars: any[]): any;
_warn(...pars: any[]): any;
_err(...pars: any[]): any;
err(...pars: any[]): any;
warning(...pars: any[]): any;
_error(...pars: any[]): any;
_warning(...pars: any[]): any;
}
}
export declare class BasicReceiver {

@@ -39,5 +25,2 @@ logger: any;

}
/**
* Powerfull logger. Exists from second generation of "ayzek"
*/
export default class Logger {

@@ -44,0 +27,0 @@ static nameLength: number;

@@ -1,327 +0,263 @@

(function (dependencies, factory) {
if (typeof module === 'object' && typeof module.exports === 'object') {
var v = factory(require, exports); if (v !== undefined) module.exports = v;
"use strict";
require("./colors");
let cluster = null;
if (process.env.__NODE__ !== 'undefined') {
cluster = require('cluster');
}
else {
cluster = {
isMaster: true,
isWorker: false,
on() { },
emit() { }
};
}
const DEBUG = process.env.DEBUG || '';
var LOGGER_ACTIONS;
(function (LOGGER_ACTIONS) {
LOGGER_ACTIONS[LOGGER_ACTIONS["IDENT"] = 0] = "IDENT";
LOGGER_ACTIONS[LOGGER_ACTIONS["DEENT"] = 1] = "DEENT";
LOGGER_ACTIONS[LOGGER_ACTIONS["LOG"] = 2] = "LOG";
LOGGER_ACTIONS[LOGGER_ACTIONS["WARNING"] = 3] = "WARNING";
LOGGER_ACTIONS[LOGGER_ACTIONS["DEPRECATED"] = 4] = "DEPRECATED";
LOGGER_ACTIONS[LOGGER_ACTIONS["ERROR"] = 5] = "ERROR";
LOGGER_ACTIONS[LOGGER_ACTIONS["DEBUG"] = 6] = "DEBUG";
LOGGER_ACTIONS[LOGGER_ACTIONS["TIME_START"] = 7] = "TIME_START";
LOGGER_ACTIONS[LOGGER_ACTIONS["TIME_END"] = 8] = "TIME_END";
LOGGER_ACTIONS[LOGGER_ACTIONS["PROGRESS"] = 9] = "PROGRESS";
LOGGER_ACTIONS[LOGGER_ACTIONS["PROGRESS_START"] = 10] = "PROGRESS_START";
LOGGER_ACTIONS[LOGGER_ACTIONS["PROGRESS_END"] = 11] = "PROGRESS_END";
LOGGER_ACTIONS[LOGGER_ACTIONS["INFO"] = 2] = "INFO";
LOGGER_ACTIONS[LOGGER_ACTIONS["WARN"] = 3] = "WARN";
LOGGER_ACTIONS[LOGGER_ACTIONS["ERR"] = 5] = "ERR";
})(LOGGER_ACTIONS = exports.LOGGER_ACTIONS || (exports.LOGGER_ACTIONS = {}));
const REPEATABLE_ACTIONS = [
LOGGER_ACTIONS.IDENT,
LOGGER_ACTIONS.DEENT,
LOGGER_ACTIONS.TIME_START,
LOGGER_ACTIONS.TIME_END,
LOGGER_ACTIONS.PROGRESS,
LOGGER_ACTIONS.PROGRESS_START,
LOGGER_ACTIONS.PROGRESS_END
];
let consoleLogger;
let loggerLogger;
class BasicReceiver {
setLogger(logger) {
this.logger = logger;
}
else if (typeof define === 'function' && define.amd) {
define(dependencies, factory);
write(data) {
throw new Error('write(): Not implemented!');
}
})(["require", "exports", "./colors"], function (require, exports) {
"use strict";
require("./colors");
var cluster = null;
/*global __NODE__*/
if (__NODE__) {
cluster = require('cluster'); //cluster
}
exports.BasicReceiver = BasicReceiver;
class Logger {
constructor(name) {
this.identation = [];
this.identationTime = [];
this.times = {};
this.name = name.toUpperCase();
}
else {
cluster = {
isMaster: true,
isWorker: false,
on: function () { },
emit: function () { }
};
static setNameLength(length) {
Logger.nameLength = length;
}
var DEBUG = process.env.DEBUG || '';
var LOGGER_ACTIONS;
(function (LOGGER_ACTIONS) {
LOGGER_ACTIONS[LOGGER_ACTIONS["IDENT"] = 0] = "IDENT";
LOGGER_ACTIONS[LOGGER_ACTIONS["DEENT"] = 1] = "DEENT";
LOGGER_ACTIONS[LOGGER_ACTIONS["LOG"] = 2] = "LOG";
LOGGER_ACTIONS[LOGGER_ACTIONS["WARNING"] = 3] = "WARNING";
LOGGER_ACTIONS[LOGGER_ACTIONS["DEPRECATED"] = 4] = "DEPRECATED";
LOGGER_ACTIONS[LOGGER_ACTIONS["ERROR"] = 5] = "ERROR";
LOGGER_ACTIONS[LOGGER_ACTIONS["DEBUG"] = 6] = "DEBUG";
LOGGER_ACTIONS[LOGGER_ACTIONS["TIME_START"] = 7] = "TIME_START";
LOGGER_ACTIONS[LOGGER_ACTIONS["TIME_END"] = 8] = "TIME_END";
LOGGER_ACTIONS[LOGGER_ACTIONS["PROGRESS"] = 9] = "PROGRESS";
LOGGER_ACTIONS[LOGGER_ACTIONS["PROGRESS_START"] = 10] = "PROGRESS_START";
LOGGER_ACTIONS[LOGGER_ACTIONS["PROGRESS_END"] = 11] = "PROGRESS_END";
LOGGER_ACTIONS[LOGGER_ACTIONS["INFO"] = 2] = "INFO";
LOGGER_ACTIONS[LOGGER_ACTIONS["WARN"] = 3] = "WARN";
LOGGER_ACTIONS[LOGGER_ACTIONS["ERR"] = 5] = "ERR";
})(LOGGER_ACTIONS = exports.LOGGER_ACTIONS || (exports.LOGGER_ACTIONS = {}));
var REPEATABLE_ACTIONS = [
LOGGER_ACTIONS.IDENT,
LOGGER_ACTIONS.DEENT,
LOGGER_ACTIONS.TIME_START,
LOGGER_ACTIONS.TIME_END,
LOGGER_ACTIONS.PROGRESS,
LOGGER_ACTIONS.PROGRESS_START,
LOGGER_ACTIONS.PROGRESS_END
];
var consoleLogger;
var loggerLogger;
if (global.__LOGGER)
throw new Error('You have more than 1 logger installed! Make sure you use only latest versions of it, and/or reinstall dependencies');
global.__LOGGER = 1;
var BasicReceiver = (function () {
function BasicReceiver() {
timeStart(name) {
if (this.times[name]) {
loggerLogger.warn('timeStart(%s) called 2 times with same name!', name);
return;
}
BasicReceiver.prototype.setLogger = function (logger) {
this.logger = logger;
};
BasicReceiver.prototype.write = function (data) {
throw new Error('write(): Not implemented!');
};
return BasicReceiver;
}());
exports.BasicReceiver = BasicReceiver;
/**
* Powerfull logger. Exists from second generation of "ayzek"
*/
var Logger = (function () {
function Logger(name) {
this.identation = [];
this.identationTime = [];
this.times = {};
this.name = name.toUpperCase();
this.times[name] = new Date().getTime();
this.write({
type: LOGGER_ACTIONS.TIME_START,
timeName: name
});
}
timeEnd(name) {
if (!this.times[name]) {
loggerLogger.warn('timeEnd(%s) called with unknown name!', name);
return;
}
Logger.setNameLength = function (length) {
Logger.nameLength = length;
};
Logger.prototype.timeStart = function (name) {
if (this.times[name]) {
loggerLogger.warn('timeStart(%s) called 2 times with same name!', name);
return;
}
this.times[name] = new Date().getTime();
this.write({
type: LOGGER_ACTIONS.TIME_END,
timeName: name,
timeTime: new Date().getTime() - this.times[name]
});
delete this.times[name];
}
ident(name) {
this.identation.push(name);
this.identationTime.push(new Date().getTime());
this.write({
type: LOGGER_ACTIONS.IDENT,
identName: name
});
}
deent() {
if (this.identation.length === 0) {
return;
}
this.write({
type: LOGGER_ACTIONS.DEENT,
identName: this.identation.pop(),
identTime: new Date().getTime() - this.identationTime.pop()
});
}
deentAll() {
while (this.identation.length > 0) {
this.deent();
}
}
log(...params) {
this.write({
type: LOGGER_ACTIONS.LOG,
line: params.shift(),
params: params
});
}
info(...params) {
this.write({
type: LOGGER_ACTIONS.LOG,
line: params.shift(),
params: params
});
}
warning(...params) {
this.write({
type: LOGGER_ACTIONS.WARNING,
line: params.shift(),
params: params
});
}
warn(...params) {
this.write({
type: LOGGER_ACTIONS.WARNING,
line: params.shift(),
params: params
});
}
error(...params) {
this.write({
type: LOGGER_ACTIONS.ERROR,
line: params.shift(),
params: params
});
}
err(...params) {
this.write({
type: LOGGER_ACTIONS.ERROR,
line: params.shift(),
params: params
});
}
debug(...params) {
if (DEBUG === '*' || ~DEBUG.split(',').indexOf(this.name))
this.write({
type: LOGGER_ACTIONS.TIME_START,
timeName: name
});
};
Logger.prototype.timeEnd = function (name) {
if (!this.times[name]) {
loggerLogger.warn('timeEnd(%s) called with unknown name!', name);
return;
}
this.write({
type: LOGGER_ACTIONS.TIME_END,
timeName: name,
timeTime: new Date().getTime() - this.times[name]
});
delete this.times[name];
};
Logger.prototype.ident = function (name) {
this.identation.push(name);
this.identationTime.push(new Date().getTime());
this.write({
type: LOGGER_ACTIONS.IDENT,
identName: name
});
};
Logger.prototype.deent = function () {
if (this.identation.length === 0) {
return;
}
this.write({
type: LOGGER_ACTIONS.DEENT,
identName: this.identation.pop(),
identTime: new Date().getTime() - this.identationTime.pop()
});
};
Logger.prototype.deentAll = function () {
while (this.identation.length > 0) {
this.deent();
}
};
// LOG
Logger.prototype.log = function () {
var params = [];
for (var _i = 0; _i < arguments.length; _i++) {
params[_i] = arguments[_i];
}
this.write({
type: LOGGER_ACTIONS.LOG,
type: LOGGER_ACTIONS.DEBUG,
line: params.shift(),
params: params
});
};
Logger.prototype.info = function () {
var params = [];
for (var _i = 0; _i < arguments.length; _i++) {
params[_i] = arguments[_i];
}
}
progress(name, progress, info) {
if (progress === true) {
this.write({
type: LOGGER_ACTIONS.LOG,
line: params.shift(),
params: params
type: LOGGER_ACTIONS.PROGRESS_START,
name
});
};
// WARNING
Logger.prototype.warning = function () {
var params = [];
for (var _i = 0; _i < arguments.length; _i++) {
params[_i] = arguments[_i];
}
}
else if (progress === false) {
this.write({
type: LOGGER_ACTIONS.WARNING,
line: params.shift(),
params: params
type: LOGGER_ACTIONS.PROGRESS_END,
name
});
};
Logger.prototype.warn = function () {
var params = [];
for (var _i = 0; _i < arguments.length; _i++) {
params[_i] = arguments[_i];
}
}
else {
this.write({
type: LOGGER_ACTIONS.WARNING,
line: params.shift(),
params: params
type: LOGGER_ACTIONS.PROGRESS,
name,
progress,
info
});
};
Logger.prototype.error = function () {
var params = [];
for (var _i = 0; _i < arguments.length; _i++) {
params[_i] = arguments[_i];
}
this.write({
type: LOGGER_ACTIONS.ERROR,
line: params.shift(),
params: params
}
}
write(data) {
if (!data.time)
data.time = new Date().getTime();
if (!data.name)
data.name = this.name;
if (!data.identationLength)
data.identationLength = this.identation.length;
Logger._write(data);
}
static _write(what) {
if (cluster.isWorker) {
process.send({
loggerAction: what
});
};
Logger.prototype.err = function () {
var params = [];
for (var _i = 0; _i < arguments.length; _i++) {
params[_i] = arguments[_i];
}
this.write({
type: LOGGER_ACTIONS.ERROR,
line: params.shift(),
params: params
});
};
// DEBUG
Logger.prototype.debug = function () {
var params = [];
for (var _i = 0; _i < arguments.length; _i++) {
params[_i] = arguments[_i];
}
//if(DEBUG === '-')
// return;
if (DEBUG === '*' || ~DEBUG.split(',').indexOf(this.name))
this.write({
type: LOGGER_ACTIONS.DEBUG,
line: params.shift(),
params: params
});
};
// Progress
Logger.prototype.progress = function (name, progress, info) {
if (progress === true) {
this.write({
type: LOGGER_ACTIONS.PROGRESS_START,
name: name
});
}
else if (progress === false) {
this.write({
type: LOGGER_ACTIONS.PROGRESS_END,
name: name
});
}
else {
this.write({
type: LOGGER_ACTIONS.PROGRESS,
name: name,
progress: progress,
info: info
});
}
};
Logger.prototype.write = function (data) {
if (!data.time)
data.time = new Date().getTime();
if (!data.name)
data.name = this.name;
if (!data.identationLength)
data.identationLength = this.identation.length;
Logger._write(data);
};
Logger._write = function (what) {
if (cluster.isWorker) {
process.send({
loggerAction: what
});
}
else {
if (Logger.receivers.length === 0) {
if (!Logger.noReceiversWarned) {
console._log('No receivers are defined for logger! See docs for info about this!');
Logger.noReceiversWarned = true;
}
switch (what.type) {
case LOGGER_ACTIONS.DEBUG:
case LOGGER_ACTIONS.LOG:
console._log.apply(console, [what.line].concat(what.params));
break;
case LOGGER_ACTIONS.ERROR:
console._error.apply(console, [what.line].concat(what.params));
break;
case LOGGER_ACTIONS.WARNING:
console._warn.apply(console, [what.line].concat(what.params));
break;
default:
console._log(what);
}
return;
}
else {
if (Logger.receivers.length === 0) {
if (!Logger.noReceiversWarned) {
console._log('No receivers are defined for logger! See docs for info about this!');
Logger.noReceiversWarned = true;
}
if (Logger.isRepeating(what.name, what.line, what.type))
Logger.repeatCount++;
else
Logger.resetRepeating(what.name, what.line, what.type);
if (REPEATABLE_ACTIONS.indexOf(what.type) === -1)
what.repeats = Logger.repeatCount;
what.repeated = what.repeats && what.repeats > 0;
Logger.receivers.forEach(function (receiver) { return receiver.write(what); });
}
};
Logger.resetRepeating = function (provider, message, type) {
Logger.lastProvider = provider;
Logger.lastMessage = message;
Logger.lastType = type;
Logger.repeatCount = 0;
};
Logger.isRepeating = function (provider, message, type) {
return Logger.lastProvider === provider && Logger.lastMessage === message && Logger.lastType === type;
};
Logger.addReceiver = function (receiver) {
if (Logger.receivers.length === 4)
loggerLogger.warn('Possible memory leak detected: 4 or more receivers are added.');
receiver.setLogger(Logger);
Logger.receivers.push(receiver);
};
return Logger;
}());
Logger.nameLength = 12;
Logger.receivers = [];
Logger.noReceiversWarned = false;
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = Logger;
if (cluster.isMaster) {
cluster.on('message', function (worker, msg) {
if (!msg.loggerAction)
switch (what.type) {
case LOGGER_ACTIONS.DEBUG:
case LOGGER_ACTIONS.LOG:
console._log(what.line, ...what.params);
break;
case LOGGER_ACTIONS.ERROR:
console._error(what.line, ...what.params);
break;
case LOGGER_ACTIONS.WARNING:
console._warn(what.line, ...what.params);
break;
default:
console._log(what);
}
return;
Logger._write(msg.loggerAction);
});
}
consoleLogger = new Logger('console');
loggerLogger = new Logger('logger'); // Like in java :D
var _loop_1 = function (method) {
console['_' + method] = console[method];
console[method] = function () {
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
return consoleLogger[method].apply(consoleLogger, args);
};
};
for (var _i = 0, _a = ['log', 'error', 'warn', 'err', 'warning']; _i < _a.length; _i++) {
var method = _a[_i];
_loop_1(method);
if (Logger.isRepeating(what.name, what.line, what.type))
Logger.repeatCount++;
else
Logger.resetRepeating(what.name, what.line, what.type);
if (REPEATABLE_ACTIONS.indexOf(what.type) === -1)
what.repeats = Logger.repeatCount;
what.repeated = what.repeats && what.repeats > 0;
Logger.receivers.forEach(receiver => receiver.write(what));
}
}
});
static resetRepeating(provider, message, type) {
Logger.lastProvider = provider;
Logger.lastMessage = message;
Logger.lastType = type;
Logger.repeatCount = 0;
}
static isRepeating(provider, message, type) {
return Logger.lastProvider === provider && Logger.lastMessage === message && Logger.lastType === type;
}
static addReceiver(receiver) {
if (Logger.receivers.length === 4)
loggerLogger.warn('Possible memory leak detected: 4 or more receivers are added.');
receiver.setLogger(Logger);
Logger.receivers.push(receiver);
}
}
Logger.nameLength = 12;
Logger.receivers = [];
Logger.noReceiversWarned = false;
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = Logger;
if (cluster.isMaster) {
cluster.on('message', (worker, msg) => {
if (!msg.loggerAction)
return;
Logger._write(msg.loggerAction);
});
}
consoleLogger = new Logger('console');
loggerLogger = new Logger('logger');
for (let method of ['log', 'error', 'warn', 'err', 'warning']) {
console['_' + method] = console[method];
console[method] = (...args) => consoleLogger[method](...args);
}
//# sourceMappingURL=index.js.map

@@ -1,19 +0,1 @@

{
"name": "@meteor-it/logger",
"version": "2.1.3",
"description": "Most powerfull logger for node.js",
"main": "index.js",
"keywords": [
"meteor-it",
"logger"
],
"author": "Yaroslaw Bolyukin <iam@f6cf.pw> (http://f6cf.pw/)",
"license": "MIT",
"dependencies": {
"@meteor-it/emoji": "latest",
"@meteor-it/platform": "latest",
"@meteor-it/reflection": "latest",
"@meteor-it/terminal": "latest",
"@meteor-it/utils": "latest"
}
}
{"name":"@meteor-it/logger","version":"2.2.6","description":"Most powerfull logger for node.js","main":"index.js","keywords":["meteor-it","logger"],"author":"Yaroslaw Bolyukin <iam@f6cf.pw> (http://f6cf.pw/)","license":"MIT","dependencies":{"@meteor-it/platform":"latest","@meteor-it/reflection":"latest","@meteor-it/terminal":"latest","@meteor-it/utils":"latest"}}

@@ -1,108 +0,81 @@

var __extends = (this && this.__extends) || function (d, b) {
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
"use strict";
const _1 = require("../");
const utils_1 = require("@meteor-it/utils");
const colors = {
reset: ['', ''],
bold: ['text-decoration:bold', 'text-decoration:none'],
dim: ['text-decoration:bold', 'text-decoration:none'],
italic: ['text-decoration:italic', 'text-decoration:none'],
underline: ['text-decoration:underline', 'text-decoration:none'],
inverse: ['color:black', 'text-decoration:none'],
hidden: ['visible:none', 'text-decoration:none'],
strikethrough: ['text-decoration:line-through', 'text-decoration:none'],
black: ['color:black', 'color:black'],
red: ['color:red', 'color:black'],
green: ['color:green', 'color:black'],
yellow: ['color:yellow', 'color:black'],
blue: ['color:blue', 'color:black'],
magenta: ['color:magenta', 'color:black'],
cyan: ['color:cyan', 'color:black'],
white: ['color:white', 'color:black'],
gray: ['color:gray', 'color:black'],
bgBlack: ['background:black', 'background:white'],
bgRed: ['background:red', 'background:white'],
bgGreen: ['background:green', 'background:white'],
bgYellow: ['background:yellow', 'background:white'],
bgBlue: ['background:blue', 'background:white'],
bgMagenta: ['background:magenta', 'background:white'],
bgCyan: ['background:cyan', 'background:white'],
bgWhite: ['background:white', 'background:white']
};
(function (dependencies, factory) {
if (typeof module === 'object' && typeof module.exports === 'object') {
var v = factory(require, exports); if (v !== undefined) module.exports = v;
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];
}
class BrowserConsoleReceiver extends _1.BasicReceiver {
constructor(nameLimit = 8) {
super();
this.nameLimit = nameLimit;
}
else if (typeof define === 'function' && define.amd) {
define(dependencies, factory);
write(data) {
let line = [data.line, ...data.params];
let name = utils_1.fixLength(data.name, this.nameLimit, true, ' ');
switch (data.type) {
case _1.LOGGER_ACTIONS.IDENT:
console.group('%cIDENT', data.name);
break;
case _1.LOGGER_ACTIONS.DEENT:
console.groupEnd();
break;
case _1.LOGGER_ACTIONS.LOG:
console._log(...line);
break;
case _1.LOGGER_ACTIONS.ERROR:
console._error(...line);
break;
case _1.LOGGER_ACTIONS.WARNING:
console._error(...line);
break;
case _1.LOGGER_ACTIONS.DEBUG:
console._log(...line);
break;
case _1.LOGGER_ACTIONS.TIME_START:
console._log('TIME_START');
break;
case _1.LOGGER_ACTIONS.TIME_END:
console._log('TIME_END');
break;
default:
console._error('ERROR', data.type, _1.LOGGER_ACTIONS);
}
}
})(["require", "exports", "../", "@meteor-it/utils"], function (require, exports) {
"use strict";
var _1 = require("../");
var utils_1 = require("@meteor-it/utils");
var colors = {
reset: ['', ''],
bold: ['text-decoration:bold', 'text-decoration:none'],
dim: ['text-decoration:bold', 'text-decoration:none'],
italic: ['text-decoration:italic', 'text-decoration:none'],
underline: ['text-decoration:underline', 'text-decoration:none'],
inverse: ['color:black', 'text-decoration:none'],
hidden: ['visible:none', 'text-decoration:none'],
strikethrough: ['text-decoration:line-through', 'text-decoration:none'],
black: ['color:black', 'color:black'],
red: ['color:red', 'color:black'],
green: ['color:green', 'color:black'],
yellow: ['color:yellow', 'color:black'],
blue: ['color:blue', 'color:black'],
magenta: ['color:magenta', 'color:black'],
cyan: ['color:cyan', 'color:black'],
white: ['color:white', 'color:black'],
gray: ['color:gray', 'color:black'],
bgBlack: ['background:black', 'background:white'],
bgRed: ['background:red', 'background:white'],
bgGreen: ['background:green', 'background:white'],
bgYellow: ['background:yellow', 'background:white'],
bgBlue: ['background:blue', 'background:white'],
bgMagenta: ['background:magenta', 'background:white'],
bgCyan: ['background:cyan', 'background:white'],
bgWhite: ['background:white', 'background:white']
};
///console.clear();
function extractColors(line) {
var r = [];
var nl = line.replace(/{(\/?)([^}]+)}/g, function () {
var d = [];
for (var _i = 0; _i < arguments.length; _i++) {
d[_i] = arguments[_i];
}
if (!colors[d[2]])
return d[0];
r.push(colors[d[2]][d[1] === '/' ? 1 : 0]);
return '%c';
});
return [r, nl];
}
var BrowserConsoleReceiver = (function (_super) {
__extends(BrowserConsoleReceiver, _super);
function BrowserConsoleReceiver(nameLimit) {
if (nameLimit === void 0) { nameLimit = 8; }
var _this = _super.call(this) || this;
_this.nameLimit = nameLimit;
return _this;
}
BrowserConsoleReceiver.prototype.write = function (data) {
var line = [data.line].concat(data.params);
//line=colors[1];
//colors=colors[0];
var name = utils_1.fixLength(data.name, this.nameLimit, true, ' ');
//line='%c'+name+'%c '+line;
switch (data.type) {
case _1.LOGGER_ACTIONS.IDENT:
console.group('%cIDENT', data.name);
break;
case _1.LOGGER_ACTIONS.DEENT:
console.groupEnd();
break;
case _1.LOGGER_ACTIONS.LOG:
console._log.apply(console, line);
break;
case _1.LOGGER_ACTIONS.ERROR:
console._error.apply(console, line);
break;
case _1.LOGGER_ACTIONS.WARNING:
console._error.apply(console, line);
break;
case _1.LOGGER_ACTIONS.DEBUG:
console._log.apply(console, line);
break;
case _1.LOGGER_ACTIONS.TIME_START:
console._log('TIME_START');
break;
case _1.LOGGER_ACTIONS.TIME_END:
console._log('TIME_END');
break;
default:
console._error('ERROR', data.type, _1.LOGGER_ACTIONS);
}
//console._log(data);
};
return BrowserConsoleReceiver;
}(_1.BasicReceiver));
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = BrowserConsoleReceiver;
});
}
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = BrowserConsoleReceiver;
//# sourceMappingURL=browser.js.map

@@ -1,246 +0,173 @@

var __extends = (this && this.__extends) || function (d, b) {
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
"use strict";
const util_1 = require("util");
const _1 = require("../");
const terminal_1 = require("@meteor-it/terminal");
const ansiColors = {
reset: [0, 0],
bold: [1, 22],
dim: [2, 22],
italic: [3, 23],
underline: [4, 24],
inverse: [7, 27],
hidden: [8, 28],
strikethrough: [9, 29],
black: [30, 39],
red: [31, 39],
green: [32, 39],
yellow: [33, 39],
blue: [34, 39],
magenta: [35, 39],
cyan: [36, 39],
white: [37, 39],
gray: [90, 39],
bgBlack: [40, 49],
bgRed: [41, 49],
bgGreen: [42, 49],
bgYellow: [43, 49],
bgBlue: [44, 49],
bgMagenta: [45, 49],
bgCyan: [46, 49],
bgWhite: [47, 49]
};
(function (dependencies, factory) {
if (typeof module === 'object' && typeof module.exports === 'object') {
var v = factory(require, exports); if (v !== undefined) module.exports = v;
if (!process.env.NODE_CONSOLE_DONT_CLEAR)
terminal_1.clearScreen();
function stringifyIdent(nameLimit, count, symbolNeeded = undefined) {
return `${' '.repeat(count)}${symbolNeeded ? symbolNeeded : ' '}`;
}
function stringifyName(nameLimit, limit, name, escapeCode = '44m') {
return `\u001B[${escapeCode}\u001B[1m${nameLimit === 0 ? '' : name.toString().padStart(nameLimit, ' ')}\u001B[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`;
}
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`;
}
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`;
}
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`;
}
function stringifyData(nameLimit, data) {
let uncolored = util_1.format(data.line, ...data.params || []);
return uncolored.replace(/{(\/?)([^}]+)}/g, (...d) => {
if (!ansiColors[d[2]])
return d[0];
return '\u001B[' + ansiColors[d[2]][d[1] === '/' ? 1 : 0] + 'm';
});
}
const STRIPPED_DATE = (new Date()).toLocaleTimeString().replace(/./g, ' ');
function stringifyCommonData(nameLimit, escapeCode, provider, data) {
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`;
for (let string of strings) {
ret += ` \u001B[40m${stringifyName(nameLimit, provider.nameLimit, '|', escapeCode)}\u001B[0m${stringifyIdent(nameLimit, data.identationLength)}${string}\n`;
}
else if (typeof define === 'function' && define.amd) {
define(dependencies, factory);
}
})(["require", "exports", "util", "../", "@meteor-it/terminal", "@meteor-it/emoji"], function (require, exports) {
"use strict";
var util_1 = require("util");
var _1 = require("../");
var terminal_1 = require("@meteor-it/terminal");
var emoji_1 = require("@meteor-it/emoji");
var ansiColors = {
reset: [0, 0],
bold: [1, 22],
dim: [2, 22],
italic: [3, 23],
underline: [4, 24],
inverse: [7, 27],
hidden: [8, 28],
strikethrough: [9, 29],
black: [30, 39],
red: [31, 39],
green: [32, 39],
yellow: [33, 39],
blue: [34, 39],
magenta: [35, 39],
cyan: [36, 39],
white: [37, 39],
gray: [90, 39],
bgBlack: [40, 49],
bgRed: [41, 49],
bgGreen: [42, 49],
bgYellow: [43, 49],
bgBlue: [44, 49],
bgMagenta: [45, 49],
bgCyan: [46, 49],
bgWhite: [47, 49]
return ret;
}
function writeLogData(nameLimit, provider, data) {
terminal_1.writeStdout(stringifyCommonData(nameLimit, '34m', provider, data));
}
function writeErrorData(nameLimit, provider, data) {
terminal_1.writeStdout(stringifyCommonData(nameLimit, '31m', provider, data));
}
function writeWarningData(nameLimit, provider, data) {
terminal_1.writeStdout(stringifyCommonData(nameLimit, '33m', provider, data));
}
function writeDebugData(nameLimit, provider, data) {
terminal_1.writeStdout(stringifyCommonData(nameLimit, '90m', provider, data));
}
const progresses = {};
function progressStart(nameLimit, provider, data) {
progresses[data.name] = {
name: data.name,
progress: 0,
time: data.time
};
// if(!process.env.NODE_CONSOLE_DONT_CLEAR)
// clearScreen();
function stringifyIdent(count, symbolNeeded) {
if (symbolNeeded === void 0) { symbolNeeded = undefined; }
return ' '.repeat(symbolNeeded ? count - 1 : count) + " " + (symbolNeeded ? symbolNeeded : '');
}
function progressEnd(nameLimit, provider, data) {
delete progresses[data.name];
}
function progress(nameLimit, provider, data) {
if (!progresses[data.name])
return;
progresses[data.name].time = data.time;
progresses[data.name].progress = data.progress;
}
function renderProgress(nameLimit) {
terminal_1.save();
let i = 0;
for (let progress of Object.values(progresses)) {
terminal_1.moveCursor(i);
terminal_1.clearLine();
let percent = Math.ceil(progress.progress);
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))}`);
i++;
}
// function writeDate(date) {
// // writeEscape('36m');
// // writeStdout((new Date(date)).toLocaleTimeString());
// // writeEscape('0m');
// }
function stringifyName(limit, name, escapeCode) {
if (escapeCode === void 0) { escapeCode = '44m'; }
return "\u001B[" + escapeCode + "\u001B[1m" + name.toString().padStart(16, ' ') + "\u001B[0m";
terminal_1.restore();
}
class NodeConsoleReceiver extends _1.BasicReceiver {
constructor(nameLimit = 18) {
super();
this.nameLimit = nameLimit;
}
// 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(provider, data) {
// writeRepeats(0, true);
// writeDate(data.time);
return " " + stringifyName(provider.nameLimit, data.name) + " \u001B[35m" + stringifyIdent(data.identationLength, '>') + "\u001B[1m " + data.identName + "\u001B[0m\n";
}
function stringifyDeentData(provider, data) {
// writeRepeats(0, true);
// writeDate(data.time);
return " " + stringifyName(provider.nameLimit, data.name) + " \u001B[35m" + stringifyIdent(data.identationLength + 1, '<') + "\u001B[1m " + data.identName + "\u001B[22m (Done in " + data.identTime + "ms)\u001B[0m\n";
}
function stringifyTimeStartData(provider, data) {
// writeRepeats(0, true);
// writeDate(data.time);
return " \u001B[35m" + stringifyName(provider.nameLimit, data.name, '1m') + "\u001B[33m" + stringifyIdent(data.identationLength) + emoji_1.default['clock face one oclock'] + " Started " + data.timeName + "\n";
}
function stringifyTimeEndData(provider, data) {
// writeRepeats(0, true);
// writeDate(data.time);
return " \u001B[35m" + stringifyName(provider.nameLimit, data.name, '1m') + "\u001B[34m" + stringifyIdent(data.identationLength) + emoji_1.default['clock face six oclock'] + " Finished " + data.timeName + "\u001B[1m in " + data.timeTime + "ms\u001B[0m\n";
}
function stringifyData(data) {
var uncolored = util_1.format.apply(void 0, [data.line].concat(data.params || [])).emojify();
return uncolored.replace(/{(\/?)([^}]+)}/g, function () {
var d = [];
for (var _i = 0; _i < arguments.length; _i++) {
d[_i] = arguments[_i];
}
if (!ansiColors[d[2]])
return d[0];
return '\u001B[' + ansiColors[d[2]][d[1] === '/' ? 1 : 0] + 'm';
});
}
var STRIPPED_DATE = (new Date()).toLocaleTimeString().replace(/./g, ' ');
function stringifyCommonData(escapeCode, provider, data) {
// writeRepeats(data.repeats, false);
// writeDate(data.time);
var strings = data.string.split('\n');
var ret = " \u001B[40m" + stringifyName(provider.nameLimit, data.name, escapeCode) + "\u001B[0m" + stringifyIdent(data.identationLength) + strings.shift() + "\n";
for (var _i = 0, strings_1 = strings; _i < strings_1.length; _i++) {
var string = strings_1[_i];
ret += "" + stringifyIdent(data.identationLength) + stringifyName(provider.nameLimit, '|', escapeCode) + " " + string + "\n";
write(data) {
let { nameLimit } = this;
if (Object.values(progresses).length !== 0) {
terminal_1.startBuffering();
}
return ret;
}
function writeLogData(provider, data) {
terminal_1.writeStdout(stringifyCommonData('34m', provider, data));
}
function writeErrorData(provider, data) {
terminal_1.writeStdout(stringifyCommonData('31m', provider, data));
}
function writeWarningData(provider, data) {
terminal_1.writeStdout(stringifyCommonData('33m', provider, data));
}
function writeDebugData(provider, data) {
terminal_1.writeStdout(stringifyCommonData('90m', provider, data));
}
var progresses = {};
function progressStart(provider, data) {
progresses[data.name] = {
name: data.name,
progress: 0,
time: data.time
};
}
function progressEnd(provider, data) {
delete progresses[data.name];
}
function progress(provider, data) {
if (!progresses[data.name])
return;
progresses[data.name].time = data.time;
progresses[data.name].progress = data.progress;
}
function renderProgress() {
terminal_1.save();
var i = 0;
for (var _i = 0, _a = Object.values(progresses); _i < _a.length; _i++) {
var progress_1 = _a[_i];
terminal_1.moveCursor(i);
terminal_1.clearLine();
var percent = Math.ceil(progress_1.progress);
// TODO: Unhardcode "18"
terminal_1.writeStdout("\u001B[34m" + progress_1.name.padStart(18) + " " + (percent + '%').padStart(4, ' ') + " " + '|'.repeat(Math.ceil((process.stdout.columns - 1 - 3 - 1 - 1 - 18) / 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++;
data.string = stringifyData(nameLimit, data);
switch (data.type) {
case _1.LOGGER_ACTIONS.IDENT:
terminal_1.writeStdout(stringifyIdentData(nameLimit, this, data));
break;
case _1.LOGGER_ACTIONS.DEENT:
terminal_1.writeStdout(stringifyDeentData(nameLimit, this, data));
break;
case _1.LOGGER_ACTIONS.LOG:
writeLogData(nameLimit, this, data);
break;
case _1.LOGGER_ACTIONS.ERROR:
writeErrorData(nameLimit, this, data);
break;
case _1.LOGGER_ACTIONS.WARNING:
writeWarningData(nameLimit, this, data);
break;
case _1.LOGGER_ACTIONS.DEBUG:
writeDebugData(nameLimit, this, data);
break;
case _1.LOGGER_ACTIONS.TIME_START:
terminal_1.writeStdout(stringifyTimeStartData(nameLimit, this, data));
break;
case _1.LOGGER_ACTIONS.TIME_END:
terminal_1.writeStdout(stringifyTimeEndData(nameLimit, this, data));
break;
case _1.LOGGER_ACTIONS.PROGRESS_START:
progressStart(nameLimit, this, data);
break;
case _1.LOGGER_ACTIONS.PROGRESS_END:
progressEnd(nameLimit, this, data);
break;
case _1.LOGGER_ACTIONS.PROGRESS:
progress(nameLimit, this, data);
break;
default:
console._log(data);
}
terminal_1.restore();
if (Object.values(progresses).length !== 0) {
renderProgress(nameLimit);
terminal_1.flushBuffer();
}
}
var NodeConsoleReceiver = (function (_super) {
__extends(NodeConsoleReceiver, _super);
function NodeConsoleReceiver(nameLimit) {
if (nameLimit === void 0) { nameLimit = 18; }
var _this = _super.call(this) || this;
_this.nameLimit = nameLimit;
return _this;
}
NodeConsoleReceiver.prototype.write = function (data) {
terminal_1.startBuffering();
data.string = stringifyData(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(this, data));
break;
case _1.LOGGER_ACTIONS.DEENT:
terminal_1.writeStdout(stringifyDeentData(this, data));
break;
case _1.LOGGER_ACTIONS.LOG:
writeLogData(this, data);
break;
case _1.LOGGER_ACTIONS.ERROR:
writeErrorData(this, data);
break;
case _1.LOGGER_ACTIONS.WARNING:
writeWarningData(this, data);
break;
case _1.LOGGER_ACTIONS.DEBUG:
writeDebugData(this, data);
break;
case _1.LOGGER_ACTIONS.TIME_START:
terminal_1.writeStdout(stringifyTimeStartData(this, data));
break;
case _1.LOGGER_ACTIONS.TIME_END:
terminal_1.writeStdout(stringifyTimeEndData(this, data));
break;
case _1.LOGGER_ACTIONS.PROGRESS_START:
progressStart(this, data);
break;
case _1.LOGGER_ACTIONS.PROGRESS_END:
progressEnd(this, data);
break;
case _1.LOGGER_ACTIONS.PROGRESS:
progress(this, data);
break;
default:
console._log(data);
}
// if (data.repeated) {
// if(!process.env.NO_COLLAPSE)restore();
// }
// TODO: Support for non-tty terminals
renderProgress();
terminal_1.flushBuffer();
};
return NodeConsoleReceiver;
}(_1.BasicReceiver));
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = NodeConsoleReceiver;
var terminalLogger = new _1.default('terminal');
process.on('uncaughtException', function (e) {
terminalLogger.err(e.stack);
});
process.on('unhandledRejection', function (e) {
terminalLogger.err(e.stack);
});
}
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = NodeConsoleReceiver;
let terminalLogger = new _1.default('terminal');
process.on('uncaughtException', e => {
terminalLogger.err(e.stack);
});
// process.on('warning', e => {
// terminalLogger.warn(e.stack);
// });
process.on('unhandledRejection', e => {
terminalLogger.err(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

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