@midscene/shared 1.3.10 → 1.3.11-beta-20260210054223.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/dist/es/logger.mjs +13 -4
- package/dist/lib/logger.js +13 -4
- package/dist/types/logger.d.ts +3 -1
- package/package.json +1 -1
- package/src/logger.ts +27 -13
package/dist/es/logger.mjs
CHANGED
|
@@ -33,9 +33,18 @@ function writeLogToFile(topic, message) {
|
|
|
33
33
|
const localISOTime = `${isoDate}T${isoTime}.${milliseconds}${timezoneString}`;
|
|
34
34
|
stream.write(`[${localISOTime}] ${message}\n`);
|
|
35
35
|
}
|
|
36
|
-
function getDebug(topic) {
|
|
36
|
+
function getDebug(topic, options) {
|
|
37
37
|
const fullTopic = `${topicPrefix}:${topic}`;
|
|
38
|
-
|
|
38
|
+
const withConsole = options?.console ?? false;
|
|
39
|
+
const cacheKey = withConsole ? `${fullTopic}:withConsole` : fullTopic;
|
|
40
|
+
if (!debugInstances.has(cacheKey)) if (withConsole) {
|
|
41
|
+
const baseFn = getDebug(topic);
|
|
42
|
+
const wrapper = (...args)=>{
|
|
43
|
+
baseFn(...args);
|
|
44
|
+
console.warn('[Midscene]', ...args);
|
|
45
|
+
};
|
|
46
|
+
debugInstances.set(cacheKey, wrapper);
|
|
47
|
+
} else {
|
|
39
48
|
const debugFn = debug(fullTopic);
|
|
40
49
|
const wrapper = (...args)=>{
|
|
41
50
|
if (ifInNode) {
|
|
@@ -44,9 +53,9 @@ function getDebug(topic) {
|
|
|
44
53
|
}
|
|
45
54
|
debugFn(...args);
|
|
46
55
|
};
|
|
47
|
-
debugInstances.set(
|
|
56
|
+
debugInstances.set(cacheKey, wrapper);
|
|
48
57
|
}
|
|
49
|
-
return debugInstances.get(
|
|
58
|
+
return debugInstances.get(cacheKey);
|
|
50
59
|
}
|
|
51
60
|
function enableDebug(topic) {
|
|
52
61
|
if (ifInNode) return;
|
package/dist/lib/logger.js
CHANGED
|
@@ -76,9 +76,18 @@ function writeLogToFile(topic, message) {
|
|
|
76
76
|
const localISOTime = `${isoDate}T${isoTime}.${milliseconds}${timezoneString}`;
|
|
77
77
|
stream.write(`[${localISOTime}] ${message}\n`);
|
|
78
78
|
}
|
|
79
|
-
function getDebug(topic) {
|
|
79
|
+
function getDebug(topic, options) {
|
|
80
80
|
const fullTopic = `${topicPrefix}:${topic}`;
|
|
81
|
-
|
|
81
|
+
const withConsole = options?.console ?? false;
|
|
82
|
+
const cacheKey = withConsole ? `${fullTopic}:withConsole` : fullTopic;
|
|
83
|
+
if (!debugInstances.has(cacheKey)) if (withConsole) {
|
|
84
|
+
const baseFn = getDebug(topic);
|
|
85
|
+
const wrapper = (...args)=>{
|
|
86
|
+
baseFn(...args);
|
|
87
|
+
console.warn('[Midscene]', ...args);
|
|
88
|
+
};
|
|
89
|
+
debugInstances.set(cacheKey, wrapper);
|
|
90
|
+
} else {
|
|
82
91
|
const debugFn = external_debug_default()(fullTopic);
|
|
83
92
|
const wrapper = (...args)=>{
|
|
84
93
|
if (external_utils_js_namespaceObject.ifInNode) {
|
|
@@ -87,9 +96,9 @@ function getDebug(topic) {
|
|
|
87
96
|
}
|
|
88
97
|
debugFn(...args);
|
|
89
98
|
};
|
|
90
|
-
debugInstances.set(
|
|
99
|
+
debugInstances.set(cacheKey, wrapper);
|
|
91
100
|
}
|
|
92
|
-
return debugInstances.get(
|
|
101
|
+
return debugInstances.get(cacheKey);
|
|
93
102
|
}
|
|
94
103
|
function enableDebug(topic) {
|
|
95
104
|
if (external_utils_js_namespaceObject.ifInNode) return;
|
package/dist/types/logger.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
export type DebugFunction = (...args: unknown[]) => void;
|
|
2
|
-
export declare function getDebug(topic: string
|
|
2
|
+
export declare function getDebug(topic: string, options?: {
|
|
3
|
+
console?: boolean;
|
|
4
|
+
}): DebugFunction;
|
|
3
5
|
export declare function enableDebug(topic: string): void;
|
|
4
6
|
export declare function cleanupLogStreams(): void;
|
package/package.json
CHANGED
package/src/logger.ts
CHANGED
|
@@ -52,25 +52,39 @@ function writeLogToFile(topic: string, message: string): void {
|
|
|
52
52
|
|
|
53
53
|
export type DebugFunction = (...args: unknown[]) => void;
|
|
54
54
|
|
|
55
|
-
export function getDebug(
|
|
55
|
+
export function getDebug(
|
|
56
|
+
topic: string,
|
|
57
|
+
options?: { console?: boolean },
|
|
58
|
+
): DebugFunction {
|
|
56
59
|
const fullTopic = `${topicPrefix}:${topic}`;
|
|
60
|
+
const withConsole = options?.console ?? false;
|
|
61
|
+
const cacheKey = withConsole ? `${fullTopic}:withConsole` : fullTopic;
|
|
57
62
|
|
|
58
|
-
if (!debugInstances.has(
|
|
59
|
-
|
|
63
|
+
if (!debugInstances.has(cacheKey)) {
|
|
64
|
+
if (withConsole) {
|
|
65
|
+
const baseFn = getDebug(topic);
|
|
66
|
+
const wrapper = (...args: unknown[]): void => {
|
|
67
|
+
baseFn(...args);
|
|
68
|
+
console.warn('[Midscene]', ...args);
|
|
69
|
+
};
|
|
70
|
+
debugInstances.set(cacheKey, wrapper);
|
|
71
|
+
} else {
|
|
72
|
+
const debugFn = debug(fullTopic) as DebugFunction;
|
|
60
73
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
74
|
+
// Create wrapper that handles both file logging and debug output
|
|
75
|
+
const wrapper = (...args: unknown[]): void => {
|
|
76
|
+
if (ifInNode) {
|
|
77
|
+
const message = util.format(...args);
|
|
78
|
+
writeLogToFile(topic, message);
|
|
79
|
+
}
|
|
80
|
+
debugFn(...args);
|
|
81
|
+
};
|
|
69
82
|
|
|
70
|
-
|
|
83
|
+
debugInstances.set(cacheKey, wrapper);
|
|
84
|
+
}
|
|
71
85
|
}
|
|
72
86
|
|
|
73
|
-
return debugInstances.get(
|
|
87
|
+
return debugInstances.get(cacheKey)!;
|
|
74
88
|
}
|
|
75
89
|
|
|
76
90
|
export function enableDebug(topic: string): void {
|