@lytjs/plugin-logger 4.0.5 → 4.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +1 -1
- package/dist/types/index.d.ts +62 -0
- package/dist/types/index.d.ts.map +1 -0
- package/package.json +8 -6
package/dist/index.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
var d=Object.defineProperty;var I=Object.getOwnPropertyDescriptor;var $=Object.getOwnPropertyNames;var _=Object.prototype.hasOwnProperty;var R=(o,r)=>{for(var n in r)d(o,n,{get:r[n],enumerable:!0})},k=(o,r,n,g)=>{if(r&&typeof r=="object"||typeof r=="function")for(let i of $(r))!_.call(o,i)&&i!==n&&d(o,i,{get:()=>r[i],enumerable:!(g=I(r,i))||g.enumerable});return o};var N=o=>k(d({},"__esModule",{value:!0}),o);var T={};R(T,{createLogger:()=>J});module.exports=N(T);var b={debug:0,info:1,warn:2,error:3,silent:4},l={reset:"\x1B[0m",gray:"\x1B[90m",blue:"\x1B[36m",yellow:"\x1B[33m",red:"\x1B[31m",bold:"\x1B[1m"},c="lyt_logger_logs";function O(o){return new Date(o).toISOString()}function P(o){return o.map(r=>{if(r===null)return"null";if(r===void 0)return"undefined";if(typeof r=="string")return r;if(typeof r=="number"||typeof r=="boolean")return String(r);if(r instanceof Error)return`${r.message}
|
|
2
2
|
${r.stack||""}`;try{return JSON.stringify(r,null,2)}catch(n){return String(r)}}).join(" ")}function C(o){switch(o){case"debug":return l.gray;case"info":return l.blue;case"warn":return l.yellow;case"error":return l.red;default:return l.reset}}function E(o){return o.toUpperCase().padEnd(5)}function J(o){let{level:r="info",prefix:n="",persist:g=!1,maxLogs:i=1e3,timestamp:v=!0,format:m,transport:p}=o||{},u=r,t=[],y=!1;if(g)try{let e=localStorage.getItem(c);e&&(t=JSON.parse(e))}catch(e){t=[]}function h(){if(g)try{localStorage.setItem(c,JSON.stringify(t))}catch(e){}}function w(e){if(m)return m.replace("{timestamp}",v?O(e.timestamp):"").replace("{level}",E(e.level)).replace("{prefix}",n).replace("{message}",e.message);let s=[];return v&&s.push(O(e.timestamp)),n&&s.push(n),s.push(`${E(e.level)} ${e.message}`),s.join(" ")}function a(e,s){if(y||b[e]<b[u])return;let L={level:e,message:P(s),timestamp:Date.now(),args:[...s]};t.push(L),t.length>i&&(t=t.slice(t.length-i)),h();let S=C(e),x=w(L),j=`${S}${x}${l.reset}`;switch(e){case"debug":break;case"info":break;case"warn":break;case"error":break}if(p)try{p(L)}catch(A){}}let f={install(e,s){e.config=e.config||{},e.config.globalProperties=e.config.globalProperties||{},e.config.globalProperties.$logger=f,typeof e.provide=="function"&&e.provide("logger",f)},debug(...e){a("debug",e)},info(...e){a("info",e)},warn(...e){a("warn",e)},error(...e){a("error",e)},setLevel(e){u=e},getLevel(){return u},getLogs(){return[...t]},clearLogs(){if(t=[],g)try{localStorage.removeItem(c)}catch(e){}},destroy(){if(y=!0,t=[],g)try{localStorage.removeItem(c)}catch(e){}}};return f}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/** 日志级别 */
|
|
2
|
+
type LogLevel = 'debug' | 'info' | 'warn' | 'error' | 'silent';
|
|
3
|
+
/** 日志插件配置选项 */
|
|
4
|
+
interface LoggerOptions {
|
|
5
|
+
/** 日志级别,默认 'info' */
|
|
6
|
+
level?: LogLevel;
|
|
7
|
+
/** 日志前缀 */
|
|
8
|
+
prefix?: string;
|
|
9
|
+
/** 是否持久化到 localStorage,默认 false */
|
|
10
|
+
persist?: boolean;
|
|
11
|
+
/** 最大日志条数,默认 1000 */
|
|
12
|
+
maxLogs?: number;
|
|
13
|
+
/** 是否显示时间戳,默认 true */
|
|
14
|
+
timestamp?: boolean;
|
|
15
|
+
/** 格式化模板,例如 '{timestamp} [{level}] {prefix} {message}' */
|
|
16
|
+
format?: string;
|
|
17
|
+
/** 自定义日志传输(如发送到服务器) */
|
|
18
|
+
transport?: (log: LogEntry) => void;
|
|
19
|
+
}
|
|
20
|
+
/** 日志条目 */
|
|
21
|
+
interface LogEntry {
|
|
22
|
+
/** 日志级别 */
|
|
23
|
+
level: LogLevel;
|
|
24
|
+
/** 日志消息 */
|
|
25
|
+
message: string;
|
|
26
|
+
/** 时间戳(毫秒) */
|
|
27
|
+
timestamp: number;
|
|
28
|
+
/** 附加参数 */
|
|
29
|
+
args: any[];
|
|
30
|
+
}
|
|
31
|
+
/** 日志插件实例 */
|
|
32
|
+
interface Logger {
|
|
33
|
+
/** 安装到 Lyt 应用 */
|
|
34
|
+
install: (app: any, options?: any) => void;
|
|
35
|
+
/** 调试日志 */
|
|
36
|
+
debug(...args: any[]): void;
|
|
37
|
+
/** 信息日志 */
|
|
38
|
+
info(...args: any[]): void;
|
|
39
|
+
/** 警告日志 */
|
|
40
|
+
warn(...args: any[]): void;
|
|
41
|
+
/** 错误日志 */
|
|
42
|
+
error(...args: any[]): void;
|
|
43
|
+
/** 设置日志级别 */
|
|
44
|
+
setLevel(level: LogLevel): void;
|
|
45
|
+
/** 获取当前日志级别 */
|
|
46
|
+
getLevel(): LogLevel;
|
|
47
|
+
/** 获取所有日志记录 */
|
|
48
|
+
getLogs(): LogEntry[];
|
|
49
|
+
/** 清除日志记录 */
|
|
50
|
+
clearLogs(): void;
|
|
51
|
+
/** 销毁日志实例 */
|
|
52
|
+
destroy(): void;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* 创建日志插件实例
|
|
56
|
+
* @param options 日志配置
|
|
57
|
+
* @returns Logger 插件实例
|
|
58
|
+
*/
|
|
59
|
+
declare function createLogger(options?: LoggerOptions): Logger;
|
|
60
|
+
export { createLogger };
|
|
61
|
+
export type { Logger, LoggerOptions, LogLevel, LogEntry };
|
|
62
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAkBA,WAAW;AACX,KAAK,QA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AAI,QAAQ,CAAA;IACpB,eAAe;IACf,OAAO,IAAI,QAAQ,EAAE,CAAA;IACrB,aAAa;IACb,SAAS,IAAI,IAAI,CAAA;IACjB,aAAa;IACb,OAAO,IAAI,IAAI,CAAA;CAChB;AAyED;;;;GAIG;AACH,iBAAS,YAAY,CAAC,OAAO,CAAC,EAAE,aAAa,GAAG,MAAM,CAgNrD;AAED,OAAO,EAAE,YAAY,EAAE,CAAA;AACvB,YAAY,EAAE,MAAM,EAAE,aAAa,EAAE,QAAQ,EAAE,QAAQ,EAAE,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lytjs/plugin-logger",
|
|
3
|
-
"version": "4.0
|
|
3
|
+
"version": "4.2.0",
|
|
4
4
|
"description": "Lyt.js 日志插件 - 提供分级日志记录、日志过滤和持久化存储功能",
|
|
5
|
-
"main": "./
|
|
6
|
-
"module": "./
|
|
5
|
+
"main": "./dist/index.cjs",
|
|
6
|
+
"module": "./dist/index.mjs",
|
|
7
|
+
"types": "./dist/types/index.d.ts",
|
|
7
8
|
"exports": {
|
|
8
9
|
".": {
|
|
9
|
-
"
|
|
10
|
-
"
|
|
11
|
-
"
|
|
10
|
+
"types": "./dist/types/index.d.ts",
|
|
11
|
+
"import": "./dist/index.mjs",
|
|
12
|
+
"require": "./dist/index.cjs",
|
|
13
|
+
"default": "./dist/index.mjs"
|
|
12
14
|
}
|
|
13
15
|
},
|
|
14
16
|
"sideEffects": false,
|