ソースを参照

Adds in memory log storage, to be used while testing. (#2858)

* Adds in memory log storage, to be used while testing.

Enabling it only when config.debug is set, a configuration provided by jitsi-meet-torture.

* Moves to using config.testing.testMode property for logs storage.

* Fixes comments.
j8
Дамян Минков 7年前
コミット
8b1aff5512

+ 50
- 0
modules/util/JitsiMeetInMemoryLogStorage.js ファイルの表示

@@ -0,0 +1,50 @@
1
+/**
2
+ * Implements in memory logs storage, used for testing/debugging.
3
+ */
4
+export default class JitsiMeetInMemoryLogStorage {
5
+
6
+    /**
7
+     * Creates new <tt>JitsiMeetInMemoryLogStorage</tt>
8
+     */
9
+    constructor() {
10
+        /**
11
+         * Array of the log entries to keep.
12
+         * @type {array}
13
+         */
14
+        this.logs = [];
15
+    }
16
+
17
+    /**
18
+     * @returns {boolean} <tt>true</tt> when this storage is ready or
19
+     * <tt>false</tt> otherwise.
20
+     */
21
+    isReady() {
22
+        return true;
23
+    }
24
+
25
+    /**
26
+     * Called by the <tt>LogCollector</tt> to store a series of log lines into
27
+     * batch.
28
+     * @param {string|object[]} logEntries an array containing strings
29
+     * representing log lines or aggregated lines objects.
30
+     */
31
+    storeLogs(logEntries) {
32
+        for (let i = 0, len = logEntries.length; i < len; i++) {
33
+            const logEntry = logEntries[i];
34
+
35
+            if (typeof logEntry === 'object') {
36
+                this.logs.push(logEntry.text);
37
+            } else {
38
+                // Regular message
39
+                this.logs.push(logEntry);
40
+            }
41
+        }
42
+    }
43
+
44
+    /**
45
+     * @returns {array} the collected log entries.
46
+     */
47
+    getLogs() {
48
+        return this.logs;
49
+    }
50
+}

+ 18
- 2
react/features/base/logging/middleware.js ファイルの表示

@@ -6,8 +6,12 @@ import { APP_WILL_MOUNT } from '../../app';
6 6
 import JitsiMeetJS, { LIB_WILL_INIT } from '../lib-jitsi-meet';
7 7
 import { MiddlewareRegistry } from '../redux';
8 8
 
9
+import JitsiMeetInMemoryLogStorage
10
+    from '../../../../modules/util/JitsiMeetInMemoryLogStorage';
9 11
 import JitsiMeetLogStorage from '../../../../modules/util/JitsiMeetLogStorage';
10 12
 
13
+import { isTestModeEnabled } from '../testing';
14
+
11 15
 import { SET_LOGGING_CONFIG } from './actionTypes';
12 16
 
13 17
 declare var APP: Object;
@@ -67,10 +71,11 @@ function _appWillMount({ getState }, next, action) {
67 71
  *
68 72
  * @param {Object} loggingConfig - The configuration with which logging is to be
69 73
  * initialized.
74
+ * @param {boolean} isTestingEnabled - Is debug logging enabled.
70 75
  * @private
71 76
  * @returns {void}
72 77
  */
73
-function _initLogging(loggingConfig) {
78
+function _initLogging(loggingConfig, isTestingEnabled) {
74 79
     // Create the LogCollector and register it as the global log transport. It
75 80
     // is done early to capture as much logs as possible. Captured logs will be
76 81
     // cached, before the JitsiMeetLogStorage gets ready (statistics module is
@@ -81,6 +86,16 @@ function _initLogging(loggingConfig) {
81 86
         APP.logCollector = new Logger.LogCollector(new JitsiMeetLogStorage());
82 87
         Logger.addGlobalTransport(APP.logCollector);
83 88
         JitsiMeetJS.addGlobalLogTransport(APP.logCollector);
89
+
90
+        if (isTestingEnabled) {
91
+            APP.debugLogs = new JitsiMeetInMemoryLogStorage();
92
+            const debugLogCollector = new Logger.LogCollector(
93
+                APP.debugLogs, { storeInterval: 1000 });
94
+
95
+            Logger.addGlobalTransport(debugLogCollector);
96
+            JitsiMeetJS.addGlobalLogTransport(debugLogCollector);
97
+            debugLogCollector.start();
98
+        }
84 99
     }
85 100
 }
86 101
 
@@ -121,6 +136,7 @@ function _libWillInit({ getState }, next, action) {
121 136
 function _setLoggingConfig({ getState }, next, action) {
122 137
     const result = next(action);
123 138
     const newValue = getState()['features/base/logging'].config;
139
+    const isTestingEnabled = isTestModeEnabled(getState());
124 140
 
125 141
     // TODO Generally, we'll want to _setLogLevels and _initLogging only if the
126 142
     // logging config values actually change.
@@ -131,7 +147,7 @@ function _setLoggingConfig({ getState }, next, action) {
131 147
     _setLogLevels(Logger, newValue);
132 148
     _setLogLevels(JitsiMeetJS, newValue);
133 149
 
134
-    _initLogging(newValue);
150
+    _initLogging(newValue, isTestingEnabled);
135 151
 
136 152
     return result;
137 153
 }

+ 0
- 0
react/features/base/testing/components/TestHint.web.js ファイルの表示


読み込み中…
キャンセル
保存