@lskjs/log
Advanced tools
Comparing version 2.52.0 to 2.56.0
@@ -16,6 +16,6 @@ #!/usr/bin/env node | ||
if (process.env.LSK_LOG_READLINE) { | ||
if (process.env.LSK_LOG_READLINE !== '0') { | ||
_readline["default"].createInterface({ | ||
input: process.stdin, | ||
output: process.stdout | ||
input: process.stdin // output: process.stdout, | ||
}).on('line', function (raw) { | ||
@@ -22,0 +22,0 @@ (0, _prettyRawLog.prettyRawLog)(_log.log, raw); |
@@ -20,5 +20,4 @@ import { ILogger, ILoggerProps, LoggerLevelType } from './types'; | ||
log(...args: any[]): void; | ||
__logger(...args: any[]): void; | ||
__log(level: LoggerLevelType, ...args: any[]): void; | ||
} | ||
export default Logger; |
@@ -10,6 +10,6 @@ "use strict"; | ||
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray")); | ||
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty")); | ||
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray")); | ||
var _construct2 = _interopRequireDefault(require("@babel/runtime/helpers/construct")); | ||
@@ -27,4 +27,2 @@ | ||
var _createMsg = require("./utils/createMsg"); | ||
var _env2 = require("./utils/env"); | ||
@@ -34,8 +32,6 @@ | ||
var _isUrlLog = require("./utils/isUrlLog"); | ||
var _lsklog = require("./utils/formats/lsklog"); | ||
var _omitNull = require("./utils/omitNull"); | ||
var _toString = require("./utils/toString"); | ||
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; } | ||
@@ -51,7 +47,4 @@ | ||
return (0, _env2.env)('LOG_FORMAT', _env.isDev || _env.isClient ? 'pretty' : 'lsk'); | ||
}; | ||
}; // const LOG_DATA = () => !!env('LOG_DATA', 0); | ||
var LOG_DATA = function LOG_DATA() { | ||
return !!(0, _env2.env)('LOG_DATA', 0); | ||
}; | ||
@@ -86,3 +79,3 @@ var Logger = /*#__PURE__*/function () { | ||
if (!this.level) this.level = 'trace'; | ||
if (!_config.levelsPriority[this.level]) throw new Error("Incorrect level ".concat(this.level)); | ||
if (!_config.levelsPriority[this.level]) throw new Error("Incorrect level: ".concat(this.level)); | ||
} | ||
@@ -182,27 +175,12 @@ }, { | ||
this.__log.apply(this, ['trace'].concat(args)); | ||
} | ||
} // log(...args: any[]): void { | ||
// if (!this.canLog('log')) return; | ||
// this.__log('log', ...args); | ||
// } | ||
}, { | ||
key: "log", | ||
value: function log() { | ||
if (!this.canLog('log')) return; | ||
for (var _len9 = arguments.length, args = new Array(_len9), _key9 = 0; _key9 < _len9; _key9++) { | ||
args[_key9] = arguments[_key9]; | ||
} | ||
this.__log.apply(this, ['log'].concat(args)); | ||
} | ||
}, { | ||
key: "__logger", | ||
value: function __logger() { | ||
for (var _len10 = arguments.length, args = new Array(_len10), _key10 = 0; _key10 < _len10; _key10++) { | ||
args[_key10] = arguments[_key10]; | ||
} | ||
// eslint-disable-next-line no-param-reassign | ||
if (LOG_FORMAT() !== 'none' && LOG_FORMAT() !== 'pretty') args = args.map(function (arg) { | ||
return (0, _toString.toString)(arg); | ||
}); // @ts-ignore | ||
// @ts-ignore | ||
// eslint-disable-next-line no-console | ||
if (console._log) { | ||
@@ -213,3 +191,3 @@ var _console; | ||
// eslint-disable-next-line no-console | ||
(_console = console)._log.apply(_console, (0, _toConsumableArray2["default"])(args)); | ||
(_console = console)._log.apply(_console, arguments); | ||
} else { | ||
@@ -219,3 +197,3 @@ var _console2; | ||
// eslint-disable-next-line no-console | ||
(_console2 = console).log.apply(_console2, (0, _toConsumableArray2["default"])(args)); | ||
(_console2 = console).log.apply(_console2, arguments); | ||
} | ||
@@ -226,4 +204,4 @@ } | ||
value: function __log(level) { | ||
for (var _len11 = arguments.length, args = new Array(_len11 > 1 ? _len11 - 1 : 0), _key11 = 1; _key11 < _len11; _key11++) { | ||
args[_key11 - 1] = arguments[_key11]; | ||
for (var _len9 = arguments.length, args = new Array(_len9 > 1 ? _len9 - 1 : 0), _key9 = 1; _key9 < _len9; _key9++) { | ||
args[_key9 - 1] = arguments[_key9]; | ||
} | ||
@@ -233,26 +211,23 @@ | ||
otherArgs = args.slice(1); | ||
var data = { | ||
var meta = { | ||
name: this.name, | ||
ns: this.ns, | ||
level: level, | ||
time: new Date() // ...mainArg, | ||
time: new Date() | ||
}; | ||
var passArgs = args; | ||
if ((0, _isUrlLog.isUrlLog)(mainArg)) { | ||
data = _objectSpread({}, mainArg); // console.log({mainArg}) | ||
if ((0, _lsklog.isLsklogWeb)(mainArg)) { | ||
meta = _objectSpread(_objectSpread({}, meta), mainArg); // console.log({mainArg}) | ||
passArgs = otherArgs; | ||
} | ||
} // // eslint-disable-next-line no-param-reassign | ||
// if (LOG_FORMAT() !== 'none' && LOG_FORMAT() !== 'pretty') args = args.map((arg) => toString(arg)); | ||
// if (LOG_DATA()) meta.data = passArgs; | ||
data.code = (0, _createMsg.getErrCode)(passArgs); | ||
data.msg = (0, _createMsg.createMsg)(passArgs); | ||
if (LOG_DATA() || LOG_FORMAT() === 'pretty') data.data = passArgs; | ||
data = (0, _omitNull.omitNull)(data); | ||
if (LOG_FORMAT() === 'none') return; | ||
if (LOG_FORMAT() === 'pretty') { | ||
this.__logger.apply(this, (0, _toConsumableArray2["default"])((0, _prettyFormat.prettyFormat)(this, data))); | ||
this.log.apply(this, (0, _toConsumableArray2["default"])(_prettyFormat.prettyFormat.apply(void 0, [(0, _omitNull.omitNull)(meta)].concat((0, _toConsumableArray2["default"])(passArgs))))); | ||
return; | ||
@@ -262,3 +237,3 @@ } // console.log({ args, data, str, 'LOG_FORMAT()': LOG_FORMAT() }); | ||
this.__logger(_formats.stringify.apply(void 0, [LOG_FORMAT(), data].concat((0, _toConsumableArray2["default"])(passArgs)))); | ||
this.log(_formats.stringify.apply(void 0, [LOG_FORMAT(), (0, _omitNull.omitNull)(meta)].concat((0, _toConsumableArray2["default"])(passArgs)))); | ||
} | ||
@@ -268,4 +243,4 @@ }], [{ | ||
value: function create() { | ||
for (var _len12 = arguments.length, propsArray = new Array(_len12), _key12 = 0; _key12 < _len12; _key12++) { | ||
propsArray[_key12] = arguments[_key12]; | ||
for (var _len10 = arguments.length, propsArray = new Array(_len10), _key10 = 0; _key10 < _len10; _key10++) { | ||
propsArray[_key10] = arguments[_key10]; | ||
} | ||
@@ -272,0 +247,0 @@ |
{ | ||
"name": "@lskjs/log", | ||
"version": "2.52.0", | ||
"version": "2.56.0", | ||
"description": "Логгер совмещающий лучшие черты morgan, winston, bunyan, logrus. debug. Базируется на debug-level.", | ||
@@ -48,3 +48,3 @@ "keywords": [], | ||
}, | ||
"gitHead": "329acc870ed557672518aba81eaee94e833ca317" | ||
"gitHead": "9f5a30d139b51edec225d90cc956c9199dd64a0e" | ||
} |
@@ -1,5 +0,5 @@ | ||
import { ILogger } from '../types'; | ||
import { ILoggerMeta } from '../types'; | ||
export declare function countInRow(args: any[], filter: any): number; | ||
export declare function concatFirstStrings(...args: any[]): string[]; | ||
export declare function prettyFormat(log: ILogger, ...args: any[]): string[]; | ||
export declare function prettyFormat(meta: ILoggerMeta, ...args: any[]): string[]; | ||
export default prettyFormat; |
@@ -15,3 +15,3 @@ "use strict"; | ||
var _isUrlLog = require("../utils/isUrlLog"); | ||
var _lsklog = require("../utils/formats/lsklog"); | ||
@@ -41,3 +41,7 @@ var _utils = require("./utils"); | ||
function prettyFormat(log) { | ||
function prettyFormat(meta) { | ||
var ns = meta === null || meta === void 0 ? void 0 : meta.ns; | ||
var name = meta === null || meta === void 0 ? void 0 : meta.name; | ||
var level = (meta === null || meta === void 0 ? void 0 : meta.level) || 'log'; // const [mainArg] = args; | ||
for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) { | ||
@@ -47,11 +51,16 @@ args[_key2 - 1] = arguments[_key2]; | ||
var mainArg = args[0]; | ||
var logArgs = mainArg.data || args; | ||
var logArgs = args; | ||
if ((0, _isUrlLog.isUrlLog)(mainArg)) { | ||
return [(0, _utils.prettyUrl)(mainArg)]; | ||
if ((0, _lsklog.isLsklogWeb)(meta)) { | ||
return [(0, _utils.prettyUrl)(meta)]; | ||
} | ||
var names = (log.ns || '').split(':').filter(Boolean).map(String); | ||
return concatFirstStrings.apply(void 0, [(0, _utils.prettyLevel)(mainArg.level), (0, _utils.prettyNs)(names, log.name)].concat((0, _toConsumableArray2["default"])(_utils.prettyContent.apply(void 0, (0, _toConsumableArray2["default"])(logArgs))))); | ||
var names = (ns || '').split(':').filter(Boolean).map(String); | ||
var prefix = [(0, _utils.prettyLevel)(level)]; | ||
if (names.length || name) { | ||
prefix.push((0, _utils.prettyNs)(names, name)); | ||
} | ||
return concatFirstStrings.apply(void 0, prefix.concat((0, _toConsumableArray2["default"])(_utils.prettyContent.apply(void 0, logArgs)))); | ||
} | ||
@@ -58,0 +67,0 @@ |
@@ -10,2 +10,4 @@ "use strict"; | ||
var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof")); | ||
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray")); | ||
@@ -19,2 +21,3 @@ | ||
/* eslint-disable no-param-reassign */ | ||
var prettyRawLog = function prettyRawLog(log, raw) { | ||
@@ -24,9 +27,21 @@ var json = (0, _tryJSONparse.tryJSONparse)(raw); | ||
if (!json) { | ||
log.log(raw); | ||
log.log.apply(log, (0, _toConsumableArray2["default"])((0, _prettyFormat.prettyFormat)({}, raw))); | ||
return; | ||
} | ||
var args = (0, _formats.parse)(json); // @ts-ignore | ||
if ((0, _typeof2["default"])(json) !== 'object') { | ||
log.log.apply(log, (0, _toConsumableArray2["default"])((0, _prettyFormat.prettyFormat)({}, json))); | ||
return; | ||
} | ||
log.__logger.apply(log, (0, _toConsumableArray2["default"])(_prettyFormat.prettyFormat.apply(void 0, [log].concat((0, _toConsumableArray2["default"])(args))))); | ||
var _parse = (0, _formats.parse)(json), | ||
meta = _parse.meta, | ||
_parse$args = _parse.args, | ||
args = _parse$args === void 0 ? [] : _parse$args; // console.log({ json, meta, args }); | ||
// const args = []; | ||
// if (meta.msg !== null) args.push(meta.msg); | ||
// if (Object.keys(data).length) args.push(data); | ||
log.log.apply(log, (0, _toConsumableArray2["default"])(_prettyFormat.prettyFormat.apply(void 0, [meta].concat((0, _toConsumableArray2["default"])(args))))); | ||
}; | ||
@@ -33,0 +48,0 @@ |
@@ -17,6 +17,6 @@ "use strict"; | ||
var _lsklog = require("../utils/formats/lsklog"); | ||
var _hashCode = require("../utils/hashCode"); | ||
var _isUrlLog = require("../utils/isUrlLog"); | ||
var _leftPad = require("../utils/leftPad"); | ||
@@ -137,3 +137,3 @@ | ||
var getUrlLevel = function getUrlLevel(req) { | ||
return getStatusLevel(req.status) || (0, _isUrlLog.isFinalUrlLog)(req) ? 'debug' : 'trace'; | ||
return getStatusLevel(req.status) || (0, _lsklog.isLsklogWebFinal)(req) ? 'debug' : 'trace'; | ||
}; | ||
@@ -144,3 +144,3 @@ | ||
var prettyUrl = function prettyUrl(req) { | ||
var isFinalUrl = (0, _isUrlLog.isFinalUrlLog)(req); | ||
var isFinalUrl = (0, _lsklog.isLsklogWebFinal)(req); | ||
var level = getUrlLevel(req); // , { level }: { level?: string | null } = {} | ||
@@ -147,0 +147,0 @@ |
@@ -26,1 +26,20 @@ export declare type LoggerLevelType = 'fatal' | 'error' | 'warn' | 'debug' | 'info' | 'trace' | 'log'; | ||
} | ||
export declare type ILoggerMeta = { | ||
ns?: string; | ||
name?: string; | ||
level?: string; | ||
time?: Date; | ||
method?: string; | ||
host?: string; | ||
reqId?: string | number; | ||
ua?: string; | ||
ip?: string; | ||
url?: string; | ||
status?: string; | ||
duration?: number; | ||
length?: number; | ||
}; | ||
export declare type ILoggerInternalMessage = { | ||
meta: ILoggerMeta; | ||
args: any[]; | ||
}; |
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
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
262251
128
2411
11