New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

zhi-log

Package Overview
Dependencies
Maintainers
1
Versions
52
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

zhi-log - npm Package Compare versions

Comparing version 1.5.3 to 1.5.4

lib/src/factory/abstractLogFactory.d.ts

207

lib/index.js
var D = Object.defineProperty;
var W = (i, e, t) => e in i ? D(i, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : i[e] = t;
var _ = (i, e, t) => (W(i, typeof e != "symbol" ? e + "" : e, t), t);
var P = typeof globalThis < "u" ? globalThis : typeof window < "u" ? window : typeof global < "u" ? global : typeof self < "u" ? self : {}, b = {}, B = {
var z = (i, e, t) => e in i ? D(i, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : i[e] = t;
var S = (i, e, t) => (z(i, typeof e != "symbol" ? e + "" : e, t), t);
var P = typeof globalThis < "u" ? globalThis : typeof window < "u" ? window : typeof global < "u" ? global : typeof self < "u" ? self : {}, _ = {}, W = {
get exports() {
return b;
return _;
},
set exports(i) {
b = i;
_ = i;
}

@@ -25,10 +25,10 @@ };

function s(a, c) {
var g = a[c];
if (typeof g.bind == "function")
return g.bind(a);
var f = a[c];
if (typeof f.bind == "function")
return f.bind(a);
try {
return Function.prototype.bind.call(g, a);
return Function.prototype.bind.call(f, a);
} catch {
return function() {
return Function.prototype.apply.apply(g, [a, arguments]);
return Function.prototype.apply.apply(f, [a, arguments]);
};

@@ -43,27 +43,27 @@ }

}
function h(a, c) {
for (var g = 0; g < p.length; g++) {
var o = p[g];
this[o] = g < a ? e : this.methodFactory(o, a, c);
function E(a, c) {
for (var f = 0; f < p.length; f++) {
var o = p[f];
this[o] = f < a ? e : this.methodFactory(o, a, c);
}
this.log = this.debug;
}
function O(a, c, g) {
function b(a, c, f) {
return function() {
typeof console !== t && (h.call(this, c, g), this[a].apply(this, arguments));
typeof console !== t && (E.call(this, c, f), this[a].apply(this, arguments));
};
}
function r(a, c, g) {
return w(a) || O.apply(this, arguments);
function r(a, c, f) {
return w(a) || b.apply(this, arguments);
}
function v(a, c, g) {
var o = this, x;
function v(a, c, f) {
var o = this, O;
c = c ?? "WARN";
var f = "loglevel";
typeof a == "string" ? f += ":" + a : typeof a == "symbol" && (f = void 0);
var g = "loglevel";
typeof a == "string" ? g += ":" + a : typeof a == "symbol" && (g = void 0);
function C(n) {
var d = (p[n] || "silent").toUpperCase();
if (!(typeof window === t || !f)) {
if (!(typeof window === t || !g)) {
try {
window.localStorage[f] = d;
window.localStorage[g] = d;
return;

@@ -73,3 +73,3 @@ } catch {

try {
window.document.cookie = encodeURIComponent(f) + "=" + d + ";";
window.document.cookie = encodeURIComponent(g) + "=" + d + ";";
} catch {

@@ -79,7 +79,7 @@ }

}
function S() {
function x() {
var n;
if (!(typeof window === t || !f)) {
if (!(typeof window === t || !g)) {
try {
n = window.localStorage[f];
n = window.localStorage[g];
} catch {

@@ -90,3 +90,3 @@ }

var d = window.document.cookie, m = d.indexOf(
encodeURIComponent(f) + "="
encodeURIComponent(g) + "="
);

@@ -100,5 +100,5 @@ m !== -1 && (n = /^([^;]+)/.exec(d.slice(m))[1]);

function V() {
if (!(typeof window === t || !f)) {
if (!(typeof window === t || !g)) {
try {
window.localStorage.removeItem(f);
window.localStorage.removeItem(g);
return;

@@ -108,3 +108,3 @@ } catch {

try {
window.document.cookie = encodeURIComponent(f) + "=; expires=Thu, 01 Jan 1970 00:00:00 UTC";
window.document.cookie = encodeURIComponent(g) + "=; expires=Thu, 01 Jan 1970 00:00:00 UTC";
} catch {

@@ -121,7 +121,7 @@ }

SILENT: 5
}, o.methodFactory = g || r, o.getLevel = function() {
return x;
}, o.methodFactory = f || r, o.getLevel = function() {
return O;
}, o.setLevel = function(n, d) {
if (typeof n == "string" && o.levels[n.toUpperCase()] !== void 0 && (n = o.levels[n.toUpperCase()]), typeof n == "number" && n >= 0 && n <= o.levels.SILENT) {
if (x = n, d !== !1 && C(n), h.call(o, n, a), typeof console === t && n < o.levels.SILENT)
if (O = n, d !== !1 && C(n), E.call(o, n, a), typeof console === t && n < o.levels.SILENT)
return "No console available for logging";

@@ -131,3 +131,3 @@ } else

}, o.setDefaultLevel = function(n) {
c = n, S() || o.setLevel(n, !1);
c = n, x() || o.setLevel(n, !1);
}, o.resetLevel = function() {

@@ -140,30 +140,30 @@ o.setLevel(c, !1), V();

};
var y = S();
var y = x();
y == null && (y = c), o.setLevel(y, !1);
}
var L = new v(), E = {};
var L = new v(), h = {};
L.getLogger = function(c) {
if (typeof c != "symbol" && typeof c != "string" || c === "")
throw new TypeError("You must supply a name when creating a logger.");
var g = E[c];
return g || (g = E[c] = new v(
var f = h[c];
return f || (f = h[c] = new v(
c,
L.getLevel(),
L.methodFactory
)), g;
)), f;
};
var k = typeof window !== t ? window.log : void 0;
var G = typeof window !== t ? window.log : void 0;
return L.noConflict = function() {
return typeof window !== t && window.log === L && (window.log = k), L;
return typeof window !== t && window.log === L && (window.log = G), L;
}, L.getLoggers = function() {
return E;
return h;
}, L.default = L, L;
});
})(B);
var T = {}, K = {
})(W);
var k = {}, B = {
get exports() {
return T;
return k;
},
set exports(i) {
T = i;
k = i;
}

@@ -176,5 +176,5 @@ };

var t = function(r) {
for (var v = 1, L = arguments.length, E; v < L; v++)
for (E in arguments[v])
Object.prototype.hasOwnProperty.call(arguments[v], E) && (r[E] = arguments[v][E]);
for (var v = 1, L = arguments.length, h; v < L; v++)
for (h in arguments[v])
Object.prototype.hasOwnProperty.call(arguments[v], h) && (r[h] = arguments[v][h]);
return r;

@@ -200,32 +200,32 @@ }, l = {

throw new TypeError("Argument is not a logger");
var L = r.methodFactory, E = r.name || "", k = s[E] || s[""] || l;
function a(c, g, o) {
var x = L(c, g, o), f = s[o] || s[""], C = f.template.indexOf("%t") !== -1, S = f.template.indexOf("%l") !== -1, V = f.template.indexOf("%n") !== -1;
var L = r.methodFactory, h = r.name || "", G = s[h] || s[""] || l;
function a(c, f, o) {
var O = L(c, f, o), g = s[o] || s[""], C = g.template.indexOf("%t") !== -1, x = g.template.indexOf("%l") !== -1, V = g.template.indexOf("%n") !== -1;
return function() {
for (var y = "", n = arguments.length, d = Array(n), m = 0; m < n; m++)
d[m] = arguments[m];
if (E || !s[o]) {
var R = f.timestampFormatter(new Date()), U = f.levelFormatter(c), A = f.nameFormatter(o);
f.format ? y += f.format(U, A, R) : (y += f.template, C && (y = y.replace(/%t/, R)), S && (y = y.replace(/%l/, U)), V && (y = y.replace(/%n/, A))), d.length && typeof d[0] == "string" ? d[0] = y + " " + d[0] : d.unshift(y);
if (h || !s[o]) {
var R = g.timestampFormatter(new Date()), U = g.levelFormatter(c), A = g.nameFormatter(o);
g.format ? y += g.format(U, A, R) : (y += g.template, C && (y = y.replace(/%t/, R)), x && (y = y.replace(/%l/, U)), V && (y = y.replace(/%n/, A))), d.length && typeof d[0] == "string" ? d[0] = y + " " + d[0] : d.unshift(y);
}
x.apply(void 0, d);
O.apply(void 0, d);
};
}
return s[E] || (r.methodFactory = a), v = v || {}, v.template && (v.format = void 0), s[E] = t({}, k, v), r.setLevel(r.getLevel()), p || r.warn(
return s[h] || (r.methodFactory = a), v = v || {}, v.template && (v.format = void 0), s[h] = t({}, G, v), r.setLevel(r.getLevel()), p || r.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"
), r;
}, h = {
}, E = {
reg: u,
apply: w
}, O;
return e && (O = e.prefix, h.noConflict = function() {
return e.prefix === h && (e.prefix = O), h;
}), h;
}, b;
return e && (b = e.prefix, E.noConflict = function() {
return e.prefix === E && (e.prefix = b), E;
}), E;
});
})(K);
class I {
})(B);
class T {
}
_(I, "LOG_LEVEL_KEY", "VITE_LOG_LEVEL"), _(I, "LOG_PREFIX_KEY", "VITE_LOG_PREFIX");
S(T, "LOG_LEVEL_KEY", "VITE_LOG_LEVEL"), S(T, "LOG_PREFIX_KEY", "VITE_LOG_PREFIX");
var F = /* @__PURE__ */ ((i) => (i.LOG_LEVEL_DEBUG = "DEBUG", i.LOG_LEVEL_INFO = "INFO", i.LOG_LEVEL_WARN = "WARN", i.LOG_LEVEL_ERROR = "ERROR", i))(F || {});
function Y() {
function K() {
const i = Error.prepareStackTrace;

@@ -236,3 +236,3 @@ Error.prepareStackTrace = (t, l) => l;

}
class G {
class I {
/**

@@ -256,5 +256,5 @@ * 解析日志级别为枚举

const t = e.getEnvOrDefault(
I.LOG_LEVEL_KEY,
T.LOG_LEVEL_KEY,
F.LOG_LEVEL_INFO
), l = G.stringToEnumValue(
), l = I.stringToEnumValue(
F,

@@ -272,8 +272,9 @@ t.toUpperCase()

if (e)
return e.getEnv(I.LOG_PREFIX_KEY);
return e.getEnv(T.LOG_PREFIX_KEY);
}
}
class X {
class Y {
constructor(e, t, l) {
_(this, "consoleLogger", "console");
S(this, "consoleLogger", "console");
S(this, "stackSize", 1);
/**

@@ -286,3 +287,3 @@ * 获取日志记录器

*/
_(this, "getLogger", (e) => {
S(this, "getLogger", (e) => {
let t;

@@ -292,3 +293,3 @@ if (e)

else {
const l = Y(), p = [];
const l = K(), p = [];
for (let s = 0; s < l.length; s++) {

@@ -298,13 +299,13 @@ const u = l[s], w = u.getFileName() ?? "none";

continue;
if (s > 5)
if (s > this.stackSize - 1)
break;
const h = w + "-" + u.getLineNumber() + ":" + u.getColumnNumber();
p.push(h);
const E = w + "-" + u.getLineNumber() + ":" + u.getColumnNumber();
p.push(E);
}
l.length === 0 ? t = void 0 : t = p.join(" -> ");
}
return t = t ?? this.consoleLogger, b.getLogger(t);
return t = t ?? this.consoleLogger, _.getLogger(t);
});
let p;
e ? p = e : p = G.getEnvLevel(l), p = p ?? F.LOG_LEVEL_INFO, b.setLevel(p);
e ? p = e : p = I.getEnvLevel(l), p = p ?? F.LOG_LEVEL_INFO, _.setLevel(p);
const s = {

@@ -316,7 +317,7 @@ gray: (u) => u.toString(),

};
T.reg(b), T.apply(b, {
format(u, w, h) {
const r = ["[" + (t ?? G.getEnvLogger(l) ?? "zhi") + "]"];
k.reg(_), k.apply(_, {
format(u, w, E) {
const r = ["[" + (t ?? I.getEnvLogger(l) ?? "zhi") + "]"];
switch (r.push(
s.gray("[") + s.green(h).toString() + s.gray("]")
s.gray("[") + s.green(E).toString() + s.gray("]")
), u) {

@@ -340,4 +341,12 @@ case F.LOG_LEVEL_DEBUG:

}
/**
* 设置输出栈的深度,默认1
*
* @param stackSize 栈的深度
*/
setStackSize(e) {
this.stackSize = e ?? 1;
}
}
class z {
class X {
/**

@@ -351,4 +360,4 @@ * 默认日志级别

constructor(e, t, l) {
_(this, "log");
this.log = new X(e, t, l);
S(this, "logger");
this.logger = new Y(e, t, l);
}

@@ -359,9 +368,10 @@ /**

* @param loggerName - 日志记录器名称
* @param stackSize - 打印栈的深度
* @protected
*/
getLogger(e) {
return this.log.getLogger(e);
getLogger(e, t) {
return this.logger.setStackSize(t), this.logger.getLogger(e);
}
}
class N extends z {
class N extends X {
constructor(e, t, l) {

@@ -374,5 +384,6 @@ super(e, t, l);

* @param loggerName - 日志记录器名称
* @param stackSize - 打印栈的深度
*/
getLogger(e) {
return super.getLogger(e);
getLogger(e, t) {
return super.getLogger(e, t);
}

@@ -384,6 +395,10 @@ }

*
* @param stackSize 栈的深度
* @param env - 环境变量实例
*/
static defaultLogger(e) {
return M.customLogFactory(void 0, void 0, e).getLogger();
static defaultLogger(e, t) {
return M.customLogFactory(void 0, void 0, e).getLogger(
void 0,
t
);
}

@@ -404,6 +419,6 @@ /**

export {
X as AbstractLogFactory,
N as CustomLogFactory,
z as LogFactory,
F as LogLevelEnum,
M as default
};

@@ -1,5 +0,5 @@

import LogFactory from '../../src/factory/logFactory';
import AbstractLogFactory from '../../src/factory/abstractLogFactory';
import LogLevelEnum from '../../src/logConstants';
import DefaultLogger from '../../src/logger';
import Env from "zhi-env";
import DefaultLogger from '../../src/defaultLogger';
/**

@@ -12,3 +12,3 @@ * 自定义日志工厂

*/
declare class CustomLogFactory extends LogFactory {
declare class CustomLogFactory extends AbstractLogFactory {
constructor(level?: LogLevelEnum, sign?: string, env?: Env);

@@ -19,6 +19,7 @@ /**

* @param loggerName - 日志记录器名称
* @param stackSize - 打印栈的深度
*/
getLogger(loggerName?: string): DefaultLogger;
getLogger(loggerName?: string, stackSize?: number): DefaultLogger;
}
export default CustomLogFactory;
//# sourceMappingURL=customLogFactory.d.ts.map
{
"name": "zhi-log",
"version": "1.5.3",
"version": "1.5.4",
"description": "a simple logger for Node and Browser",

@@ -5,0 +5,0 @@ "files": [

/**
* @packageDocumentation
* This is the documentation for my package.
* 同时支持 Node 和 浏览器 的 简洁、强大的日志框架
*/

@@ -10,2 +10,29 @@

/**
* 日志记录工厂
*
* @public
* @author terwer
* @since 1.0.0
*/
export declare abstract class AbstractLogFactory {
private logger
/**
* 默认日志级别
*
* @param level - 可选,未设置默认INFO
* @param sign - 可选前缀,默认zhi
* @param env - 可选环境变量实例
*/
protected constructor(level?: LogLevelEnum, sign?: string, env?: Env)
/**
* 获取日志记录器
*
* @param loggerName - 日志记录器名称
* @param stackSize - 打印栈的深度
* @protected
*/
protected getLogger(loggerName?: string, stackSize?: number): DefaultLogger
}
/**
* 自定义日志工厂

@@ -17,3 +44,3 @@ *

*/
export declare class CustomLogFactory extends LogFactory {
export declare class CustomLogFactory extends AbstractLogFactory {
constructor(level?: LogLevelEnum, sign?: string, env?: Env)

@@ -24,4 +51,5 @@ /**

* @param loggerName - 日志记录器名称
* @param stackSize - 打印栈的深度
*/
getLogger(loggerName?: string): DefaultLogger
getLogger(loggerName?: string, stackSize?: number): DefaultLogger
}

@@ -45,62 +73,66 @@

*
* @param msg - any data to log to the console
* @param msg - unknown data to log to the console
*/
trace(...msg: any[]): void
trace(...msg: unknown[]): void
/**
* Output debug message to console including appropriate icons
*
* @param msg - any data to log to the console
* @param msg - unknown data to log to the console
*/
debug(...msg: any[]): void
debug(...msg: unknown[]): void
/**
* Output debug message to console including appropriate icons
*
* @param msg - any data to log to the console
* @param msg - unknown data to log to the console
*/
log(...msg: any[]): void
log(...msg: unknown[]): void
/**
* Output info message to console including appropriate icons
*
* @param msg - any data to log to the console
* @param msg - unknown data to log to the console
*/
info(...msg: any[]): void
info(...msg: unknown[]): void
/**
* Output warn message to console including appropriate icons
*
* @param msg - any data to log to the console
* @param msg - unknown data to log to the console
*/
warn(...msg: any[]): void
warn(...msg: unknown[]): void
/**
* Output error message to console including appropriate icons
*
* @param msg - any data to log to the console
* @param msg - unknown data to log to the console
*/
error(...msg: any[]): void
error(...msg: unknown[]): void
}
/**
* 日志记录工厂
* 日志工具类
*
* @public
* @author terwer
* @since 1.0.0
* @since 1.0.7
*/
export declare abstract class LogFactory {
private log
declare class LogFactory {
/**
* 默认日志级别
* 默认日志记录器
*
* @param level - 可选,未设置默认INFO
* @param sign - 可选前缀,默认zhi
* @param env - 可选环境变量实例
* @param stackSize 栈的深度
* @param env - 环境变量实例
*/
protected constructor(level?: LogLevelEnum, sign?: string, env?: Env)
static defaultLogger(env?: Env, stackSize?: number): DefaultLogger
/**
* 获取日志记录器
*
* @param loggerName - 日志记录器名称
* @protected
* 自定义日志工厂
*/
protected getLogger(loggerName?: string): DefaultLogger
static customLogFactory(
level?: LogLevelEnum,
sign?: string,
env?: Env
): CustomLogFactory
/**
* 自定义日志工厂,自定义前缀
*/
static customSignLogFactory(sign?: string, env?: Env): CustomLogFactory
}
export default LogFactory

@@ -133,31 +165,2 @@ /**

/**
* 日志工具类
*
* @public
* @author terwer
* @since 1.0.7
*/
declare class LogUtil {
/**
* 默认日志记录器
*
* @param env - 环境变量实例
*/
static defaultLogger(env?: Env): DefaultLogger
/**
* 自定义日志工厂
*/
static customLogFactory(
level?: LogLevelEnum,
sign?: string,
env?: Env
): CustomLogFactory
/**
* 自定义日志工厂,自定义前缀
*/
static customSignLogFactory(sign?: string, env?: Env): CustomLogFactory
}
export default LogUtil
export {}

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