@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.
@@ -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
- if (!debugInstances.has(fullTopic)) {
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(fullTopic, wrapper);
56
+ debugInstances.set(cacheKey, wrapper);
48
57
  }
49
- return debugInstances.get(fullTopic);
58
+ return debugInstances.get(cacheKey);
50
59
  }
51
60
  function enableDebug(topic) {
52
61
  if (ifInNode) return;
@@ -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
- if (!debugInstances.has(fullTopic)) {
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(fullTopic, wrapper);
99
+ debugInstances.set(cacheKey, wrapper);
91
100
  }
92
- return debugInstances.get(fullTopic);
101
+ return debugInstances.get(cacheKey);
93
102
  }
94
103
  function enableDebug(topic) {
95
104
  if (external_utils_js_namespaceObject.ifInNode) return;
@@ -1,4 +1,6 @@
1
1
  export type DebugFunction = (...args: unknown[]) => void;
2
- export declare function getDebug(topic: string): DebugFunction;
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@midscene/shared",
3
- "version": "1.3.10",
3
+ "version": "1.3.11-beta-20260210054223.0",
4
4
  "repository": "https://github.com/web-infra-dev/midscene",
5
5
  "homepage": "https://midscenejs.com/",
6
6
  "types": "./dist/types/index.d.ts",
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(topic: string): DebugFunction {
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(fullTopic)) {
59
- const debugFn = debug(fullTopic) as DebugFunction;
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
- // Create wrapper that handles both file logging and debug output
62
- const wrapper = (...args: unknown[]): void => {
63
- if (ifInNode) {
64
- const message = util.format(...args);
65
- writeLogToFile(topic, message);
66
- }
67
- debugFn(...args);
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
- debugInstances.set(fullTopic, wrapper);
83
+ debugInstances.set(cacheKey, wrapper);
84
+ }
71
85
  }
72
86
 
73
- return debugInstances.get(fullTopic)!;
87
+ return debugInstances.get(cacheKey)!;
74
88
  }
75
89
 
76
90
  export function enableDebug(topic: string): void {