modality-kit 0.0.0 → 0.0.2
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 +112 -1
- package/dist/types/index.d.ts +1 -0
- package/dist/types/util_logger.d.ts +28 -0
- package/package.json +4 -2
package/dist/index.js
CHANGED
|
@@ -54,8 +54,119 @@ function formatErrorResponse(errorData, operation, meta) {
|
|
|
54
54
|
}
|
|
55
55
|
return JSON.stringify(errorResponse);
|
|
56
56
|
}
|
|
57
|
+
// src/util_logger.ts
|
|
58
|
+
class ModalityLogger {
|
|
59
|
+
options;
|
|
60
|
+
logLevel;
|
|
61
|
+
constructor(options = {}, logLevel = "info") {
|
|
62
|
+
this.options = options;
|
|
63
|
+
this.logLevel = logLevel;
|
|
64
|
+
}
|
|
65
|
+
getTimestamp() {
|
|
66
|
+
if (this.options.timestampFormat === false)
|
|
67
|
+
return;
|
|
68
|
+
const now = new Date;
|
|
69
|
+
if (this.options.timestampFormat === "locale")
|
|
70
|
+
return now.toLocaleString();
|
|
71
|
+
return now.toISOString();
|
|
72
|
+
}
|
|
73
|
+
shouldLog(level) {
|
|
74
|
+
const levels = ["debug", "info", "warn", "error", "success"];
|
|
75
|
+
return levels.indexOf(level) >= levels.indexOf(this.logLevel);
|
|
76
|
+
}
|
|
77
|
+
format(level, message, context = {}, extra) {
|
|
78
|
+
const timestamp = this.getTimestamp();
|
|
79
|
+
const ctx = { ...this.options.context || {}, ...context };
|
|
80
|
+
const base = {
|
|
81
|
+
level,
|
|
82
|
+
message,
|
|
83
|
+
...timestamp ? { timestamp } : {},
|
|
84
|
+
...Object.keys(ctx).length ? { context: ctx } : {},
|
|
85
|
+
...extra ? { ...extra } : {}
|
|
86
|
+
};
|
|
87
|
+
if (this.options.json)
|
|
88
|
+
return JSON.stringify(base);
|
|
89
|
+
let prefix = "";
|
|
90
|
+
switch (level) {
|
|
91
|
+
case "debug":
|
|
92
|
+
prefix = "\uD83D\uDD0D";
|
|
93
|
+
break;
|
|
94
|
+
case "info":
|
|
95
|
+
prefix = "ℹ️";
|
|
96
|
+
break;
|
|
97
|
+
case "warn":
|
|
98
|
+
prefix = "⚠️";
|
|
99
|
+
break;
|
|
100
|
+
case "error":
|
|
101
|
+
prefix = "❌";
|
|
102
|
+
break;
|
|
103
|
+
case "success":
|
|
104
|
+
prefix = "✅";
|
|
105
|
+
break;
|
|
106
|
+
default:
|
|
107
|
+
prefix = "";
|
|
108
|
+
}
|
|
109
|
+
let out = `${prefix} ${message}`;
|
|
110
|
+
if (timestamp)
|
|
111
|
+
out = `[${timestamp}] ` + out;
|
|
112
|
+
if (Object.keys(ctx).length)
|
|
113
|
+
out += ` | context: ${JSON.stringify(ctx)}`;
|
|
114
|
+
return extra ? [out, extra] : [out];
|
|
115
|
+
}
|
|
116
|
+
withContext(context) {
|
|
117
|
+
return new ModalityLogger({ ...this.options, context: { ...this.options.context || {}, ...context } }, this.logLevel);
|
|
118
|
+
}
|
|
119
|
+
setLogLevel(level) {
|
|
120
|
+
this.logLevel = level;
|
|
121
|
+
}
|
|
122
|
+
setOptions(options) {
|
|
123
|
+
this.options = { ...this.options, ...options };
|
|
124
|
+
}
|
|
125
|
+
log(level, message, context = {}, extra) {
|
|
126
|
+
if (!this.shouldLog(level))
|
|
127
|
+
return;
|
|
128
|
+
const formatted = this.format(level, message, context, extra);
|
|
129
|
+
switch (level) {
|
|
130
|
+
case "debug":
|
|
131
|
+
this.options.json ? console.debug(formatted) : console.debug(...formatted);
|
|
132
|
+
break;
|
|
133
|
+
case "info":
|
|
134
|
+
this.options.json ? console.info(formatted) : console.info(...formatted);
|
|
135
|
+
break;
|
|
136
|
+
case "warn":
|
|
137
|
+
this.options.json ? console.warn(formatted) : console.warn(...formatted);
|
|
138
|
+
break;
|
|
139
|
+
case "error":
|
|
140
|
+
this.options.json ? console.error(formatted) : console.error(...formatted);
|
|
141
|
+
break;
|
|
142
|
+
case "success":
|
|
143
|
+
this.options.json ? console.log(formatted) : console.log(...formatted);
|
|
144
|
+
break;
|
|
145
|
+
default:
|
|
146
|
+
this.options.json ? console.log(formatted) : console.log(...formatted);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
debug(message, context, error) {
|
|
150
|
+
const extra = error ? { error: error.message, stack: error.stack } : undefined;
|
|
151
|
+
this.log("debug", message, context, extra);
|
|
152
|
+
}
|
|
153
|
+
info(message, context) {
|
|
154
|
+
this.log("info", message, context);
|
|
155
|
+
}
|
|
156
|
+
warn(message, context) {
|
|
157
|
+
this.log("warn", message, context);
|
|
158
|
+
}
|
|
159
|
+
error(message, context, error) {
|
|
160
|
+
const extra = error ? { error: error.message, stack: error.stack } : undefined;
|
|
161
|
+
this.log("error", message, context, extra);
|
|
162
|
+
}
|
|
163
|
+
success(message, context) {
|
|
164
|
+
this.log("success", message, context);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
57
167
|
export {
|
|
58
168
|
setupAITools,
|
|
59
169
|
formatSuccessResponse,
|
|
60
|
-
formatErrorResponse
|
|
170
|
+
formatErrorResponse,
|
|
171
|
+
ModalityLogger
|
|
61
172
|
};
|
package/dist/types/index.d.ts
CHANGED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Storage Logger for structured logging
|
|
3
|
+
* Provides consistent logging across storage operations with configurable levels
|
|
4
|
+
*/
|
|
5
|
+
export type LogLevel = 'debug' | 'info' | 'warn' | 'error' | 'success';
|
|
6
|
+
export interface LoggerOptions {
|
|
7
|
+
timestampFormat?: 'iso' | 'locale' | false;
|
|
8
|
+
color?: boolean;
|
|
9
|
+
json?: boolean;
|
|
10
|
+
context?: Record<string, any>;
|
|
11
|
+
}
|
|
12
|
+
export declare class ModalityLogger {
|
|
13
|
+
private options;
|
|
14
|
+
private logLevel;
|
|
15
|
+
constructor(options?: LoggerOptions, logLevel?: LogLevel);
|
|
16
|
+
private getTimestamp;
|
|
17
|
+
private shouldLog;
|
|
18
|
+
private format;
|
|
19
|
+
withContext(context: Record<string, any>): ModalityLogger;
|
|
20
|
+
setLogLevel(level: LogLevel): void;
|
|
21
|
+
setOptions(options: LoggerOptions): void;
|
|
22
|
+
log(level: LogLevel, message: string, context?: Record<string, any>, extra?: any): void;
|
|
23
|
+
debug(message: string, context?: Record<string, any>, error?: Error): void;
|
|
24
|
+
info(message: string, context?: Record<string, any>): void;
|
|
25
|
+
warn(message: string, context?: Record<string, any>): void;
|
|
26
|
+
error(message: string, context?: Record<string, any>, error?: Error): void;
|
|
27
|
+
success(message: string, context?: Record<string, any>): void;
|
|
28
|
+
}
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "0.0.
|
|
2
|
+
"version": "0.0.2",
|
|
3
3
|
"name": "modality-kit",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
@@ -19,15 +19,17 @@
|
|
|
19
19
|
},
|
|
20
20
|
"exports": {
|
|
21
21
|
"require": "./dist/index.js",
|
|
22
|
+
"import": "./dist/index.js",
|
|
22
23
|
"types": "./dist/types/index.d.ts"
|
|
23
24
|
},
|
|
24
25
|
"type": "module",
|
|
25
26
|
"main": "./dist/index.js",
|
|
26
27
|
"scripts": {
|
|
27
28
|
"update-compile-sh": "yo reshow:compile-sh",
|
|
29
|
+
"build:clean": "find ./dist -name '*.*' | xargs rm -rf",
|
|
28
30
|
"build:types": "bunx tsc -p ./",
|
|
29
31
|
"build:src": "bun build src/index.ts --outdir dist",
|
|
30
|
-
"build": "bun run build:src && bun run build:types",
|
|
32
|
+
"build": "bun run build:clean && bun run build:src && bun run build:types",
|
|
31
33
|
"test": "npm run build",
|
|
32
34
|
"prepublishOnly": "npm run test"
|
|
33
35
|
},
|