modality-kit 0.0.2 → 0.0.4
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 +57 -50
- package/dist/types/index.d.ts +1 -1
- package/dist/types/util_logger.d.ts +14 -15
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -56,12 +56,23 @@ function formatErrorResponse(errorData, operation, meta) {
|
|
|
56
56
|
}
|
|
57
57
|
// src/util_logger.ts
|
|
58
58
|
class ModalityLogger {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
59
|
+
static instance;
|
|
60
|
+
options = {};
|
|
61
|
+
logLevel = "info";
|
|
62
|
+
constructor(logOption, logLevel = "info") {
|
|
63
|
+
if (typeof logOption === "string") {
|
|
64
|
+
this.options.name = logOption;
|
|
65
|
+
} else {
|
|
66
|
+
this.options = { ...this.options, ...logOption };
|
|
67
|
+
}
|
|
63
68
|
this.logLevel = logLevel;
|
|
64
69
|
}
|
|
70
|
+
static getInstance(logOption, logLevel) {
|
|
71
|
+
if (!ModalityLogger.instance) {
|
|
72
|
+
ModalityLogger.instance = new ModalityLogger(logOption, logLevel);
|
|
73
|
+
}
|
|
74
|
+
return ModalityLogger.instance;
|
|
75
|
+
}
|
|
65
76
|
getTimestamp() {
|
|
66
77
|
if (this.options.timestampFormat === false)
|
|
67
78
|
return;
|
|
@@ -74,18 +85,11 @@ class ModalityLogger {
|
|
|
74
85
|
const levels = ["debug", "info", "warn", "error", "success"];
|
|
75
86
|
return levels.indexOf(level) >= levels.indexOf(this.logLevel);
|
|
76
87
|
}
|
|
77
|
-
|
|
88
|
+
setLogLevel(level) {
|
|
89
|
+
this.logLevel = level;
|
|
90
|
+
}
|
|
91
|
+
format(level, payload, categroy) {
|
|
78
92
|
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
93
|
let prefix = "";
|
|
90
94
|
switch (level) {
|
|
91
95
|
case "debug":
|
|
@@ -106,66 +110,69 @@ class ModalityLogger {
|
|
|
106
110
|
default:
|
|
107
111
|
prefix = "";
|
|
108
112
|
}
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
if (
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
setLogLevel(level) {
|
|
120
|
-
this.logLevel = level;
|
|
121
|
-
}
|
|
122
|
-
setOptions(options) {
|
|
123
|
-
this.options = { ...this.options, ...options };
|
|
113
|
+
if (timestamp) {
|
|
114
|
+
prefix += ` [${timestamp}]`;
|
|
115
|
+
}
|
|
116
|
+
if (this.options.name) {
|
|
117
|
+
prefix += ` [${this.options.name}]`;
|
|
118
|
+
}
|
|
119
|
+
if (categroy) {
|
|
120
|
+
prefix += ` [${categroy}]`;
|
|
121
|
+
}
|
|
122
|
+
return [prefix, payload];
|
|
124
123
|
}
|
|
125
|
-
log(level,
|
|
124
|
+
log(level, payload, categroy) {
|
|
126
125
|
if (!this.shouldLog(level))
|
|
127
126
|
return;
|
|
128
|
-
const formatted = this.format(level,
|
|
127
|
+
const formatted = this.format(level, payload, categroy);
|
|
129
128
|
switch (level) {
|
|
130
129
|
case "debug":
|
|
131
|
-
|
|
130
|
+
console.debug(formatted);
|
|
132
131
|
break;
|
|
133
132
|
case "info":
|
|
134
|
-
|
|
133
|
+
console.info(formatted);
|
|
135
134
|
break;
|
|
136
135
|
case "warn":
|
|
137
|
-
|
|
136
|
+
console.warn(formatted);
|
|
138
137
|
break;
|
|
139
138
|
case "error":
|
|
140
|
-
|
|
139
|
+
console.error(formatted);
|
|
141
140
|
break;
|
|
142
141
|
case "success":
|
|
143
|
-
|
|
142
|
+
console.log(formatted);
|
|
144
143
|
break;
|
|
145
144
|
default:
|
|
146
|
-
|
|
145
|
+
console.log(formatted);
|
|
146
|
+
break;
|
|
147
147
|
}
|
|
148
148
|
}
|
|
149
|
-
debug(message,
|
|
150
|
-
|
|
151
|
-
this.log("debug", message, context, extra);
|
|
149
|
+
debug(message, error) {
|
|
150
|
+
this.log("debug", { message, error });
|
|
152
151
|
}
|
|
153
|
-
info(message,
|
|
154
|
-
this.log("info", message,
|
|
152
|
+
info(message, data) {
|
|
153
|
+
this.log("info", { message, data });
|
|
155
154
|
}
|
|
156
|
-
warn(message,
|
|
157
|
-
this.log("warn", message,
|
|
155
|
+
warn(message, resolution) {
|
|
156
|
+
this.log("warn", { message, resolution });
|
|
158
157
|
}
|
|
159
|
-
error(message,
|
|
160
|
-
const
|
|
161
|
-
|
|
158
|
+
error(message, error) {
|
|
159
|
+
const data = { message };
|
|
160
|
+
if (error) {
|
|
161
|
+
data.error = {
|
|
162
|
+
message: error.message,
|
|
163
|
+
stack: error.stack
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
this.log("error", data);
|
|
162
167
|
}
|
|
163
|
-
success(message,
|
|
164
|
-
this.log("success", message,
|
|
168
|
+
success(message, data) {
|
|
169
|
+
this.log("success", { message, data });
|
|
165
170
|
}
|
|
166
171
|
}
|
|
172
|
+
var loggerInstance = ModalityLogger.getInstance.bind(ModalityLogger);
|
|
167
173
|
export {
|
|
168
174
|
setupAITools,
|
|
175
|
+
loggerInstance,
|
|
169
176
|
formatSuccessResponse,
|
|
170
177
|
formatErrorResponse,
|
|
171
178
|
ModalityLogger
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export { setupAITools } from "./util_mcp_tools_converter";
|
|
2
2
|
export type { AITools, AITool } from "./schemas/schemas_tool_config";
|
|
3
3
|
export { formatErrorResponse, formatSuccessResponse } from "./util_response";
|
|
4
|
-
export { ModalityLogger } from "./util_logger";
|
|
4
|
+
export { ModalityLogger, loggerInstance } from "./util_logger";
|
|
@@ -2,27 +2,26 @@
|
|
|
2
2
|
* Storage Logger for structured logging
|
|
3
3
|
* Provides consistent logging across storage operations with configurable levels
|
|
4
4
|
*/
|
|
5
|
-
export type LogLevel =
|
|
5
|
+
export type LogLevel = "debug" | "info" | "warn" | "error" | "success";
|
|
6
6
|
export interface LoggerOptions {
|
|
7
|
-
timestampFormat?:
|
|
8
|
-
|
|
9
|
-
json?: boolean;
|
|
10
|
-
context?: Record<string, any>;
|
|
7
|
+
timestampFormat?: "iso" | "locale" | false;
|
|
8
|
+
name?: string;
|
|
11
9
|
}
|
|
12
10
|
export declare class ModalityLogger {
|
|
11
|
+
private static instance;
|
|
13
12
|
private options;
|
|
14
13
|
private logLevel;
|
|
15
|
-
constructor(
|
|
14
|
+
constructor(logOption: string | LoggerOptions, logLevel?: LogLevel);
|
|
15
|
+
static getInstance(logOption: string | LoggerOptions, logLevel?: LogLevel): ModalityLogger;
|
|
16
16
|
private getTimestamp;
|
|
17
17
|
private shouldLog;
|
|
18
|
-
private format;
|
|
19
|
-
withContext(context: Record<string, any>): ModalityLogger;
|
|
20
18
|
setLogLevel(level: LogLevel): void;
|
|
21
|
-
|
|
22
|
-
log(level: LogLevel,
|
|
23
|
-
debug(message: string,
|
|
24
|
-
info(message: string,
|
|
25
|
-
warn(message: string,
|
|
26
|
-
error(message: string,
|
|
27
|
-
success(message: string,
|
|
19
|
+
private format;
|
|
20
|
+
log(level: LogLevel, payload: any, categroy?: string): void;
|
|
21
|
+
debug(message: string, error?: Error): void;
|
|
22
|
+
info(message: string, data?: any): void;
|
|
23
|
+
warn(message: string, resolution: string): void;
|
|
24
|
+
error(message: string, error?: Error): void;
|
|
25
|
+
success(message: string, data?: any): void;
|
|
28
26
|
}
|
|
27
|
+
export declare const loggerInstance: typeof ModalityLogger.getInstance;
|
package/package.json
CHANGED