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 CHANGED
@@ -56,12 +56,23 @@ function formatErrorResponse(errorData, operation, meta) {
56
56
  }
57
57
  // src/util_logger.ts
58
58
  class ModalityLogger {
59
- options;
60
- logLevel;
61
- constructor(options = {}, logLevel = "info") {
62
- this.options = options;
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
- format(level, message, context = {}, extra) {
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
- 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 };
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, message, context = {}, extra) {
124
+ log(level, payload, categroy) {
126
125
  if (!this.shouldLog(level))
127
126
  return;
128
- const formatted = this.format(level, message, context, extra);
127
+ const formatted = this.format(level, payload, categroy);
129
128
  switch (level) {
130
129
  case "debug":
131
- this.options.json ? console.debug(formatted) : console.debug(...formatted);
130
+ console.debug(formatted);
132
131
  break;
133
132
  case "info":
134
- this.options.json ? console.info(formatted) : console.info(...formatted);
133
+ console.info(formatted);
135
134
  break;
136
135
  case "warn":
137
- this.options.json ? console.warn(formatted) : console.warn(...formatted);
136
+ console.warn(formatted);
138
137
  break;
139
138
  case "error":
140
- this.options.json ? console.error(formatted) : console.error(...formatted);
139
+ console.error(formatted);
141
140
  break;
142
141
  case "success":
143
- this.options.json ? console.log(formatted) : console.log(...formatted);
142
+ console.log(formatted);
144
143
  break;
145
144
  default:
146
- this.options.json ? console.log(formatted) : console.log(...formatted);
145
+ console.log(formatted);
146
+ break;
147
147
  }
148
148
  }
149
- debug(message, context, error) {
150
- const extra = error ? { error: error.message, stack: error.stack } : undefined;
151
- this.log("debug", message, context, extra);
149
+ debug(message, error) {
150
+ this.log("debug", { message, error });
152
151
  }
153
- info(message, context) {
154
- this.log("info", message, context);
152
+ info(message, data) {
153
+ this.log("info", { message, data });
155
154
  }
156
- warn(message, context) {
157
- this.log("warn", message, context);
155
+ warn(message, resolution) {
156
+ this.log("warn", { message, resolution });
158
157
  }
159
- error(message, context, error) {
160
- const extra = error ? { error: error.message, stack: error.stack } : undefined;
161
- this.log("error", message, context, extra);
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, context) {
164
- this.log("success", message, context);
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
@@ -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 = 'debug' | 'info' | 'warn' | 'error' | 'success';
5
+ export type LogLevel = "debug" | "info" | "warn" | "error" | "success";
6
6
  export interface LoggerOptions {
7
- timestampFormat?: 'iso' | 'locale' | false;
8
- color?: boolean;
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(options?: LoggerOptions, logLevel?: LogLevel);
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
- 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;
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
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.0.2",
2
+ "version": "0.0.4",
3
3
  "name": "modality-kit",
4
4
  "repository": {
5
5
  "type": "git",