@jsmodules/logger
Advanced tools
Comparing version 2.0.16 to 2.0.17
@@ -15,6 +15,7 @@ export declare type LogLevel = "none" | "debug" | "info" | "warn" | "error"; | ||
setLogLevel: (level: LogLevel) => void; | ||
showTimestamps: (show: boolean) => void; | ||
tag: (tagName: string) => ILoggerAdapter; | ||
} | ||
export declare const Logger: ILoggerAdapter & ILogger; | ||
export {}; | ||
export default Logger; | ||
//# sourceMappingURL=index.d.ts.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Logger = void 0; | ||
var tslib_1 = require("tslib"); | ||
var logTypes = ["none", "debug", "info", "warn", "error"]; | ||
var adapters = {}; | ||
var logLevel = "debug"; | ||
var logTypes = ["none", "error", "warn", "info", "debug"]; | ||
var adapters = { | ||
console: console, | ||
}; | ||
var logSettings = { | ||
logLevel: "debug", | ||
showTimestamps: false, | ||
}; | ||
function setAdapter(name, adapter) { | ||
@@ -22,3 +26,3 @@ adapters[name] = adapter; | ||
var logIdx = logTypes.indexOf(logType); | ||
var level = logTypes.indexOf(logLevel); | ||
var level = logTypes.indexOf(logSettings.logLevel); | ||
if (logIdx > level) { | ||
@@ -31,9 +35,16 @@ return; | ||
var logMethod = adapter[logType]; | ||
var prefix = "[" + tagName + "]"; | ||
if (logSettings.showTimestamps) { | ||
prefix = "[" + new Date().toLocaleTimeString() + "]" + prefix; | ||
} | ||
if (logType === "assert") { | ||
var _a = (0, tslib_1.__read)(args), condition = _a[0], message = _a[1], data = _a.slice(2); | ||
logMethod.apply(void 0, (0, tslib_1.__spreadArray)([condition, "[".concat(tagName, "] ").concat(message)], (0, tslib_1.__read)(data), false)); | ||
var condition = args[0]; | ||
var message = args[1]; | ||
var data = args.slice(2); | ||
logMethod.apply(null, [condition, prefix + " " + message].concat(data)); | ||
} | ||
else { | ||
var _b = (0, tslib_1.__read)(args), message = _b[0], data = _b.slice(1); | ||
logMethod.apply(void 0, (0, tslib_1.__spreadArray)(["[".concat(tagName, "] ").concat(message)], (0, tslib_1.__read)(data), false)); | ||
var message = args[0]; | ||
var data = args.slice(1); | ||
logMethod.apply(null, [prefix + " " + message].concat(data)); | ||
} | ||
@@ -58,4 +69,7 @@ } | ||
setLogLevel: function (level) { | ||
logLevel = level; | ||
logSettings.logLevel = level; | ||
}, | ||
showTimestamps: function (show) { | ||
logSettings.showTimestamps = show; | ||
}, | ||
tag: function (tagName) { | ||
@@ -69,3 +83,3 @@ return new Proxy({}, { | ||
} | ||
applyLog.apply(void 0, (0, tslib_1.__spreadArray)([logType, tagName], (0, tslib_1.__read)(args), false)); | ||
applyLog.apply(null, [logType, tagName].concat(args)); | ||
}; | ||
@@ -86,3 +100,3 @@ }, | ||
} | ||
applyLog.apply(void 0, (0, tslib_1.__spreadArray)([prop, "Default"], (0, tslib_1.__read)(args), false)); | ||
applyLog.apply(null, [prop, "Default"].concat(args)); | ||
}; | ||
@@ -92,2 +106,3 @@ } | ||
}); | ||
exports.default = exports.Logger; | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "@jsmodules/logger", | ||
"version": "2.0.16", | ||
"version": "2.0.17", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -1,2 +0,2 @@ | ||
const logTypes = ["none", "debug", "info", "warn", "error"]; | ||
const logTypes = ["none", "error", "warn", "info", "debug"]; | ||
@@ -13,5 +13,14 @@ export type LogLevel = "none" | "debug" | "info" | "warn" | "error"; | ||
let adapters: { [key: string]: ILoggerAdapter } = {}; | ||
let logLevel: LogLevel = "debug"; | ||
let adapters: { [key: string]: ILoggerAdapter } = { | ||
console: console, | ||
}; | ||
const logSettings: { | ||
logLevel: LogLevel; | ||
showTimestamps: boolean; | ||
} = { | ||
logLevel: "debug", | ||
showTimestamps: false, | ||
}; | ||
function setAdapter(name, adapter: ILoggerAdapter) { | ||
@@ -29,3 +38,3 @@ adapters[name] = adapter; | ||
const logIdx = logTypes.indexOf(logType); | ||
const level = logTypes.indexOf(logLevel); | ||
const level = logTypes.indexOf(logSettings.logLevel); | ||
if (logIdx > level) { | ||
@@ -38,8 +47,15 @@ return; | ||
const logMethod = adapter[logType]; | ||
let prefix = "[" + tagName + "]"; | ||
if (logSettings.showTimestamps) { | ||
prefix = "[" + new Date().toLocaleTimeString() + "]" + prefix; | ||
} | ||
if (logType === "assert") { | ||
const [condition, message, ...data] = args; | ||
logMethod(condition, `[${tagName}] ${message}`, ...data); | ||
const condition = args[0]; | ||
const message = args[1]; | ||
const data = args.slice(2); | ||
logMethod.apply(null, [condition, prefix + " " + message].concat(data)); | ||
} else { | ||
const [message, ...data] = args; | ||
logMethod(`[${tagName}] ${message}`, ...data); | ||
const message = args[0]; | ||
const data = args.slice(1); | ||
logMethod.apply(null, [prefix + " " + message].concat(data)); | ||
} | ||
@@ -55,2 +71,3 @@ } | ||
setLogLevel: (level: LogLevel) => void; | ||
showTimestamps: (show: boolean) => void; | ||
tag: (tagName: string) => ILoggerAdapter; | ||
@@ -73,4 +90,7 @@ } | ||
setLogLevel: (level: LogLevel) => { | ||
logLevel = level; | ||
logSettings.logLevel = level; | ||
}, | ||
showTimestamps: (show: boolean) => { | ||
logSettings.showTimestamps = show; | ||
}, | ||
tag: (tagName) => { | ||
@@ -80,3 +100,3 @@ return new Proxy<ILoggerAdapter>({} as any, { | ||
return function (...args) { | ||
applyLog(logType, tagName, ...args); | ||
applyLog.apply(null, [logType, tagName].concat(args)); | ||
}; | ||
@@ -93,3 +113,3 @@ }, | ||
return function (...args) { | ||
applyLog(prop, "Default", ...args); | ||
applyLog.apply(null, [prop, "Default"].concat(args)); | ||
}; | ||
@@ -100,1 +120,2 @@ } | ||
); | ||
export default Logger; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
12341
235
0