浏览代码

feat(loggin) forward logs to external api

master
Tudor-Ovidiu Avram 4 年前
父节点
当前提交
e2731ce73e

+ 3
- 0
config.js 查看文件

@@ -510,6 +510,9 @@ var config = {
510 510
         // ],
511 511
     },
512 512
 
513
+    // Logs that should go be passed through the 'log' event if a handler is defined for it
514
+    // apiLogLevels: ['warn', 'log', 'error', 'info', 'debug'],
515
+
513 516
     // Information about the jitsi-meet instance we are connecting to, including
514 517
     // the user region as seen by the server.
515 518
     deploymentInfo: {

+ 15
- 0
modules/API/API.js 查看文件

@@ -696,6 +696,21 @@ class API {
696 696
         });
697 697
     }
698 698
 
699
+    /**
700
+     * Notify external application (if API is enabled) that the an error has been logged.
701
+     *
702
+     * @param {string} logLevel - The message log level.
703
+     * @param {Array} args - Array of strings composing the log message.
704
+     * @returns {void}
705
+     */
706
+    notifyLog(logLevel: string, args: Array<string>) {
707
+        this._sendEvent({
708
+            name: 'log',
709
+            logLevel,
710
+            args
711
+        });
712
+    }
713
+
699 714
     /**
700 715
      * Notify external application (if API is enabled) that the conference has
701 716
      * been joined.

+ 8
- 0
modules/API/external/external_api.js 查看文件

@@ -68,6 +68,7 @@ const events = {
68 68
     'feedback-prompt-displayed': 'feedbackPromptDisplayed',
69 69
     'filmstrip-display-changed': 'filmstripDisplayChanged',
70 70
     'incoming-message': 'incomingMessage',
71
+    'log': 'log',
71 72
     'mic-error': 'micError',
72 73
     'outgoing-message': 'outgoingMessage',
73 74
     'participant-joined': 'participantJoined',
@@ -543,6 +544,13 @@ export default class JitsiMeetExternalAPI extends EventEmitter {
543 544
      * the event and value - the listener.
544 545
      * Currently we support the following
545 546
      * events:
547
+     * {@code log} - receives event notifications whenever information has
548
+     * been logged and has a log level specified within {@code config.apiLogLevels}.
549
+     * The listener will receive object with the following structure:
550
+     * {{
551
+     * logLevel: the message log level
552
+     * arguments: an array of strings that compose the actual log message
553
+     * }}
546 554
      * {@code incomingMessage} - receives event notifications about incoming
547 555
      * messages. The listener will receive object with the following structure:
548 556
      * {{

+ 1
- 0
react/features/base/config/configWhitelist.js 查看文件

@@ -17,6 +17,7 @@ export default [
17 17
     'audioLevelsInterval',
18 18
     'autoRecord',
19 19
     'autoRecordToken',
20
+    'apiLogLevels',
20 21
     'avgRtpStatsN',
21 22
 
22 23
     /**

+ 22
- 0
react/features/base/logging/ExternalApiLogTransport.js 查看文件

@@ -0,0 +1,22 @@
1
+// @flow
2
+
3
+declare var APP: Object;
4
+
5
+/**
6
+ * Constructs a log transport object for use with external API.
7
+ *
8
+ * @param {Array} levels - The log levels forwarded to the external API.
9
+
10
+ * @returns {Object} - The transport object.
11
+ */
12
+function buildTransport(levels: Array<string>) {
13
+    return levels.reduce((logger, level) => {
14
+        logger[level] = (...args) => {
15
+            APP.API.notifyLog(level, args);
16
+        };
17
+
18
+        return logger;
19
+    }, {});
20
+}
21
+
22
+export default buildTransport;

+ 10
- 0
react/features/base/logging/middleware.js 查看文件

@@ -11,6 +11,7 @@ import JitsiMeetJS, {
11 11
 import { MiddlewareRegistry } from '../redux';
12 12
 import { isTestModeEnabled } from '../testing';
13 13
 
14
+import buildExternalApiLogTransport from './ExternalApiLogTransport';
14 15
 import JitsiMeetInMemoryLogStorage from './JitsiMeetInMemoryLogStorage';
15 16
 import JitsiMeetLogStorage from './JitsiMeetLogStorage';
16 17
 import { SET_LOGGING_CONFIG } from './actionTypes';
@@ -141,6 +142,15 @@ function _initLogging({ dispatch, getState }, loggingConfig, isTestingEnabled) {
141 142
         const _logCollector
142 143
             = new Logger.LogCollector(new JitsiMeetLogStorage(getState));
143 144
 
145
+        const { apiLogLevels } = getState()['features/base/config'];
146
+
147
+        if (apiLogLevels && Array.isArray(apiLogLevels) && typeof APP === 'object') {
148
+            const transport = buildExternalApiLogTransport(apiLogLevels);
149
+
150
+            Logger.addGlobalTransport(transport);
151
+            JitsiMeetJS.addGlobalLogTransport(transport);
152
+        }
153
+
144 154
         Logger.addGlobalTransport(_logCollector);
145 155
         JitsiMeetJS.addGlobalLogTransport(_logCollector);
146 156
         dispatch(setLogCollector(_logCollector));

正在加载...
取消
保存