modality-kit 0.0.2 → 0.0.3

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,66 @@ 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 (categroy) {
117
+ prefix += ` [${categroy}]`;
118
+ }
119
+ return [prefix, payload];
124
120
  }
125
- log(level, message, context = {}, extra) {
121
+ log(level, payload, categroy) {
126
122
  if (!this.shouldLog(level))
127
123
  return;
128
- const formatted = this.format(level, message, context, extra);
124
+ const formatted = this.format(level, payload, categroy);
129
125
  switch (level) {
130
126
  case "debug":
131
- this.options.json ? console.debug(formatted) : console.debug(...formatted);
127
+ console.debug(formatted);
132
128
  break;
133
129
  case "info":
134
- this.options.json ? console.info(formatted) : console.info(...formatted);
130
+ console.info(formatted);
135
131
  break;
136
132
  case "warn":
137
- this.options.json ? console.warn(formatted) : console.warn(...formatted);
133
+ console.warn(formatted);
138
134
  break;
139
135
  case "error":
140
- this.options.json ? console.error(formatted) : console.error(...formatted);
136
+ console.error(formatted);
141
137
  break;
142
138
  case "success":
143
- this.options.json ? console.log(formatted) : console.log(...formatted);
139
+ console.log(formatted);
144
140
  break;
145
141
  default:
146
- this.options.json ? console.log(formatted) : console.log(...formatted);
142
+ console.log(formatted);
143
+ break;
147
144
  }
148
145
  }
149
- debug(message, context, error) {
150
- const extra = error ? { error: error.message, stack: error.stack } : undefined;
151
- this.log("debug", message, context, extra);
146
+ debug(message, error) {
147
+ this.log("debug", { message, error });
152
148
  }
153
- info(message, context) {
154
- this.log("info", message, context);
149
+ info(message, data) {
150
+ this.log("info", { message, data });
155
151
  }
156
- warn(message, context) {
157
- this.log("warn", message, context);
152
+ warn(message, resolution) {
153
+ this.log("warn", { message, resolution });
158
154
  }
159
- error(message, context, error) {
160
- const extra = error ? { error: error.message, stack: error.stack } : undefined;
161
- this.log("error", message, context, extra);
155
+ error(message, error) {
156
+ const data = { message };
157
+ if (error) {
158
+ data.error = {
159
+ message: error.message,
160
+ stack: error.stack
161
+ };
162
+ }
163
+ this.log("error", data);
162
164
  }
163
- success(message, context) {
164
- this.log("success", message, context);
165
+ success(message, data) {
166
+ this.log("success", { message, data });
165
167
  }
166
168
  }
169
+ var loggerInstance = ModalityLogger.getInstance.bind(ModalityLogger);
167
170
  export {
168
171
  setupAITools,
172
+ loggerInstance,
169
173
  formatSuccessResponse,
170
174
  formatErrorResponse,
171
175
  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.3",
3
3
  "name": "modality-kit",
4
4
  "repository": {
5
5
  "type": "git",