@lukstei/dsh-log 0.2.2-rc.5.5 → 0.2.2-rc.5.7
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.js +50 -0
- package/package.json +10 -4
package/dist/index.js
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { appendFileSync, mkdirSync } from "node:fs";
|
|
2
|
+
import { homedir } from "node:os";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { format } from "node:util";
|
|
5
|
+
import Schema from "@deepseek-ai/schemastery";
|
|
6
|
+
// src/index.ts
|
|
7
|
+
const name = "file-log";
|
|
8
|
+
const levels = Schema.dict(Schema.number()).description("Log severity per logger name; `default` is the catch-all, -1 silences.");
|
|
9
|
+
const Config = Schema.object({ outputs: Schema.array(Schema.union([Schema.object({
|
|
10
|
+
target: Schema.const("stdout").required(),
|
|
11
|
+
levels: levels.required()
|
|
12
|
+
}), Schema.object({
|
|
13
|
+
target: Schema.const("file").required(),
|
|
14
|
+
filePath: Schema.string().required().description("Log file path; a leading `~` expands to home."),
|
|
15
|
+
levels: levels.required()
|
|
16
|
+
})])).description("Destinations; each receives the loggers its levels admit.") });
|
|
17
|
+
function formatMessage(message) {
|
|
18
|
+
const ts = new Date(message.ts).toISOString();
|
|
19
|
+
const type = String(message.type).toUpperCase().padEnd(5);
|
|
20
|
+
const text = format(...message.args);
|
|
21
|
+
return `${ts} [${type}] [${message.name}] ${text}\n`;
|
|
22
|
+
}
|
|
23
|
+
function expandHome(filePath) {
|
|
24
|
+
return filePath === "~" || filePath.startsWith("~/") ? path.join(homedir(), filePath.slice(1)) : filePath;
|
|
25
|
+
}
|
|
26
|
+
function createFileWriter(rawPath) {
|
|
27
|
+
const filePath = expandHome(rawPath);
|
|
28
|
+
let dirEnsured = false;
|
|
29
|
+
return (content) => {
|
|
30
|
+
try {
|
|
31
|
+
if (!dirEnsured) {
|
|
32
|
+
mkdirSync(path.dirname(filePath), { recursive: true });
|
|
33
|
+
dirEnsured = true;
|
|
34
|
+
}
|
|
35
|
+
appendFileSync(filePath, content, "utf8");
|
|
36
|
+
} catch {}
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
function apply(ctx, config) {
|
|
40
|
+
for (const output of config.outputs) {
|
|
41
|
+
const write = output.target === "stdout" ? (line) => process.stdout.write(line) : createFileWriter(output.filePath);
|
|
42
|
+
const exporter = {
|
|
43
|
+
colors: false,
|
|
44
|
+
levels: output.levels,
|
|
45
|
+
export: (message) => write(formatMessage(message))
|
|
46
|
+
};
|
|
47
|
+
ctx.logger.exporter(exporter);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
export { Config, apply, createFileWriter, expandHome, formatMessage, name };
|
package/package.json
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lukstei/dsh-log",
|
|
3
|
-
"version": "0.2.2-rc.5.
|
|
3
|
+
"version": "0.2.2-rc.5.7",
|
|
4
4
|
"description": "File logging exporter for DSH",
|
|
5
5
|
"type": "module",
|
|
6
|
-
"main": "./
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
7
|
"exports": {
|
|
8
|
-
".":
|
|
8
|
+
".": {
|
|
9
|
+
"types": "./src/index.ts",
|
|
10
|
+
"default": "./dist/index.js"
|
|
11
|
+
}
|
|
9
12
|
},
|
|
10
13
|
"dsh": {
|
|
11
14
|
"bundle": {
|
|
@@ -24,6 +27,7 @@
|
|
|
24
27
|
},
|
|
25
28
|
"files": [
|
|
26
29
|
"src",
|
|
30
|
+
"dist",
|
|
27
31
|
"README.md",
|
|
28
32
|
"cordis.patch.yml",
|
|
29
33
|
"!src/**/*.spec.*",
|
|
@@ -45,9 +49,11 @@
|
|
|
45
49
|
"access": "public"
|
|
46
50
|
},
|
|
47
51
|
"scripts": {
|
|
52
|
+
"build": "tsdown --config tsdown.config.ts --logLevel error",
|
|
53
|
+
"dev": "tsdown --config tsdown.config.ts --watch",
|
|
48
54
|
"check": "biome check --reporter=concise .",
|
|
49
55
|
"typecheck": "tsc --noEmit",
|
|
50
56
|
"test": "node --test --test-reporter=dot",
|
|
51
|
-
"verify": "pnpm --silent run check && pnpm --silent run typecheck && pnpm --silent run test"
|
|
57
|
+
"verify": "pnpm --silent run check && pnpm --silent run build && pnpm --silent run typecheck && pnpm --silent run test"
|
|
52
58
|
}
|
|
53
59
|
}
|