@cordisjs/logger-console 0.0.0-stage → 1.0.1
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/README.md +1 -3
- package/lib/browser.d.ts +7 -0
- package/lib/browser.js +89 -0
- package/lib/index.d.ts +12 -0
- package/lib/index.js +101 -0
- package/lib/shared.d.ts +40 -0
- package/package.json +45 -3
package/README.md
CHANGED
package/lib/browser.d.ts
ADDED
package/lib/browser.js
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
+
|
|
4
|
+
// src/shared.ts
|
|
5
|
+
import { Logger } from "cordis";
|
|
6
|
+
import { Time } from "cosmokit";
|
|
7
|
+
import z from "schemastery";
|
|
8
|
+
var ConsoleExporter = class {
|
|
9
|
+
constructor(ctx, config = {}) {
|
|
10
|
+
this.ctx = ctx;
|
|
11
|
+
Object.assign(this, this.getDefaults(), config);
|
|
12
|
+
this.timestamp = Date.now();
|
|
13
|
+
ctx.logger.exporter(this);
|
|
14
|
+
}
|
|
15
|
+
ctx;
|
|
16
|
+
static name = "logger-console";
|
|
17
|
+
static Config = z.object({
|
|
18
|
+
colors: z.union([z.const(false), z.number()]),
|
|
19
|
+
maxLength: z.number(),
|
|
20
|
+
levels: z.dict(z.number()),
|
|
21
|
+
showDiff: z.boolean().default(false),
|
|
22
|
+
showTime: z.string().default("yyyy-MM-dd hh:mm:ss "),
|
|
23
|
+
label: z.object({
|
|
24
|
+
width: z.number(),
|
|
25
|
+
margin: z.number(),
|
|
26
|
+
align: z.union(["left", "right"])
|
|
27
|
+
})
|
|
28
|
+
});
|
|
29
|
+
colors;
|
|
30
|
+
maxLength;
|
|
31
|
+
levels;
|
|
32
|
+
showDiff;
|
|
33
|
+
showTime;
|
|
34
|
+
label;
|
|
35
|
+
timestamp;
|
|
36
|
+
formatters = {};
|
|
37
|
+
getDefaults() {
|
|
38
|
+
return {
|
|
39
|
+
colors: false,
|
|
40
|
+
showTime: "yyyy-MM-dd hh:mm:ss ",
|
|
41
|
+
showDiff: false
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
export(message) {
|
|
45
|
+
console.log(this.render(message));
|
|
46
|
+
}
|
|
47
|
+
render(message) {
|
|
48
|
+
const prefix = `[${message.type[0].toUpperCase()}]`;
|
|
49
|
+
const space = " ".repeat(this.label?.margin ?? 1);
|
|
50
|
+
let indent = 3 + space.length, output = "";
|
|
51
|
+
if (this.showTime) {
|
|
52
|
+
indent += this.showTime.length;
|
|
53
|
+
output += Logger.color(this, 8, Time.template(this.showTime));
|
|
54
|
+
}
|
|
55
|
+
const code = Logger.code(message.name, this.colors);
|
|
56
|
+
const label = Logger.color(this, code, message.name, ";1");
|
|
57
|
+
const padLength = (this.label?.width ?? 0) + label.length - message.name.length;
|
|
58
|
+
if (this.label?.align === "right") {
|
|
59
|
+
output += label.padStart(padLength) + space + prefix + space;
|
|
60
|
+
indent += (this.label.width ?? 0) + space.length;
|
|
61
|
+
} else {
|
|
62
|
+
output += prefix + space + label.padEnd(padLength) + space;
|
|
63
|
+
}
|
|
64
|
+
output += Logger.format(this, message).replace(/\n/g, "\n" + " ".repeat(indent));
|
|
65
|
+
if (this.showDiff && this.timestamp) {
|
|
66
|
+
const diff = message.ts - this.timestamp;
|
|
67
|
+
output += Logger.color(this, code, " +" + Time.format(diff));
|
|
68
|
+
}
|
|
69
|
+
this.timestamp = message.ts;
|
|
70
|
+
return output;
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
// src/browser.ts
|
|
75
|
+
var ConsoleExporter2 = class extends ConsoleExporter {
|
|
76
|
+
static {
|
|
77
|
+
__name(this, "ConsoleExporter");
|
|
78
|
+
}
|
|
79
|
+
export(message) {
|
|
80
|
+
const prefix = `[${message.type[0].toUpperCase()}] ${message.name}`;
|
|
81
|
+
const method = message.type === "error" ? "error" : message.type === "warn" ? "warn" : "log";
|
|
82
|
+
console[method](prefix, ...message.args);
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
var browser_default = ConsoleExporter2;
|
|
86
|
+
export {
|
|
87
|
+
ConsoleExporter2 as ConsoleExporter,
|
|
88
|
+
browser_default as default
|
|
89
|
+
};
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Formatter } from 'cordis';
|
|
2
|
+
import { ConsoleExporter as Base } from './shared.js';
|
|
3
|
+
export * from './shared.js';
|
|
4
|
+
export declare class ConsoleExporter extends Base {
|
|
5
|
+
formatters: Record<string, Formatter>;
|
|
6
|
+
getDefaults(): {
|
|
7
|
+
colors: false | 0 | 1 | 2 | 3;
|
|
8
|
+
showTime: string;
|
|
9
|
+
showDiff: boolean;
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
export default ConsoleExporter;
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
+
|
|
4
|
+
// src/index.ts
|
|
5
|
+
import { inspect } from "node:util";
|
|
6
|
+
import supportsColor from "supports-color";
|
|
7
|
+
|
|
8
|
+
// src/shared.ts
|
|
9
|
+
import { Logger } from "cordis";
|
|
10
|
+
import { Time } from "cosmokit";
|
|
11
|
+
import z from "schemastery";
|
|
12
|
+
var ConsoleExporter = class {
|
|
13
|
+
constructor(ctx, config = {}) {
|
|
14
|
+
this.ctx = ctx;
|
|
15
|
+
Object.assign(this, this.getDefaults(), config);
|
|
16
|
+
this.timestamp = Date.now();
|
|
17
|
+
ctx.logger.exporter(this);
|
|
18
|
+
}
|
|
19
|
+
ctx;
|
|
20
|
+
static name = "logger-console";
|
|
21
|
+
static Config = z.object({
|
|
22
|
+
colors: z.union([z.const(false), z.number()]),
|
|
23
|
+
maxLength: z.number(),
|
|
24
|
+
levels: z.dict(z.number()),
|
|
25
|
+
showDiff: z.boolean().default(false),
|
|
26
|
+
showTime: z.string().default("yyyy-MM-dd hh:mm:ss "),
|
|
27
|
+
label: z.object({
|
|
28
|
+
width: z.number(),
|
|
29
|
+
margin: z.number(),
|
|
30
|
+
align: z.union(["left", "right"])
|
|
31
|
+
})
|
|
32
|
+
});
|
|
33
|
+
colors;
|
|
34
|
+
maxLength;
|
|
35
|
+
levels;
|
|
36
|
+
showDiff;
|
|
37
|
+
showTime;
|
|
38
|
+
label;
|
|
39
|
+
timestamp;
|
|
40
|
+
formatters = {};
|
|
41
|
+
getDefaults() {
|
|
42
|
+
return {
|
|
43
|
+
colors: false,
|
|
44
|
+
showTime: "yyyy-MM-dd hh:mm:ss ",
|
|
45
|
+
showDiff: false
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
export(message) {
|
|
49
|
+
console.log(this.render(message));
|
|
50
|
+
}
|
|
51
|
+
render(message) {
|
|
52
|
+
const prefix = `[${message.type[0].toUpperCase()}]`;
|
|
53
|
+
const space = " ".repeat(this.label?.margin ?? 1);
|
|
54
|
+
let indent = 3 + space.length, output = "";
|
|
55
|
+
if (this.showTime) {
|
|
56
|
+
indent += this.showTime.length;
|
|
57
|
+
output += Logger.color(this, 8, Time.template(this.showTime));
|
|
58
|
+
}
|
|
59
|
+
const code = Logger.code(message.name, this.colors);
|
|
60
|
+
const label = Logger.color(this, code, message.name, ";1");
|
|
61
|
+
const padLength = (this.label?.width ?? 0) + label.length - message.name.length;
|
|
62
|
+
if (this.label?.align === "right") {
|
|
63
|
+
output += label.padStart(padLength) + space + prefix + space;
|
|
64
|
+
indent += (this.label.width ?? 0) + space.length;
|
|
65
|
+
} else {
|
|
66
|
+
output += prefix + space + label.padEnd(padLength) + space;
|
|
67
|
+
}
|
|
68
|
+
output += Logger.format(this, message).replace(/\n/g, "\n" + " ".repeat(indent));
|
|
69
|
+
if (this.showDiff && this.timestamp) {
|
|
70
|
+
const diff = message.ts - this.timestamp;
|
|
71
|
+
output += Logger.color(this, code, " +" + Time.format(diff));
|
|
72
|
+
}
|
|
73
|
+
this.timestamp = message.ts;
|
|
74
|
+
return output;
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
// src/index.ts
|
|
79
|
+
var inspectFormatter = /* @__PURE__ */ __name((value, target) => {
|
|
80
|
+
return inspect(value, { colors: !!target.colors, depth: Infinity, compact: true, breakLength: Infinity });
|
|
81
|
+
}, "inspectFormatter");
|
|
82
|
+
var ConsoleExporter2 = class extends ConsoleExporter {
|
|
83
|
+
static {
|
|
84
|
+
__name(this, "ConsoleExporter");
|
|
85
|
+
}
|
|
86
|
+
formatters = {
|
|
87
|
+
o: inspectFormatter,
|
|
88
|
+
O: inspectFormatter
|
|
89
|
+
};
|
|
90
|
+
getDefaults() {
|
|
91
|
+
return {
|
|
92
|
+
...super.getDefaults(),
|
|
93
|
+
colors: supportsColor.stdout ? supportsColor.stdout.level : 0
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
var index_default = ConsoleExporter2;
|
|
98
|
+
export {
|
|
99
|
+
ConsoleExporter2 as ConsoleExporter,
|
|
100
|
+
index_default as default
|
|
101
|
+
};
|
package/lib/shared.d.ts
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { Context, Exporter, Formatter, Message } from 'cordis';
|
|
2
|
+
import z from 'schemastery';
|
|
3
|
+
export type ColorSupportLevel = 0 | 1 | 2 | 3;
|
|
4
|
+
export interface LabelStyle {
|
|
5
|
+
width?: number;
|
|
6
|
+
margin?: number;
|
|
7
|
+
align?: 'left' | 'right';
|
|
8
|
+
}
|
|
9
|
+
export declare namespace ConsoleExporter {
|
|
10
|
+
interface Config {
|
|
11
|
+
colors?: false | ColorSupportLevel;
|
|
12
|
+
maxLength?: number;
|
|
13
|
+
levels?: Record<string, number>;
|
|
14
|
+
showDiff?: boolean;
|
|
15
|
+
showTime?: string;
|
|
16
|
+
label?: LabelStyle;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
export declare class ConsoleExporter implements Exporter {
|
|
20
|
+
ctx: Context;
|
|
21
|
+
static readonly name = "logger-console";
|
|
22
|
+
static readonly Config: z<ConsoleExporter.Config>;
|
|
23
|
+
colors: false | ColorSupportLevel;
|
|
24
|
+
maxLength?: number;
|
|
25
|
+
levels?: Record<string, number>;
|
|
26
|
+
showDiff: boolean;
|
|
27
|
+
showTime: string;
|
|
28
|
+
label?: LabelStyle;
|
|
29
|
+
timestamp: number;
|
|
30
|
+
formatters: Record<string, Formatter>;
|
|
31
|
+
constructor(ctx: Context, config?: ConsoleExporter.Config);
|
|
32
|
+
getDefaults(): {
|
|
33
|
+
colors: false | ColorSupportLevel;
|
|
34
|
+
showTime: string;
|
|
35
|
+
showDiff: boolean;
|
|
36
|
+
};
|
|
37
|
+
export(message: Message): void;
|
|
38
|
+
render(message: Message): string;
|
|
39
|
+
}
|
|
40
|
+
export default ConsoleExporter;
|
package/package.json
CHANGED
|
@@ -1,6 +1,48 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cordisjs/logger-console",
|
|
3
|
-
"
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"description": "Console logger exporter for Cordis",
|
|
4
|
+
"version": "1.0.1",
|
|
5
|
+
"sideEffects": false,
|
|
6
|
+
"type": "module",
|
|
7
|
+
"main": "lib/index.js",
|
|
8
|
+
"types": "lib/shared.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./lib/shared.d.ts",
|
|
12
|
+
"node": "./lib/index.js",
|
|
13
|
+
"default": "./lib/browser.js"
|
|
14
|
+
},
|
|
15
|
+
"./package.json": "./package.json"
|
|
16
|
+
},
|
|
17
|
+
"files": [
|
|
18
|
+
"lib"
|
|
19
|
+
],
|
|
20
|
+
"author": "Shigma <shigma10826@gmail.com>",
|
|
21
|
+
"license": "MIT",
|
|
22
|
+
"repository": {
|
|
23
|
+
"type": "git",
|
|
24
|
+
"url": "git+https://github.com/cordiverse/cordis.git",
|
|
25
|
+
"directory": "packages/logger-console"
|
|
26
|
+
},
|
|
27
|
+
"bugs": {
|
|
28
|
+
"url": "https://github.com/cordiverse/cordis/issues"
|
|
29
|
+
},
|
|
30
|
+
"homepage": "https://github.com/cordiverse/cordis",
|
|
31
|
+
"keywords": [
|
|
32
|
+
"cordis",
|
|
33
|
+
"logger",
|
|
34
|
+
"console",
|
|
35
|
+
"component"
|
|
36
|
+
],
|
|
37
|
+
"devDependencies": {
|
|
38
|
+
"cordis": "^4.0.0-rc.13"
|
|
39
|
+
},
|
|
40
|
+
"peerDependencies": {
|
|
41
|
+
"cordis": "^4.0.0-rc.13"
|
|
42
|
+
},
|
|
43
|
+
"dependencies": {
|
|
44
|
+
"cosmokit": "^1.8.1",
|
|
45
|
+
"schemastery": "^3.18.0",
|
|
46
|
+
"supports-color": "^9.4.0"
|
|
47
|
+
}
|
|
6
48
|
}
|