@nebulaaa/journal 1.1.3 → 1.1.5
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/journal.cjs +18 -19
- package/dist/journal.d.ts +8 -8
- package/dist/journal.min.cjs +1 -1
- package/dist/journal.min.mjs +1 -1
- package/dist/journal.mjs +18 -19
- package/dist/package.json +1 -1
- package/package.json +1 -1
package/dist/journal.cjs
CHANGED
|
@@ -17,11 +17,11 @@ const JOURNAL_LEVEL_WEIGHTS = {
|
|
|
17
17
|
};
|
|
18
18
|
/** 默认分级样式 */
|
|
19
19
|
const JOURNAL_DEFAULT_LEVEL_STYLES = {
|
|
20
|
-
debug: {
|
|
21
|
-
info: {
|
|
22
|
-
warn: {
|
|
23
|
-
error: {
|
|
24
|
-
disable: {
|
|
20
|
+
debug: { Label: '[Debug]', Color: '#8C8C8C' },
|
|
21
|
+
info: { Label: '[Info]', Color: '#0986FF' },
|
|
22
|
+
warn: { Label: '[Warn]', Color: '#E6A23C' },
|
|
23
|
+
error: { Label: '[Error]', Color: '#D93026' },
|
|
24
|
+
disable: { Label: '[Disable]', Color: '' },
|
|
25
25
|
};
|
|
26
26
|
/** 默认记录器名称 */
|
|
27
27
|
const JOURNAL_DEFAULT_LOGGER_NAME = 'journal';
|
|
@@ -48,8 +48,8 @@ const CONSOLE_METHODS = {
|
|
|
48
48
|
class JournalLogger {
|
|
49
49
|
constructor(options) {
|
|
50
50
|
var _a;
|
|
51
|
-
this.Name = options.
|
|
52
|
-
this.Level = (_a = options.
|
|
51
|
+
this.Name = options.Name;
|
|
52
|
+
this.Level = (_a = options.Level) !== null && _a !== void 0 ? _a : 'debug';
|
|
53
53
|
}
|
|
54
54
|
/** 输出 debug 级别记录 */
|
|
55
55
|
Debug(message, ...args) {
|
|
@@ -86,11 +86,11 @@ class JournalLogger {
|
|
|
86
86
|
const style = GetLevelStyle(level);
|
|
87
87
|
const text = `[${this.Name}] ${String(message)}`;
|
|
88
88
|
const method = CONSOLE_METHODS[level];
|
|
89
|
-
if (style.
|
|
90
|
-
console[method](`%c${style.
|
|
89
|
+
if (style.Color) {
|
|
90
|
+
console[method](`%c${style.Label}%c ${text}`, `color:${style.Color};font-weight:bold;`, 'color:inherit;font-weight:inherit;', ...args);
|
|
91
91
|
}
|
|
92
92
|
else {
|
|
93
|
-
console[method](`${style.
|
|
93
|
+
console[method](`${style.Label} ${text}`, ...args);
|
|
94
94
|
}
|
|
95
95
|
}
|
|
96
96
|
}
|
|
@@ -105,21 +105,20 @@ const JournalContext = {
|
|
|
105
105
|
_loggers: new Map(),
|
|
106
106
|
};
|
|
107
107
|
/**
|
|
108
|
-
*
|
|
108
|
+
* 初始化
|
|
109
109
|
* @param options 管理器配置
|
|
110
110
|
*/
|
|
111
111
|
function JournalInit(options) {
|
|
112
112
|
var _a, _b, _c;
|
|
113
113
|
if (JournalContext._instance) {
|
|
114
|
-
JournalContext._instance.Warn('[Journal] 已初始化,请勿重复调用');
|
|
115
114
|
return JournalContext._instance;
|
|
116
115
|
}
|
|
117
|
-
JournalContext._level = (_a = options === null || options === void 0 ? void 0 : options.
|
|
116
|
+
JournalContext._level = (_a = options === null || options === void 0 ? void 0 : options.Level) !== null && _a !== void 0 ? _a : 'debug';
|
|
118
117
|
JournalContext._logger = new JournalLogger({
|
|
119
|
-
|
|
120
|
-
|
|
118
|
+
Name: JOURNAL_DEFAULT_LOGGER_NAME,
|
|
119
|
+
Level: JournalContext._level,
|
|
121
120
|
});
|
|
122
|
-
const overrides = options === null || options === void 0 ? void 0 : options.
|
|
121
|
+
const overrides = options === null || options === void 0 ? void 0 : options.Levels;
|
|
123
122
|
if (overrides) {
|
|
124
123
|
for (const level of JOURNAL_LEVELS) {
|
|
125
124
|
const style = overrides[level];
|
|
@@ -128,8 +127,8 @@ function JournalInit(options) {
|
|
|
128
127
|
}
|
|
129
128
|
}
|
|
130
129
|
}
|
|
131
|
-
for (const config of (_b = options === null || options === void 0 ? void 0 : options.
|
|
132
|
-
Create(config.
|
|
130
|
+
for (const config of (_b = options === null || options === void 0 ? void 0 : options.Loggers) !== null && _b !== void 0 ? _b : []) {
|
|
131
|
+
Create(config.Name, (_c = config.Level) !== null && _c !== void 0 ? _c : 'debug');
|
|
133
132
|
}
|
|
134
133
|
JournalContext._instance = {
|
|
135
134
|
Acquire,
|
|
@@ -201,7 +200,7 @@ function Create(name, level = 'debug') {
|
|
|
201
200
|
existing.Level = level;
|
|
202
201
|
return existing;
|
|
203
202
|
}
|
|
204
|
-
const logger = new JournalLogger({ name, level });
|
|
203
|
+
const logger = new JournalLogger({ Name: name, Level: level });
|
|
205
204
|
JournalContext._loggers.set(name, logger);
|
|
206
205
|
return logger;
|
|
207
206
|
}
|
package/dist/journal.d.ts
CHANGED
|
@@ -10,27 +10,27 @@ type JournalPrintLevel = Exclude<JournalLevel, 'disable'>;
|
|
|
10
10
|
/** 分级样式:标记与颜色 */
|
|
11
11
|
interface JournalLevelStyle {
|
|
12
12
|
/** 分级标记,输出于日志头部,如 "[Debug]" */
|
|
13
|
-
|
|
13
|
+
Label: string;
|
|
14
14
|
/** 分级颜色,支持任意 CSS 颜色值;留空表示不着色 */
|
|
15
|
-
|
|
15
|
+
Color: string;
|
|
16
16
|
}
|
|
17
17
|
/** 记录器配置 */
|
|
18
18
|
interface JournalLoggerOptions {
|
|
19
19
|
/** 记录器名称,需非空且在所属管理器内唯一 */
|
|
20
|
-
|
|
20
|
+
Name: string;
|
|
21
21
|
/** 记录器分级,默认为 debug */
|
|
22
|
-
|
|
22
|
+
Level?: JournalLevel;
|
|
23
23
|
}
|
|
24
24
|
/** 日志管理器配置 */
|
|
25
25
|
interface JournalManagerOptions {
|
|
26
26
|
/** 管理器分级,默认为 debug */
|
|
27
|
-
|
|
27
|
+
Level?: JournalLevel;
|
|
28
28
|
/** 分级样式配置,覆盖对应分级的默认标记与颜色 */
|
|
29
|
-
|
|
29
|
+
Levels?: {
|
|
30
30
|
[L in JournalLevel]?: Partial<JournalLevelStyle>;
|
|
31
31
|
};
|
|
32
32
|
/** 初始记录器配置列表 */
|
|
33
|
-
|
|
33
|
+
Loggers?: JournalLoggerOptions[];
|
|
34
34
|
}
|
|
35
35
|
/** 日志记录器 */
|
|
36
36
|
interface IJournalLogger {
|
|
@@ -134,7 +134,7 @@ declare class JournalLogger implements IJournalLogger {
|
|
|
134
134
|
Log(level: JournalLevel, message: string, ...args: unknown[]): void;
|
|
135
135
|
}
|
|
136
136
|
/**
|
|
137
|
-
*
|
|
137
|
+
* 初始化
|
|
138
138
|
* @param options 管理器配置
|
|
139
139
|
*/
|
|
140
140
|
declare function JournalInit(options?: JournalManagerOptions): IJournal;
|
package/dist/journal.min.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";const e=["debug","info","warn","error","disable"],
|
|
1
|
+
"use strict";const e=["debug","info","warn","error","disable"],o={debug:0,info:1,warn:2,error:3,disable:4},n={debug:{Label:"[Debug]",Color:"#8C8C8C"},info:{Label:"[Info]",Color:"#0986FF"},warn:{Label:"[Warn]",Color:"#E6A23C"},error:{Label:"[Error]",Color:"#D93026"},disable:{Label:"[Disable]",Color:""}},r="journal",l={debug:"log",info:"info",warn:"warn",error:"error"};class t{constructor(e){var o;this.Name=e.Name,this.Level=null!==(o=e.Level)&&void 0!==o?o:"debug"}Debug(e,...o){this.Log("debug",e,...o)}Info(e,...o){this.Log("info",e,...o)}Warn(e,...o){this.Log("warn",e,...o)}Error(e,...o){this.Log("error",e,...o)}Log(e,n,...r){if("disable"===e)return;if(o[this.Level]<o[i()])return;if(o[e]<o[this.Level])return;const t=_(e),s=`[${this.Name}] ${String(n)}`,u=l[e];t.Color?console[u](`%c${t.Label}%c ${s}`,`color:${t.Color};font-weight:bold;`,"color:inherit;font-weight:inherit;",...r):console[u](`${t.Label} ${s}`,...r)}}const s={_instance:null,_level:"disable",_logger:null,_styles:Object.assign({},n),_loggers:new Map};function i(){return s._level}function u(e){s._level=e,s._logger.Level=e}function g(e,...o){f("debug",e,...o)}function a(e,...o){f("info",e,...o)}function c(e,...o){f("warn",e,...o)}function L(e,...o){f("error",e,...o)}function f(e,o,...n){s._logger.Log(e,o,...n)}function _(e){return s._styles[e]}function v(e,o){s._styles[e]=Object.assign(Object.assign({},s._styles[e]),o)}function b(e,o="debug"){const n=s._loggers.get(e);if(n)return n.Level=o,n;const r=new t({Name:e,Level:o});return s._loggers.set(e,r),r}function d(e){var o;return null!==(o=s._loggers.get(e))&&void 0!==o?o:b(e,s._level)}function E(e){return s._loggers.delete(e)}function h(){s._loggers.clear()}function C(){return[...s._loggers.values()]}exports.JOURNAL_DEFAULT_LEVEL_STYLES=n,exports.JOURNAL_DEFAULT_LOGGER_NAME=r,exports.JOURNAL_LEVELS=e,exports.JOURNAL_LEVEL_WEIGHTS=o,exports.JournalInit=function(o){var n,l,f;if(s._instance)return s._instance;s._level=null!==(n=null==o?void 0:o.Level)&&void 0!==n?n:"debug",s._logger=new t({Name:r,Level:s._level});const w=null==o?void 0:o.Levels;if(w)for(const o of e){const e=w[o];e&&(s._styles[o]=Object.assign(Object.assign({},s._styles[o]),e))}for(const e of null!==(l=null==o?void 0:o.Loggers)&&void 0!==l?l:[])b(e.Name,null!==(f=e.Level)&&void 0!==f?f:"debug");return s._instance={Acquire:d,Create:b,Remove:E,Clear:h,All:C,GetLevel:i,SetLevel:u,GetLevelStyle:_,SetLevelStyle:v,Debug:g,Info:a,Warn:c,Error:L},s._instance},exports.JournalLogger=t;
|
package/dist/journal.min.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
const e=["debug","info","warn","error","disable"],n={debug:0,info:1,warn:2,error:3,disable:4},
|
|
1
|
+
const e=["debug","info","warn","error","disable"],n={debug:0,info:1,warn:2,error:3,disable:4},o={debug:{Label:"[Debug]",Color:"#8C8C8C"},info:{Label:"[Info]",Color:"#0986FF"},warn:{Label:"[Warn]",Color:"#E6A23C"},error:{Label:"[Error]",Color:"#D93026"},disable:{Label:"[Disable]",Color:""}},r="journal",l={debug:"log",info:"info",warn:"warn",error:"error"};class t{constructor(e){var n;this.Name=e.Name,this.Level=null!==(n=e.Level)&&void 0!==n?n:"debug"}Debug(e,...n){this.Log("debug",e,...n)}Info(e,...n){this.Log("info",e,...n)}Warn(e,...n){this.Log("warn",e,...n)}Error(e,...n){this.Log("error",e,...n)}Log(e,o,...r){if("disable"===e)return;if(n[this.Level]<n[g()])return;if(n[e]<n[this.Level])return;const t=L(e),i=`[${this.Name}] ${String(o)}`,s=l[e];t.Color?console[s](`%c${t.Label}%c ${i}`,`color:${t.Color};font-weight:bold;`,"color:inherit;font-weight:inherit;",...r):console[s](`${t.Label} ${i}`,...r)}}const i={_instance:null,_level:"disable",_logger:null,_styles:Object.assign({},o),_loggers:new Map};function s(n){var o,l,s;if(i._instance)return i._instance;i._level=null!==(o=null==n?void 0:n.Level)&&void 0!==o?o:"debug",i._logger=new t({Name:r,Level:i._level});const b=null==n?void 0:n.Levels;if(b)for(const n of e){const e=b[n];e&&(i._styles[n]=Object.assign(Object.assign({},i._styles[n]),e))}for(const e of null!==(l=null==n?void 0:n.Loggers)&&void 0!==l?l:[])d(e.Name,null!==(s=e.Level)&&void 0!==s?s:"debug");return i._instance={Acquire:h,Create:d,Remove:C,Clear:w,All:y,GetLevel:g,SetLevel:u,GetLevelStyle:L,SetLevelStyle:_,Debug:a,Info:c,Warn:f,Error:v},i._instance}function g(){return i._level}function u(e){i._level=e,i._logger.Level=e}function a(e,...n){b("debug",e,...n)}function c(e,...n){b("info",e,...n)}function f(e,...n){b("warn",e,...n)}function v(e,...n){b("error",e,...n)}function b(e,n,...o){i._logger.Log(e,n,...o)}function L(e){return i._styles[e]}function _(e,n){i._styles[e]=Object.assign(Object.assign({},i._styles[e]),n)}function d(e,n="debug"){const o=i._loggers.get(e);if(o)return o.Level=n,o;const r=new t({Name:e,Level:n});return i._loggers.set(e,r),r}function h(e){var n;return null!==(n=i._loggers.get(e))&&void 0!==n?n:d(e,i._level)}function C(e){return i._loggers.delete(e)}function w(){i._loggers.clear()}function y(){return[...i._loggers.values()]}export{o as JOURNAL_DEFAULT_LEVEL_STYLES,r as JOURNAL_DEFAULT_LOGGER_NAME,e as JOURNAL_LEVELS,n as JOURNAL_LEVEL_WEIGHTS,s as JournalInit,t as JournalLogger};
|
package/dist/journal.mjs
CHANGED
|
@@ -15,11 +15,11 @@ const JOURNAL_LEVEL_WEIGHTS = {
|
|
|
15
15
|
};
|
|
16
16
|
/** 默认分级样式 */
|
|
17
17
|
const JOURNAL_DEFAULT_LEVEL_STYLES = {
|
|
18
|
-
debug: {
|
|
19
|
-
info: {
|
|
20
|
-
warn: {
|
|
21
|
-
error: {
|
|
22
|
-
disable: {
|
|
18
|
+
debug: { Label: '[Debug]', Color: '#8C8C8C' },
|
|
19
|
+
info: { Label: '[Info]', Color: '#0986FF' },
|
|
20
|
+
warn: { Label: '[Warn]', Color: '#E6A23C' },
|
|
21
|
+
error: { Label: '[Error]', Color: '#D93026' },
|
|
22
|
+
disable: { Label: '[Disable]', Color: '' },
|
|
23
23
|
};
|
|
24
24
|
/** 默认记录器名称 */
|
|
25
25
|
const JOURNAL_DEFAULT_LOGGER_NAME = 'journal';
|
|
@@ -46,8 +46,8 @@ const CONSOLE_METHODS = {
|
|
|
46
46
|
class JournalLogger {
|
|
47
47
|
constructor(options) {
|
|
48
48
|
var _a;
|
|
49
|
-
this.Name = options.
|
|
50
|
-
this.Level = (_a = options.
|
|
49
|
+
this.Name = options.Name;
|
|
50
|
+
this.Level = (_a = options.Level) !== null && _a !== void 0 ? _a : 'debug';
|
|
51
51
|
}
|
|
52
52
|
/** 输出 debug 级别记录 */
|
|
53
53
|
Debug(message, ...args) {
|
|
@@ -84,11 +84,11 @@ class JournalLogger {
|
|
|
84
84
|
const style = GetLevelStyle(level);
|
|
85
85
|
const text = `[${this.Name}] ${String(message)}`;
|
|
86
86
|
const method = CONSOLE_METHODS[level];
|
|
87
|
-
if (style.
|
|
88
|
-
console[method](`%c${style.
|
|
87
|
+
if (style.Color) {
|
|
88
|
+
console[method](`%c${style.Label}%c ${text}`, `color:${style.Color};font-weight:bold;`, 'color:inherit;font-weight:inherit;', ...args);
|
|
89
89
|
}
|
|
90
90
|
else {
|
|
91
|
-
console[method](`${style.
|
|
91
|
+
console[method](`${style.Label} ${text}`, ...args);
|
|
92
92
|
}
|
|
93
93
|
}
|
|
94
94
|
}
|
|
@@ -103,21 +103,20 @@ const JournalContext = {
|
|
|
103
103
|
_loggers: new Map(),
|
|
104
104
|
};
|
|
105
105
|
/**
|
|
106
|
-
*
|
|
106
|
+
* 初始化
|
|
107
107
|
* @param options 管理器配置
|
|
108
108
|
*/
|
|
109
109
|
function JournalInit(options) {
|
|
110
110
|
var _a, _b, _c;
|
|
111
111
|
if (JournalContext._instance) {
|
|
112
|
-
JournalContext._instance.Warn('[Journal] 已初始化,请勿重复调用');
|
|
113
112
|
return JournalContext._instance;
|
|
114
113
|
}
|
|
115
|
-
JournalContext._level = (_a = options === null || options === void 0 ? void 0 : options.
|
|
114
|
+
JournalContext._level = (_a = options === null || options === void 0 ? void 0 : options.Level) !== null && _a !== void 0 ? _a : 'debug';
|
|
116
115
|
JournalContext._logger = new JournalLogger({
|
|
117
|
-
|
|
118
|
-
|
|
116
|
+
Name: JOURNAL_DEFAULT_LOGGER_NAME,
|
|
117
|
+
Level: JournalContext._level,
|
|
119
118
|
});
|
|
120
|
-
const overrides = options === null || options === void 0 ? void 0 : options.
|
|
119
|
+
const overrides = options === null || options === void 0 ? void 0 : options.Levels;
|
|
121
120
|
if (overrides) {
|
|
122
121
|
for (const level of JOURNAL_LEVELS) {
|
|
123
122
|
const style = overrides[level];
|
|
@@ -126,8 +125,8 @@ function JournalInit(options) {
|
|
|
126
125
|
}
|
|
127
126
|
}
|
|
128
127
|
}
|
|
129
|
-
for (const config of (_b = options === null || options === void 0 ? void 0 : options.
|
|
130
|
-
Create(config.
|
|
128
|
+
for (const config of (_b = options === null || options === void 0 ? void 0 : options.Loggers) !== null && _b !== void 0 ? _b : []) {
|
|
129
|
+
Create(config.Name, (_c = config.Level) !== null && _c !== void 0 ? _c : 'debug');
|
|
131
130
|
}
|
|
132
131
|
JournalContext._instance = {
|
|
133
132
|
Acquire,
|
|
@@ -199,7 +198,7 @@ function Create(name, level = 'debug') {
|
|
|
199
198
|
existing.Level = level;
|
|
200
199
|
return existing;
|
|
201
200
|
}
|
|
202
|
-
const logger = new JournalLogger({ name, level });
|
|
201
|
+
const logger = new JournalLogger({ Name: name, Level: level });
|
|
203
202
|
JournalContext._loggers.set(name, logger);
|
|
204
203
|
return logger;
|
|
205
204
|
}
|
package/dist/package.json
CHANGED