zario 0.3.5 → 0.4.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/README.md +102 -359
- package/dist/cjs/aggregation/LogAggregator.js +60 -31
- package/dist/cjs/core/Formatter.js +3 -4
- package/dist/cjs/core/Logger.js +41 -24
- package/dist/cjs/filters/Filter.js +52 -18
- package/dist/cjs/filters/index.js +0 -1
- package/dist/cjs/index.js +6 -1
- package/dist/cjs/transports/CircuitBreakerTransport.js +171 -0
- package/dist/cjs/transports/DeadLetterQueue.js +129 -0
- package/dist/cjs/transports/FileTransport.js +78 -7
- package/dist/cjs/transports/HttpTransport.js +15 -3
- package/dist/cjs/transports/RetryTransport.js +199 -0
- package/dist/cjs/transports/index.js +3 -0
- package/dist/cjs/types/TypeInterfaces.js +2 -0
- package/dist/cjs/utils/index.js +78 -0
- package/dist/esm/aggregation/LogAggregator.d.ts +8 -29
- package/dist/esm/aggregation/LogAggregator.js +60 -31
- package/dist/esm/core/Formatter.js +1 -2
- package/dist/esm/core/Logger.d.ts +13 -3
- package/dist/esm/core/Logger.js +40 -23
- package/dist/esm/filters/Filter.d.ts +24 -22
- package/dist/esm/filters/Filter.js +47 -17
- package/dist/esm/filters/index.d.ts +0 -1
- package/dist/esm/filters/index.js +0 -1
- package/dist/esm/index.d.ts +3 -2
- package/dist/esm/index.js +6 -3
- package/dist/esm/transports/CircuitBreakerTransport.d.ts +43 -0
- package/dist/esm/transports/CircuitBreakerTransport.js +167 -0
- package/dist/esm/transports/DeadLetterQueue.d.ts +34 -0
- package/dist/esm/transports/DeadLetterQueue.js +92 -0
- package/dist/esm/transports/FileTransport.d.ts +4 -0
- package/dist/esm/transports/FileTransport.js +78 -7
- package/dist/esm/transports/HttpTransport.d.ts +2 -0
- package/dist/esm/transports/HttpTransport.js +15 -3
- package/dist/esm/transports/RetryTransport.d.ts +67 -0
- package/dist/esm/transports/RetryTransport.js +195 -0
- package/dist/esm/transports/Transport.d.ts +1 -0
- package/dist/esm/transports/index.d.ts +3 -0
- package/dist/esm/transports/index.js +3 -0
- package/dist/esm/types/TypeInterfaces.d.ts +7 -0
- package/dist/esm/types/TypeInterfaces.js +1 -0
- package/dist/esm/utils/index.d.ts +15 -0
- package/dist/esm/utils/index.js +72 -0
- package/package.json +87 -71
- package/dist/cjs/filters/SpecificFilters.js +0 -71
- package/dist/cjs/utils/ColorUtil.js +0 -42
- package/dist/cjs/utils/TimeUtil.js +0 -26
- package/dist/cjs/utils/Timerutil.js +0 -22
- package/dist/esm/filters/SpecificFilters.d.ts +0 -41
- package/dist/esm/filters/SpecificFilters.js +0 -64
- package/dist/esm/utils/ColorUtil.d.ts +0 -4
- package/dist/esm/utils/ColorUtil.js +0 -38
- package/dist/esm/utils/TimeUtil.d.ts +0 -3
- package/dist/esm/utils/TimeUtil.js +0 -22
- package/dist/esm/utils/Timerutil.d.ts +0 -8
- package/dist/esm/utils/Timerutil.js +0 -18
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
export class ColorUtil {
|
|
2
|
+
static colorize(text, color) {
|
|
3
|
+
const supportsColor = process.env.FORCE_COLOR !== "0" &&
|
|
4
|
+
(process.stdout.isTTY || process.env.FORCE_COLOR === "1");
|
|
5
|
+
if (!supportsColor) {
|
|
6
|
+
return text;
|
|
7
|
+
}
|
|
8
|
+
const colorCode = ColorUtil.ANSI_COLORS[color] || ColorUtil.ANSI_COLORS.reset;
|
|
9
|
+
return `${colorCode}${text}${ColorUtil.ANSI_COLORS.reset}`;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
ColorUtil.ANSI_COLORS = {
|
|
13
|
+
black: "\x1b[30m",
|
|
14
|
+
red: "\x1b[31m",
|
|
15
|
+
green: "\x1b[32m",
|
|
16
|
+
yellow: "\x1b[33m",
|
|
17
|
+
blue: "\x1b[34m",
|
|
18
|
+
magenta: "\x1b[35m",
|
|
19
|
+
cyan: "\x1b[36m",
|
|
20
|
+
white: "\x1b[37m",
|
|
21
|
+
brightRed: "\x1b[91m",
|
|
22
|
+
brightGreen: "\x1b[92m",
|
|
23
|
+
brightYellow: "\x1b[93m",
|
|
24
|
+
brightBlue: "\x1b[94m",
|
|
25
|
+
brightMagenta: "\x1b[95m",
|
|
26
|
+
brightCyan: "\x1b[96m",
|
|
27
|
+
brightWhite: "\x1b[97m",
|
|
28
|
+
info: "\x1b[32m",
|
|
29
|
+
warn: "\x1b[33m",
|
|
30
|
+
error: "\x1b[31m",
|
|
31
|
+
debug: "\x1b[36m",
|
|
32
|
+
boring: "\x1b[37m",
|
|
33
|
+
reset: "\x1b[0m",
|
|
34
|
+
};
|
|
35
|
+
export class TimeUtil {
|
|
36
|
+
static format(date, format) {
|
|
37
|
+
if (format === "ISO")
|
|
38
|
+
return date.toISOString();
|
|
39
|
+
if (format === "UTC")
|
|
40
|
+
return date.toUTCString();
|
|
41
|
+
if (format === "LOCAL")
|
|
42
|
+
return date.toLocaleString();
|
|
43
|
+
const pad = (n, width = 2) => n.toString().padStart(width, "0");
|
|
44
|
+
const tokens = {
|
|
45
|
+
YYYY: pad(date.getFullYear(), 4),
|
|
46
|
+
MM: pad(date.getMonth() + 1),
|
|
47
|
+
DD: pad(date.getDate()),
|
|
48
|
+
HH: pad(date.getHours()),
|
|
49
|
+
mm: pad(date.getMinutes()),
|
|
50
|
+
ss: pad(date.getSeconds()),
|
|
51
|
+
SSS: pad(date.getMilliseconds(), 3),
|
|
52
|
+
};
|
|
53
|
+
return format.replace(/YYYY|MM|DD|HH|mm|ss|SSS/g, (match) => tokens[match] || match);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
export class Timer {
|
|
57
|
+
constructor(name, logFn) {
|
|
58
|
+
this.hasEnded = false;
|
|
59
|
+
this.name = name;
|
|
60
|
+
this.logFn = logFn;
|
|
61
|
+
this.startTime = Date.now();
|
|
62
|
+
}
|
|
63
|
+
end() {
|
|
64
|
+
if (this.hasEnded) {
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
const endTime = Date.now();
|
|
68
|
+
const duration = endTime - this.startTime;
|
|
69
|
+
this.logFn(`${this.name} took ${duration}ms`);
|
|
70
|
+
this.hasEnded = true;
|
|
71
|
+
}
|
|
72
|
+
}
|
package/package.json
CHANGED
|
@@ -1,71 +1,87 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "zario",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "
|
|
5
|
-
"main": "./dist/cjs/index.js",
|
|
6
|
-
"module": "./dist/esm/index.js",
|
|
7
|
-
"types": "./dist/esm/index.d.ts",
|
|
8
|
-
"exports": {
|
|
9
|
-
".": {
|
|
10
|
-
"types": "./dist/esm/index.d.ts",
|
|
11
|
-
"import": "./dist/esm/index.js",
|
|
12
|
-
"require": "./dist/cjs/index.js"
|
|
13
|
-
},
|
|
14
|
-
"./core/*": {
|
|
15
|
-
"types": "./dist/esm/core/*.d.ts",
|
|
16
|
-
"import": "./dist/esm/core/*.js",
|
|
17
|
-
"require": "./dist/cjs/core/*.js"
|
|
18
|
-
},
|
|
19
|
-
"./transports/*": {
|
|
20
|
-
"types": "./dist/esm/transports/*.d.ts",
|
|
21
|
-
"import": "./dist/esm/transports/*.js",
|
|
22
|
-
"require": "./dist/cjs/transports/*.js"
|
|
23
|
-
}
|
|
24
|
-
},
|
|
25
|
-
"scripts": {
|
|
26
|
-
"build": "node -e \"require('fs').rmSync('dist', {recursive:true, force:true})\" && tsc -p tsconfig.json && tsc -p tsconfig.cjs.json && node -e \"require('fs').writeFileSync('dist/cjs/package.json', '{\\\"type\\\":\\\"commonjs\\\"}')\"",
|
|
27
|
-
"dev": "tsc --watch",
|
|
28
|
-
"test": "jest",
|
|
29
|
-
"lint": "eslint .",
|
|
30
|
-
"prepublishOnly": "npm run build
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
"
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
"
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
"
|
|
42
|
-
"
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
"
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
"
|
|
54
|
-
"
|
|
55
|
-
"
|
|
56
|
-
"
|
|
57
|
-
"
|
|
58
|
-
"
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
"
|
|
66
|
-
},
|
|
67
|
-
"
|
|
68
|
-
|
|
69
|
-
"
|
|
70
|
-
|
|
71
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "zario",
|
|
3
|
+
"version": "0.4.0",
|
|
4
|
+
"description": "Fast, TypeScript-Native logging library for modern TypeScript applications.",
|
|
5
|
+
"main": "./dist/cjs/index.js",
|
|
6
|
+
"module": "./dist/esm/index.js",
|
|
7
|
+
"types": "./dist/esm/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/esm/index.d.ts",
|
|
11
|
+
"import": "./dist/esm/index.js",
|
|
12
|
+
"require": "./dist/cjs/index.js"
|
|
13
|
+
},
|
|
14
|
+
"./core/*": {
|
|
15
|
+
"types": "./dist/esm/core/*.d.ts",
|
|
16
|
+
"import": "./dist/esm/core/*.js",
|
|
17
|
+
"require": "./dist/cjs/core/*.js"
|
|
18
|
+
},
|
|
19
|
+
"./transports/*": {
|
|
20
|
+
"types": "./dist/esm/transports/*.d.ts",
|
|
21
|
+
"import": "./dist/esm/transports/*.js",
|
|
22
|
+
"require": "./dist/cjs/transports/*.js"
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
"scripts": {
|
|
26
|
+
"build": "node -e \"require('fs').rmSync('dist', {recursive:true, force:true})\" && tsc -p tsconfig.json && tsc -p tsconfig.cjs.json && node -e \"require('fs').writeFileSync('dist/cjs/package.json', '{\\\"type\\\":\\\"commonjs\\\"}')\"",
|
|
27
|
+
"dev": "tsc --watch",
|
|
28
|
+
"test": "jest",
|
|
29
|
+
"lint": "eslint .",
|
|
30
|
+
"prepublishOnly": "npm run build"
|
|
31
|
+
},
|
|
32
|
+
"repository": {
|
|
33
|
+
"type": "git",
|
|
34
|
+
"url": "git+https://github.com/Dev-Dami/zario.git"
|
|
35
|
+
},
|
|
36
|
+
"funding": {
|
|
37
|
+
"type": "github",
|
|
38
|
+
"url": "https://github.com/sponsors/Dev-Dami"
|
|
39
|
+
},
|
|
40
|
+
"keywords": [
|
|
41
|
+
"logging",
|
|
42
|
+
"logger",
|
|
43
|
+
"console",
|
|
44
|
+
"terminal",
|
|
45
|
+
"typescript",
|
|
46
|
+
"nodejs",
|
|
47
|
+
"structured-logging",
|
|
48
|
+
"json",
|
|
49
|
+
"circuit-breaker",
|
|
50
|
+
"retry",
|
|
51
|
+
"dead-letter-queue",
|
|
52
|
+
"async-logging",
|
|
53
|
+
"enterprise",
|
|
54
|
+
"resilience",
|
|
55
|
+
"performance",
|
|
56
|
+
"microservices",
|
|
57
|
+
"error-handling",
|
|
58
|
+
"zero-dependencies"
|
|
59
|
+
],
|
|
60
|
+
"author": "Dev-dami",
|
|
61
|
+
"license": "MIT",
|
|
62
|
+
"sideEffects": false,
|
|
63
|
+
"type": "module",
|
|
64
|
+
"bugs": {
|
|
65
|
+
"url": "https://github.com/Dev-Dami/zario/issues"
|
|
66
|
+
},
|
|
67
|
+
"homepage": "https://github.com/Dev-Dami/zario#readme",
|
|
68
|
+
"devDependencies": {
|
|
69
|
+
"@eslint/js": "^9.39.1",
|
|
70
|
+
"@types/jest": "^30.0.0",
|
|
71
|
+
"@types/node": "^24.10.1",
|
|
72
|
+
"@typescript-eslint/eslint-plugin": "^8.46.4",
|
|
73
|
+
"@typescript-eslint/parser": "^8.46.4",
|
|
74
|
+
"esbuild": "^0.27.0",
|
|
75
|
+
"eslint": "^9.39.1",
|
|
76
|
+
"eslint-plugin-import": "^2.32.0",
|
|
77
|
+
"globals": "^16.5.0",
|
|
78
|
+
"jest": "^30.2.0",
|
|
79
|
+
"ts-jest": "^29.4.5",
|
|
80
|
+
"typescript": "^5.9.3",
|
|
81
|
+
"typescript-eslint": "^8.49.0"
|
|
82
|
+
},
|
|
83
|
+
"files": [
|
|
84
|
+
"dist/**/*",
|
|
85
|
+
"README.md"
|
|
86
|
+
]
|
|
87
|
+
}
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.FieldFilter = exports.MetadataFilter = exports.PrefixFilter = exports.LevelFilter = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* A filter that allows logs based on their log level
|
|
6
|
-
*/
|
|
7
|
-
class LevelFilter {
|
|
8
|
-
constructor(allowedLevels) {
|
|
9
|
-
this.allowedLevels = new Set(allowedLevels);
|
|
10
|
-
}
|
|
11
|
-
shouldEmit(logData) {
|
|
12
|
-
return this.allowedLevels.has(logData.level);
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
exports.LevelFilter = LevelFilter;
|
|
16
|
-
/**
|
|
17
|
-
* A filter that allows logs based on their prefix/namespace
|
|
18
|
-
*/
|
|
19
|
-
class PrefixFilter {
|
|
20
|
-
constructor(allowedPrefixes) {
|
|
21
|
-
this.allowedPrefixes = new Set(allowedPrefixes);
|
|
22
|
-
}
|
|
23
|
-
shouldEmit(logData) {
|
|
24
|
-
if (!logData.prefix) {
|
|
25
|
-
// If no prefix exists, only allow if empty string is in allowed prefixes
|
|
26
|
-
return this.allowedPrefixes.has('');
|
|
27
|
-
}
|
|
28
|
-
return this.allowedPrefixes.has(logData.prefix);
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
exports.PrefixFilter = PrefixFilter;
|
|
32
|
-
/**
|
|
33
|
-
* A filter that allows logs based on specific metadata fields
|
|
34
|
-
* Note: Uses strict equality (===) for comparison, which means objects and arrays
|
|
35
|
-
* will only match if they are the same reference. For deep comparison of complex
|
|
36
|
-
* values, consider implementing a custom filter.
|
|
37
|
-
*/
|
|
38
|
-
class MetadataFilter {
|
|
39
|
-
constructor(requiredMetadata) {
|
|
40
|
-
this.requiredMetadata = requiredMetadata;
|
|
41
|
-
}
|
|
42
|
-
shouldEmit(logData) {
|
|
43
|
-
if (!logData.metadata) {
|
|
44
|
-
// If no metadata exists but we require some, return false
|
|
45
|
-
return Object.keys(this.requiredMetadata).length === 0;
|
|
46
|
-
}
|
|
47
|
-
for (const [key, value] of Object.entries(this.requiredMetadata)) {
|
|
48
|
-
if (logData.metadata[key] !== value) {
|
|
49
|
-
return false;
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
return true;
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
exports.MetadataFilter = MetadataFilter;
|
|
56
|
-
/**
|
|
57
|
-
* A filter that allows logs based on a custom field in metadata
|
|
58
|
-
*/
|
|
59
|
-
class FieldFilter {
|
|
60
|
-
constructor(fieldName, expectedValue) {
|
|
61
|
-
this.fieldName = fieldName;
|
|
62
|
-
this.expectedValue = expectedValue;
|
|
63
|
-
}
|
|
64
|
-
shouldEmit(logData) {
|
|
65
|
-
if (!logData.metadata) {
|
|
66
|
-
return false;
|
|
67
|
-
}
|
|
68
|
-
return logData.metadata[this.fieldName] === this.expectedValue;
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
exports.FieldFilter = FieldFilter;
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ColorUtil = void 0;
|
|
4
|
-
class ColorUtil {
|
|
5
|
-
static colorize(text, color) {
|
|
6
|
-
const supportsColor = process.env.FORCE_COLOR !== "0" &&
|
|
7
|
-
(process.stdout.isTTY || process.env.FORCE_COLOR === "1");
|
|
8
|
-
if (!supportsColor) {
|
|
9
|
-
return text;
|
|
10
|
-
}
|
|
11
|
-
const colorCode = ColorUtil.ANSI_COLORS[color] || ColorUtil.ANSI_COLORS.reset;
|
|
12
|
-
return `${colorCode}${text}${ColorUtil.ANSI_COLORS.reset}`;
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
exports.ColorUtil = ColorUtil;
|
|
16
|
-
// ANSI color codes
|
|
17
|
-
ColorUtil.ANSI_COLORS = {
|
|
18
|
-
// Standard colors
|
|
19
|
-
black: "\x1b[30m",
|
|
20
|
-
red: "\x1b[31m",
|
|
21
|
-
green: "\x1b[32m",
|
|
22
|
-
yellow: "\x1b[33m",
|
|
23
|
-
blue: "\x1b[34m",
|
|
24
|
-
magenta: "\x1b[35m",
|
|
25
|
-
cyan: "\x1b[36m",
|
|
26
|
-
white: "\x1b[37m",
|
|
27
|
-
// Bright colors
|
|
28
|
-
brightRed: "\x1b[91m",
|
|
29
|
-
brightGreen: "\x1b[92m",
|
|
30
|
-
brightYellow: "\x1b[93m",
|
|
31
|
-
brightBlue: "\x1b[94m",
|
|
32
|
-
brightMagenta: "\x1b[95m",
|
|
33
|
-
brightCyan: "\x1b[96m",
|
|
34
|
-
brightWhite: "\x1b[97m",
|
|
35
|
-
// Default log level colors
|
|
36
|
-
info: "\x1b[32m",
|
|
37
|
-
warn: "\x1b[33m",
|
|
38
|
-
error: "\x1b[31m",
|
|
39
|
-
debug: "\x1b[36m",
|
|
40
|
-
boring: "\x1b[37m",
|
|
41
|
-
reset: "\x1b[0m",
|
|
42
|
-
};
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.TimeUtil = void 0;
|
|
4
|
-
class TimeUtil {
|
|
5
|
-
// util class for date formating
|
|
6
|
-
static format(date, format) {
|
|
7
|
-
if (format === "ISO")
|
|
8
|
-
return date.toISOString();
|
|
9
|
-
if (format === "UTC")
|
|
10
|
-
return date.toUTCString();
|
|
11
|
-
if (format === "LOCAL")
|
|
12
|
-
return date.toLocaleString();
|
|
13
|
-
const pad = (n, width = 2) => n.toString().padStart(width, "0");
|
|
14
|
-
const tokens = {
|
|
15
|
-
YYYY: pad(date.getFullYear(), 4),
|
|
16
|
-
MM: pad(date.getMonth() + 1),
|
|
17
|
-
DD: pad(date.getDate()),
|
|
18
|
-
HH: pad(date.getHours()),
|
|
19
|
-
mm: pad(date.getMinutes()),
|
|
20
|
-
ss: pad(date.getSeconds()),
|
|
21
|
-
SSS: pad(date.getMilliseconds(), 3),
|
|
22
|
-
};
|
|
23
|
-
return format.replace(/YYYY|MM|DD|HH|mm|ss|SSS/g, (match) => tokens[match] || match);
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
exports.TimeUtil = TimeUtil;
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Timer = void 0;
|
|
4
|
-
class Timer {
|
|
5
|
-
constructor(name, logFn) {
|
|
6
|
-
this.hasEnded = false;
|
|
7
|
-
this.name = name;
|
|
8
|
-
this.logFn = logFn;
|
|
9
|
-
this.startTime = Date.now();
|
|
10
|
-
}
|
|
11
|
-
end() {
|
|
12
|
-
// If already ended, do nothing (idempotent)
|
|
13
|
-
if (this.hasEnded) {
|
|
14
|
-
return;
|
|
15
|
-
}
|
|
16
|
-
const endTime = Date.now();
|
|
17
|
-
const duration = endTime - this.startTime;
|
|
18
|
-
this.logFn(`${this.name} took ${duration}ms`);
|
|
19
|
-
this.hasEnded = true;
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
exports.Timer = Timer;
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import { LogData } from '../types/index.js';
|
|
2
|
-
import { LogLevel } from '../core/LogLevel.js';
|
|
3
|
-
import { Filter } from './Filter.js';
|
|
4
|
-
/**
|
|
5
|
-
* A filter that allows logs based on their log level
|
|
6
|
-
*/
|
|
7
|
-
export declare class LevelFilter implements Filter {
|
|
8
|
-
private allowedLevels;
|
|
9
|
-
constructor(allowedLevels: LogLevel[]);
|
|
10
|
-
shouldEmit(logData: LogData): boolean;
|
|
11
|
-
}
|
|
12
|
-
/**
|
|
13
|
-
* A filter that allows logs based on their prefix/namespace
|
|
14
|
-
*/
|
|
15
|
-
export declare class PrefixFilter implements Filter {
|
|
16
|
-
private allowedPrefixes;
|
|
17
|
-
constructor(allowedPrefixes: string[]);
|
|
18
|
-
shouldEmit(logData: LogData): boolean;
|
|
19
|
-
}
|
|
20
|
-
/**
|
|
21
|
-
* A filter that allows logs based on specific metadata fields
|
|
22
|
-
* Note: Uses strict equality (===) for comparison, which means objects and arrays
|
|
23
|
-
* will only match if they are the same reference. For deep comparison of complex
|
|
24
|
-
* values, consider implementing a custom filter.
|
|
25
|
-
*/
|
|
26
|
-
export declare class MetadataFilter implements Filter {
|
|
27
|
-
private requiredMetadata;
|
|
28
|
-
constructor(requiredMetadata: {
|
|
29
|
-
[key: string]: any;
|
|
30
|
-
});
|
|
31
|
-
shouldEmit(logData: LogData): boolean;
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* A filter that allows logs based on a custom field in metadata
|
|
35
|
-
*/
|
|
36
|
-
export declare class FieldFilter implements Filter {
|
|
37
|
-
private fieldName;
|
|
38
|
-
private expectedValue;
|
|
39
|
-
constructor(fieldName: string, expectedValue: any);
|
|
40
|
-
shouldEmit(logData: LogData): boolean;
|
|
41
|
-
}
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* A filter that allows logs based on their log level
|
|
3
|
-
*/
|
|
4
|
-
export class LevelFilter {
|
|
5
|
-
constructor(allowedLevels) {
|
|
6
|
-
this.allowedLevels = new Set(allowedLevels);
|
|
7
|
-
}
|
|
8
|
-
shouldEmit(logData) {
|
|
9
|
-
return this.allowedLevels.has(logData.level);
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
/**
|
|
13
|
-
* A filter that allows logs based on their prefix/namespace
|
|
14
|
-
*/
|
|
15
|
-
export class PrefixFilter {
|
|
16
|
-
constructor(allowedPrefixes) {
|
|
17
|
-
this.allowedPrefixes = new Set(allowedPrefixes);
|
|
18
|
-
}
|
|
19
|
-
shouldEmit(logData) {
|
|
20
|
-
if (!logData.prefix) {
|
|
21
|
-
// If no prefix exists, only allow if empty string is in allowed prefixes
|
|
22
|
-
return this.allowedPrefixes.has('');
|
|
23
|
-
}
|
|
24
|
-
return this.allowedPrefixes.has(logData.prefix);
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
/**
|
|
28
|
-
* A filter that allows logs based on specific metadata fields
|
|
29
|
-
* Note: Uses strict equality (===) for comparison, which means objects and arrays
|
|
30
|
-
* will only match if they are the same reference. For deep comparison of complex
|
|
31
|
-
* values, consider implementing a custom filter.
|
|
32
|
-
*/
|
|
33
|
-
export class MetadataFilter {
|
|
34
|
-
constructor(requiredMetadata) {
|
|
35
|
-
this.requiredMetadata = requiredMetadata;
|
|
36
|
-
}
|
|
37
|
-
shouldEmit(logData) {
|
|
38
|
-
if (!logData.metadata) {
|
|
39
|
-
// If no metadata exists but we require some, return false
|
|
40
|
-
return Object.keys(this.requiredMetadata).length === 0;
|
|
41
|
-
}
|
|
42
|
-
for (const [key, value] of Object.entries(this.requiredMetadata)) {
|
|
43
|
-
if (logData.metadata[key] !== value) {
|
|
44
|
-
return false;
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
return true;
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
/**
|
|
51
|
-
* A filter that allows logs based on a custom field in metadata
|
|
52
|
-
*/
|
|
53
|
-
export class FieldFilter {
|
|
54
|
-
constructor(fieldName, expectedValue) {
|
|
55
|
-
this.fieldName = fieldName;
|
|
56
|
-
this.expectedValue = expectedValue;
|
|
57
|
-
}
|
|
58
|
-
shouldEmit(logData) {
|
|
59
|
-
if (!logData.metadata) {
|
|
60
|
-
return false;
|
|
61
|
-
}
|
|
62
|
-
return logData.metadata[this.fieldName] === this.expectedValue;
|
|
63
|
-
}
|
|
64
|
-
}
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
export class ColorUtil {
|
|
2
|
-
static colorize(text, color) {
|
|
3
|
-
const supportsColor = process.env.FORCE_COLOR !== "0" &&
|
|
4
|
-
(process.stdout.isTTY || process.env.FORCE_COLOR === "1");
|
|
5
|
-
if (!supportsColor) {
|
|
6
|
-
return text;
|
|
7
|
-
}
|
|
8
|
-
const colorCode = ColorUtil.ANSI_COLORS[color] || ColorUtil.ANSI_COLORS.reset;
|
|
9
|
-
return `${colorCode}${text}${ColorUtil.ANSI_COLORS.reset}`;
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
// ANSI color codes
|
|
13
|
-
ColorUtil.ANSI_COLORS = {
|
|
14
|
-
// Standard colors
|
|
15
|
-
black: "\x1b[30m",
|
|
16
|
-
red: "\x1b[31m",
|
|
17
|
-
green: "\x1b[32m",
|
|
18
|
-
yellow: "\x1b[33m",
|
|
19
|
-
blue: "\x1b[34m",
|
|
20
|
-
magenta: "\x1b[35m",
|
|
21
|
-
cyan: "\x1b[36m",
|
|
22
|
-
white: "\x1b[37m",
|
|
23
|
-
// Bright colors
|
|
24
|
-
brightRed: "\x1b[91m",
|
|
25
|
-
brightGreen: "\x1b[92m",
|
|
26
|
-
brightYellow: "\x1b[93m",
|
|
27
|
-
brightBlue: "\x1b[94m",
|
|
28
|
-
brightMagenta: "\x1b[95m",
|
|
29
|
-
brightCyan: "\x1b[96m",
|
|
30
|
-
brightWhite: "\x1b[97m",
|
|
31
|
-
// Default log level colors
|
|
32
|
-
info: "\x1b[32m",
|
|
33
|
-
warn: "\x1b[33m",
|
|
34
|
-
error: "\x1b[31m",
|
|
35
|
-
debug: "\x1b[36m",
|
|
36
|
-
boring: "\x1b[37m",
|
|
37
|
-
reset: "\x1b[0m",
|
|
38
|
-
};
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
export class TimeUtil {
|
|
2
|
-
// util class for date formating
|
|
3
|
-
static format(date, format) {
|
|
4
|
-
if (format === "ISO")
|
|
5
|
-
return date.toISOString();
|
|
6
|
-
if (format === "UTC")
|
|
7
|
-
return date.toUTCString();
|
|
8
|
-
if (format === "LOCAL")
|
|
9
|
-
return date.toLocaleString();
|
|
10
|
-
const pad = (n, width = 2) => n.toString().padStart(width, "0");
|
|
11
|
-
const tokens = {
|
|
12
|
-
YYYY: pad(date.getFullYear(), 4),
|
|
13
|
-
MM: pad(date.getMonth() + 1),
|
|
14
|
-
DD: pad(date.getDate()),
|
|
15
|
-
HH: pad(date.getHours()),
|
|
16
|
-
mm: pad(date.getMinutes()),
|
|
17
|
-
ss: pad(date.getSeconds()),
|
|
18
|
-
SSS: pad(date.getMilliseconds(), 3),
|
|
19
|
-
};
|
|
20
|
-
return format.replace(/YYYY|MM|DD|HH|mm|ss|SSS/g, (match) => tokens[match] || match);
|
|
21
|
-
}
|
|
22
|
-
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
export class Timer {
|
|
2
|
-
constructor(name, logFn) {
|
|
3
|
-
this.hasEnded = false;
|
|
4
|
-
this.name = name;
|
|
5
|
-
this.logFn = logFn;
|
|
6
|
-
this.startTime = Date.now();
|
|
7
|
-
}
|
|
8
|
-
end() {
|
|
9
|
-
// If already ended, do nothing (idempotent)
|
|
10
|
-
if (this.hasEnded) {
|
|
11
|
-
return;
|
|
12
|
-
}
|
|
13
|
-
const endTime = Date.now();
|
|
14
|
-
const duration = endTime - this.startTime;
|
|
15
|
-
this.logFn(`${this.name} took ${duration}ms`);
|
|
16
|
-
this.hasEnded = true;
|
|
17
|
-
}
|
|
18
|
-
}
|