Comparing version 1.0.7 to 1.1.0
@@ -1,18 +0,18 @@ | ||
var M = Object.defineProperty; | ||
var P = (u, r, n) => r in u ? M(u, r, { enumerable: !0, configurable: !0, writable: !0, value: n }) : u[r] = n; | ||
var C = (u, r, n) => (P(u, typeof r != "symbol" ? r + "" : r, n), n); | ||
var G = typeof globalThis < "u" ? globalThis : typeof window < "u" ? window : typeof global < "u" ? global : typeof self < "u" ? self : {}, m = {}, N = { | ||
var N = Object.defineProperty; | ||
var V = (l, o, r) => o in l ? N(l, o, { enumerable: !0, configurable: !0, writable: !0, value: r }) : l[o] = r; | ||
var U = (l, o, r) => (V(l, typeof o != "symbol" ? o + "" : o, r), r); | ||
var k = typeof globalThis < "u" ? globalThis : typeof window < "u" ? window : typeof global < "u" ? global : typeof self < "u" ? self : {}, m = {}, M = { | ||
get exports() { | ||
return m; | ||
}, | ||
set exports(u) { | ||
m = u; | ||
set exports(l) { | ||
m = l; | ||
} | ||
}; | ||
(function(u) { | ||
(function(r, n) { | ||
u.exports ? u.exports = n() : r.log = n(); | ||
})(G, function() { | ||
var r = function() { | ||
}, n = "undefined", y = typeof window !== n && typeof window.navigator !== n && /Trident\/|MSIE /.test(window.navigator.userAgent), s = [ | ||
(function(l) { | ||
(function(o, r) { | ||
l.exports ? l.exports = r() : o.log = r(); | ||
})(k, function() { | ||
var o = function() { | ||
}, r = "undefined", y = typeof window !== r && typeof window.navigator !== r && /Trident\/|MSIE /.test(window.navigator.userAgent), f = [ | ||
"trace", | ||
@@ -24,45 +24,45 @@ "debug", | ||
]; | ||
function w(o, a) { | ||
var f = o[a]; | ||
if (typeof f.bind == "function") | ||
return f.bind(o); | ||
function w(n, a) { | ||
var u = n[a]; | ||
if (typeof u.bind == "function") | ||
return u.bind(n); | ||
try { | ||
return Function.prototype.bind.call(f, o); | ||
return Function.prototype.bind.call(u, n); | ||
} catch { | ||
return function() { | ||
return Function.prototype.apply.apply(f, [o, arguments]); | ||
return Function.prototype.apply.apply(u, [n, arguments]); | ||
}; | ||
} | ||
} | ||
function E() { | ||
function b() { | ||
console.log && (console.log.apply ? console.log.apply(console, arguments) : Function.prototype.apply.apply(console.log, [console, arguments])), console.trace && console.trace(); | ||
} | ||
function b(o) { | ||
return o === "debug" && (o = "log"), typeof console === n ? !1 : o === "trace" && y ? E : console[o] !== void 0 ? w(console, o) : console.log !== void 0 ? w(console, "log") : r; | ||
function x(n) { | ||
return n === "debug" && (n = "log"), typeof console === r ? !1 : n === "trace" && y ? b : console[n] !== void 0 ? w(console, n) : console.log !== void 0 ? w(console, "log") : o; | ||
} | ||
function g(o, a) { | ||
for (var f = 0; f < s.length; f++) { | ||
var t = s[f]; | ||
this[t] = f < o ? r : this.methodFactory(t, o, a); | ||
function c(n, a) { | ||
for (var u = 0; u < f.length; u++) { | ||
var t = f[u]; | ||
this[t] = u < n ? o : this.methodFactory(t, n, a); | ||
} | ||
this.log = this.debug; | ||
} | ||
function x(o, a, f) { | ||
function F(n, a, u) { | ||
return function() { | ||
typeof console !== n && (g.call(this, a, f), this[o].apply(this, arguments)); | ||
typeof console !== r && (c.call(this, a, u), this[n].apply(this, arguments)); | ||
}; | ||
} | ||
function i(o, a, f) { | ||
return b(o) || x.apply(this, arguments); | ||
function i(n, a, u) { | ||
return x(n) || F.apply(this, arguments); | ||
} | ||
function p(o, a, f) { | ||
var t = this, F; | ||
function g(n, a, u) { | ||
var t = this, O; | ||
a = a ?? "WARN"; | ||
var l = "loglevel"; | ||
typeof o == "string" ? l += ":" + o : typeof o == "symbol" && (l = void 0); | ||
function O(e) { | ||
var c = (s[e] || "silent").toUpperCase(); | ||
if (!(typeof window === n || !l)) { | ||
var s = "loglevel"; | ||
typeof n == "string" ? s += ":" + n : typeof n == "symbol" && (s = void 0); | ||
function C(e) { | ||
var p = (f[e] || "silent").toUpperCase(); | ||
if (!(typeof window === r || !s)) { | ||
try { | ||
window.localStorage[l] = c; | ||
window.localStorage[s] = p; | ||
return; | ||
@@ -72,3 +72,3 @@ } catch { | ||
try { | ||
window.document.cookie = encodeURIComponent(l) + "=" + c + ";"; | ||
window.document.cookie = encodeURIComponent(s) + "=" + p + ";"; | ||
} catch { | ||
@@ -78,15 +78,15 @@ } | ||
} | ||
function S() { | ||
function R() { | ||
var e; | ||
if (!(typeof window === n || !l)) { | ||
if (!(typeof window === r || !s)) { | ||
try { | ||
e = window.localStorage[l]; | ||
e = window.localStorage[s]; | ||
} catch { | ||
} | ||
if (typeof e === n) | ||
if (typeof e === r) | ||
try { | ||
var c = window.document.cookie, L = c.indexOf( | ||
encodeURIComponent(l) + "=" | ||
var p = window.document.cookie, L = p.indexOf( | ||
encodeURIComponent(s) + "=" | ||
); | ||
L !== -1 && (e = /^([^;]+)/.exec(c.slice(L))[1]); | ||
L !== -1 && (e = /^([^;]+)/.exec(p.slice(L))[1]); | ||
} catch { | ||
@@ -97,6 +97,6 @@ } | ||
} | ||
function U() { | ||
if (!(typeof window === n || !l)) { | ||
function T() { | ||
if (!(typeof window === r || !s)) { | ||
try { | ||
window.localStorage.removeItem(l); | ||
window.localStorage.removeItem(s); | ||
return; | ||
@@ -106,3 +106,3 @@ } catch { | ||
try { | ||
window.document.cookie = encodeURIComponent(l) + "=; expires=Thu, 01 Jan 1970 00:00:00 UTC"; | ||
window.document.cookie = encodeURIComponent(s) + "=; expires=Thu, 01 Jan 1970 00:00:00 UTC"; | ||
} catch { | ||
@@ -112,3 +112,3 @@ } | ||
} | ||
t.name = o, t.levels = { | ||
t.name = n, t.levels = { | ||
TRACE: 0, | ||
@@ -120,7 +120,7 @@ DEBUG: 1, | ||
SILENT: 5 | ||
}, t.methodFactory = f || i, t.getLevel = function() { | ||
return F; | ||
}, t.setLevel = function(e, c) { | ||
}, t.methodFactory = u || i, t.getLevel = function() { | ||
return O; | ||
}, t.setLevel = function(e, p) { | ||
if (typeof e == "string" && t.levels[e.toUpperCase()] !== void 0 && (e = t.levels[e.toUpperCase()]), typeof e == "number" && e >= 0 && e <= t.levels.SILENT) { | ||
if (F = e, c !== !1 && O(e), g.call(t, e, o), typeof console === n && e < t.levels.SILENT) | ||
if (O = e, p !== !1 && C(e), c.call(t, e, n), typeof console === r && e < t.levels.SILENT) | ||
return "No console available for logging"; | ||
@@ -130,5 +130,5 @@ } else | ||
}, t.setDefaultLevel = function(e) { | ||
a = e, S() || t.setLevel(e, !1); | ||
a = e, R() || t.setLevel(e, !1); | ||
}, t.resetLevel = function() { | ||
t.setLevel(a, !1), U(); | ||
t.setLevel(a, !1), T(); | ||
}, t.enableAll = function(e) { | ||
@@ -139,19 +139,19 @@ t.setLevel(t.levels.TRACE, e); | ||
}; | ||
var v = S(); | ||
var v = R(); | ||
v == null && (v = a), t.setLevel(v, !1); | ||
} | ||
var d = new p(), h = {}; | ||
var d = new g(), h = {}; | ||
d.getLogger = function(a) { | ||
if (typeof a != "symbol" && typeof a != "string" || a === "") | ||
throw new TypeError("You must supply a name when creating a logger."); | ||
var f = h[a]; | ||
return f || (f = h[a] = new p( | ||
var u = h[a]; | ||
return u || (u = h[a] = new g( | ||
a, | ||
d.getLevel(), | ||
d.methodFactory | ||
)), f; | ||
)), u; | ||
}; | ||
var I = typeof window !== n ? window.log : void 0; | ||
var I = typeof window !== r ? window.log : void 0; | ||
return d.noConflict = function() { | ||
return typeof window !== n && window.log === d && (window.log = I), d; | ||
return typeof window !== r && window.log === d && (window.log = I), d; | ||
}, d.getLoggers = function() { | ||
@@ -161,19 +161,19 @@ return h; | ||
}); | ||
})(N); | ||
var T = {}, D = { | ||
})(M); | ||
var _ = {}, P = { | ||
get exports() { | ||
return T; | ||
return _; | ||
}, | ||
set exports(u) { | ||
T = u; | ||
set exports(l) { | ||
_ = l; | ||
} | ||
}; | ||
(function(u) { | ||
(function(r, n) { | ||
u.exports ? u.exports = n() : r.prefix = n(r); | ||
})(G, function(r) { | ||
var n = function(i) { | ||
for (var p = 1, d = arguments.length, h; p < d; p++) | ||
for (h in arguments[p]) | ||
Object.prototype.hasOwnProperty.call(arguments[p], h) && (i[h] = arguments[p][h]); | ||
(function(l) { | ||
(function(o, r) { | ||
l.exports ? l.exports = r() : o.prefix = r(o); | ||
})(k, function(o) { | ||
var r = function(i) { | ||
for (var g = 1, d = arguments.length, h; g < d; g++) | ||
for (h in arguments[g]) | ||
Object.prototype.hasOwnProperty.call(arguments[g], h) && (i[h] = arguments[g][h]); | ||
return i; | ||
@@ -192,38 +192,38 @@ }, y = { | ||
format: void 0 | ||
}, s, w = {}, E = function(i) { | ||
}, f, w = {}, b = function(i) { | ||
if (!i || !i.getLogger) | ||
throw new TypeError("Argument is not a root logger"); | ||
s = i; | ||
}, b = function(i, p) { | ||
f = i; | ||
}, x = function(i, g) { | ||
if (!i || !i.setLevel) | ||
throw new TypeError("Argument is not a logger"); | ||
var d = i.methodFactory, h = i.name || "", I = w[h] || w[""] || y; | ||
function o(a, f, t) { | ||
var F = d(a, f, t), l = w[t] || w[""], O = l.template.indexOf("%t") !== -1, S = l.template.indexOf("%l") !== -1, U = l.template.indexOf("%n") !== -1; | ||
function n(a, u, t) { | ||
var O = d(a, u, t), s = w[t] || w[""], C = s.template.indexOf("%t") !== -1, R = s.template.indexOf("%l") !== -1, T = s.template.indexOf("%n") !== -1; | ||
return function() { | ||
for (var v = "", e = arguments.length, c = Array(e), L = 0; L < e; L++) | ||
c[L] = arguments[L]; | ||
for (var v = "", e = arguments.length, p = Array(e), L = 0; L < e; L++) | ||
p[L] = arguments[L]; | ||
if (h || !w[t]) { | ||
var R = l.timestampFormatter(new Date()), A = l.levelFormatter(a), k = l.nameFormatter(t); | ||
l.format ? v += l.format(A, k, R) : (v += l.template, O && (v = v.replace(/%t/, R)), S && (v = v.replace(/%l/, A)), U && (v = v.replace(/%n/, k))), c.length && typeof c[0] == "string" ? c[0] = v + " " + c[0] : c.unshift(v); | ||
var S = s.timestampFormatter(new Date()), A = s.levelFormatter(a), G = s.nameFormatter(t); | ||
s.format ? v += s.format(A, G, S) : (v += s.template, C && (v = v.replace(/%t/, S)), R && (v = v.replace(/%l/, A)), T && (v = v.replace(/%n/, G))), p.length && typeof p[0] == "string" ? p[0] = v + " " + p[0] : p.unshift(v); | ||
} | ||
F.apply(void 0, c); | ||
O.apply(void 0, p); | ||
}; | ||
} | ||
return w[h] || (i.methodFactory = o), p = p || {}, p.template && (p.format = void 0), w[h] = n({}, I, p), i.setLevel(i.getLevel()), s || i.warn( | ||
return w[h] || (i.methodFactory = n), g = g || {}, g.template && (g.format = void 0), w[h] = r({}, I, g), i.setLevel(i.getLevel()), f || i.warn( | ||
"It is necessary to call the function reg() of loglevel-plugin-prefix before calling apply. From the next release, it will throw an error. See more: https://github.com/kutuluk/loglevel-plugin-prefix/blob/master/README.md" | ||
), i; | ||
}, g = { | ||
reg: E, | ||
apply: b | ||
}, x; | ||
return r && (x = r.prefix, g.noConflict = function() { | ||
return r.prefix === g && (r.prefix = x), g; | ||
}), g; | ||
}, c = { | ||
reg: b, | ||
apply: x | ||
}, F; | ||
return o && (F = o.prefix, c.noConflict = function() { | ||
return o.prefix === c && (o.prefix = F), c; | ||
}), c; | ||
}); | ||
})(D); | ||
const W = "DEBUG", _ = "INFO", B = "WARN", V = "ERROR"; | ||
class z { | ||
constructor(r, n) { | ||
C(this, "consoleLogger", "console"); | ||
})(P); | ||
var E = /* @__PURE__ */ ((l) => (l.LOG_LEVEL_DEBUG = "DEBUG", l.LOG_LEVEL_INFO = "INFO", l.LOG_LEVEL_WARN = "WARN", l.LOG_LEVEL_ERROR = "ERROR", l))(E || {}); | ||
class W { | ||
constructor(o, r) { | ||
U(this, "consoleLogger", "console"); | ||
/** | ||
@@ -236,29 +236,29 @@ * 获取日志记录器 | ||
*/ | ||
C(this, "getLogger", (r) => m.getLogger(r ?? this.consoleLogger)); | ||
U(this, "getLogger", (o) => m.getLogger(o ?? this.consoleLogger)); | ||
const y = { | ||
gray: (s) => s.toString(), | ||
green: (s) => s.toString(), | ||
yellow: (s) => s.toString(), | ||
red: (s) => s.toString() | ||
gray: (f) => f.toString(), | ||
green: (f) => f.toString(), | ||
yellow: (f) => f.toString(), | ||
red: (f) => f.toString() | ||
}; | ||
T.reg(m), r ? m.setLevel(r) : m.setLevel(_), T.apply(m, { | ||
format(s, w, E) { | ||
const g = ["[" + (n ?? "zhi") + "]"]; | ||
switch (g.push( | ||
y.gray("[") + y.green(E).toString() + y.gray("]") | ||
), s) { | ||
case W: | ||
g.push(y.gray(s.toUpperCase().toString())); | ||
_.reg(m), o ? m.setLevel(o) : m.setLevel(E.LOG_LEVEL_INFO), _.apply(m, { | ||
format(f, w, b) { | ||
const c = ["[" + (r ?? "zhi") + "]"]; | ||
switch (c.push( | ||
y.gray("[") + y.green(b).toString() + y.gray("]") | ||
), f) { | ||
case E.LOG_LEVEL_DEBUG: | ||
c.push(y.gray(f.toUpperCase().toString())); | ||
break; | ||
case _: | ||
g.push(y.green(s.toUpperCase().toString())); | ||
case E.LOG_LEVEL_INFO: | ||
c.push(y.green(f.toUpperCase().toString())); | ||
break; | ||
case B: | ||
g.push(y.yellow(s.toUpperCase().toString())); | ||
case E.LOG_LEVEL_WARN: | ||
c.push(y.yellow(f.toUpperCase().toString())); | ||
break; | ||
case V: | ||
g.push(y.red(s.toUpperCase().toString())); | ||
case E.LOG_LEVEL_ERROR: | ||
c.push(y.red(f.toUpperCase().toString())); | ||
break; | ||
} | ||
return g.push(y.green(w).toString()), g.push(y.gray(":")), g.join(" "); | ||
return c.push(y.green(w).toString()), c.push(y.gray(":")), c.join(" "); | ||
} | ||
@@ -268,19 +268,4 @@ }); | ||
} | ||
class K { | ||
/** | ||
* 默认日志级别 | ||
* | ||
* @param level 可选,未设置默认INFO | ||
* @param sign 可选前缀,默认zhi | ||
*/ | ||
constructor(r, n) { | ||
C(this, "log"); | ||
this.log = new z(r, n); | ||
} | ||
getLogger(r) { | ||
return this.log.getLogger(r); | ||
} | ||
} | ||
export { | ||
K as default | ||
W as default | ||
}; |
{ | ||
"name": "zhi-log", | ||
"version": "1.0.7", | ||
"version": "1.1.0", | ||
"description": "a simple logger for Node", | ||
@@ -5,0 +5,0 @@ "type": "module", |
@@ -17,4 +17,3 @@ # zhi-log | ||
```js | ||
const logFactory = new LogFactory() | ||
const logger = logFactory.getLogger("test") | ||
const logger = LogUtil.defaultLogFactory().getLogger() | ||
logger.debug("This is debug log") | ||
@@ -24,4 +23,4 @@ logger.info("This is info log") | ||
// [zhi] [20:43:36] INFO test : This is info log | ||
// [zhi] [20:43:36] ERROR test : This is error log | ||
// [zhi] [11:26:51] INFO /Users/terwer/Documents/mydocs/zhi-log/test/log.test.ts:33:48 : This is info log | ||
// [zhi] [11:26:51] ERROR /Users/terwer/Documents/mydocs/zhi-log/test/log.test.ts:33:48 : This is error log | ||
``` | ||
@@ -32,4 +31,3 @@ | ||
```js | ||
const logFactory = new LogFactory("DEBUG") | ||
const logger = logFactory.getLogger("test") | ||
const logger = LogUtil.customLogFactory(LogLevelEnum.LOG_LEVEL_DEBUG).getLogger("test") | ||
logger.debug("This is debug log") | ||
@@ -39,5 +37,5 @@ logger.info("This is info log") | ||
// [zhi] [20:43:59] DEBUG test : This is debug log | ||
// [zhi] [20:43:59] INFO test : This is info log | ||
// [zhi] [20:43:59] ERROR test : This is error log | ||
// [zhi] [11:28:15] DEBUG test : This is debug log | ||
// [zhi] [11:28:15] INFO test : This is info log | ||
// [zhi] [11:28:15] ERROR test : This is error log | ||
``` | ||
@@ -48,4 +46,3 @@ | ||
```js | ||
const logFactory = new LogFactory("DEBUG", "my-log") | ||
const logger = logFactory.getLogger("test") | ||
const logger = LogUtil.customLogFactory(LogLevelEnum.LOG_LEVEL_DEBUG, "my-log").getLogger("test") | ||
logger.debug("This is debug log") | ||
@@ -55,5 +52,5 @@ logger.info("This is info log") | ||
// [my-log] [20:46:06] DEBUG test : This is debug log | ||
// [my-log] [20:46:06] INFO test : This is info log | ||
// [my-log] [20:46:06] ERROR test : This is error log | ||
// [my-log] [11:29:04] DEBUG test : This is debug log | ||
// [my-log] [11:29:04] INFO test : This is info log | ||
// [my-log] [11:29:04] ERROR test : This is error log | ||
``` |
Sorry, the diff of this file is not supported yet
17093
282
50