Przeglądaj źródła

feat: add logging config

j8
paweldomas 8 lat temu
rodzic
commit
76c89845a8
6 zmienionych plików z 63 dodań i 8 usunięć
  1. 35
    1
      app.js
  2. 0
    2
      conference.js
  3. 2
    0
      index.html
  4. 8
    0
      logging_config.js
  5. 8
    3
      modules/config/URLProcessor.js
  6. 10
    2
      modules/config/Util.js

+ 35
- 1
app.js Wyświetl plik

@@ -1,4 +1,4 @@
1
-/* global $, config, getRoomName */
1
+/* global $, config, getRoomName, loggingConfig, JitsiMeetJS */
2 2
 /* application specific logic */
3 3
 const logger = require("jitsi-meet-logger").getLogger(__filename);
4 4
 
@@ -19,6 +19,8 @@ import 'aui-experimental-css';
19 19
 
20 20
 window.toastr = require("toastr");
21 21
 
22
+const Logger = require("jitsi-meet-logger");
23
+
22 24
 import URLProcessor from "./modules/config/URLProcessor";
23 25
 import RoomnameGenerator from './modules/util/RoomnameGenerator';
24 26
 
@@ -32,6 +34,7 @@ import UIEvents from './service/UI/UIEvents';
32 34
 import getTokenData from "./modules/tokendata/TokenData";
33 35
 import translation from "./modules/translation/translation";
34 36
 
37
+
35 38
 /**
36 39
  * Tries to push history state with the following parameters:
37 40
  * 'VideoChat', `Room: ${roomName}`, URL. If fail, prints the error and returns
@@ -79,6 +82,36 @@ function buildRoomName () {
79 82
     return roomName;
80 83
 }
81 84
 
85
+/**
86
+ * Adjusts the logging levels.
87
+ * @private
88
+ */
89
+function configureLoggingLevels () {
90
+    // NOTE The library Logger is separated from the app loggers, so the levels
91
+    // have to be set in two places
92
+
93
+    // Set default logging level
94
+    const defaultLogLevel
95
+        = loggingConfig.defaultLogLevel || JitsiMeetJS.logLevels.TRACE;
96
+    Logger.setLogLevel(defaultLogLevel);
97
+    JitsiMeetJS.setLogLevel(defaultLogLevel);
98
+
99
+    // NOTE console was used on purpose here to go around the logging
100
+    // and always print the default logging level to the console
101
+    console.info("Default logging level set to: " + defaultLogLevel);
102
+
103
+    // Set log level for each logger
104
+    if (loggingConfig) {
105
+        Object.keys(loggingConfig).forEach(function(loggerName) {
106
+            if ('defaultLogLevel' !== loggerName) {
107
+                const level = loggingConfig[loggerName];
108
+                Logger.setLogLevelById(level, loggerName);
109
+                JitsiMeetJS.setLogLevelById(level, loggerName);
110
+            }
111
+        });
112
+    }
113
+}
114
+
82 115
 const APP = {
83 116
     // Used by do_external_connect.js if we receive the attach data after
84 117
     // connect was already executed. status property can be "initialized",
@@ -107,6 +140,7 @@ const APP = {
107 140
     connection: null,
108 141
     API,
109 142
     init () {
143
+        configureLoggingLevels();
110 144
         this.keyboardshortcut =
111 145
             require("./modules/keyboardshortcut/keyboardshortcut");
112 146
         this.configFetch = require("./modules/config/HttpConfigFetch");

+ 0
- 2
conference.js Wyświetl plik

@@ -464,8 +464,6 @@ export default {
464 464
      */
465 465
     init(options) {
466 466
         this.roomName = options.roomName;
467
-        JitsiMeetJS.setLogLevel(JitsiMeetJS.logLevels.TRACE);
468
-
469 467
         // attaches global error handler, if there is already one, respect it
470 468
         if(JitsiMeetJS.getGlobalOnErrorHandler){
471 469
             var oldOnErrorHandler = window.onerror;

+ 2
- 0
index.html Wyświetl plik

@@ -14,6 +14,7 @@
14 14
             "utils.js",
15 15
             "do_external_connect.js",
16 16
             "interface_config.js",
17
+            "logging_config.js",
17 18
             "lib-jitsi-meet.min.js",
18 19
             "app.bundle.min.js",
19 20
             "all.css"
@@ -43,6 +44,7 @@
43 44
     <!--#include virtual="connection_optimization/connection_optimization.html" -->
44 45
     <script src="connection_optimization/do_external_connect.js?v=1"></script>
45 46
     <script><!--#include virtual="/interface_config.js" --></script>
47
+    <script><!--#include virtual="/logging_config.js" --></script>
46 48
     <script src="libs/lib-jitsi-meet.min.js?v=139"></script>
47 49
     <script src="libs/app.bundle.min.js?v=139"></script>
48 50
     <!--#include virtual="title.html" -->

+ 8
- 0
logging_config.js Wyświetl plik

@@ -0,0 +1,8 @@
1
+// Logging configuration
2
+var loggingConfig = { // eslint-disable-line no-unused-vars
3
+    //default log level for the app and lib-jitsi-meet
4
+    //defaultLogLevel: 'trace',
5
+    // Examples:
6
+    //'modules/version/ComponentsVersions.js': 'info',
7
+    //'modules/xmpp/ChatRoom.js': 'log'
8
+};

+ 8
- 3
modules/config/URLProcessor.js Wyświetl plik

@@ -1,4 +1,4 @@
1
-/* global config, interfaceConfig, getConfigParamsFromUrl */
1
+/* global config, interfaceConfig, loggingConfig, getConfigParamsFromUrl */
2 2
 const logger = require("jitsi-meet-logger").getLogger(__filename);
3 3
 
4 4
 var configUtils = require('./Util');
@@ -27,7 +27,8 @@ var URLProcessor = {
27 27
         // }
28 28
         var configJSON = {
29 29
             config: {},
30
-            interfaceConfig: {}
30
+            interfaceConfig: {},
31
+            loggingConfig: {}
31 32
         };
32 33
         for (var key in params) {
33 34
             if (typeof key !== "string") {
@@ -47,6 +48,9 @@ var URLProcessor = {
47 48
             } else if (key.indexOf("interfaceConfig.") === 0) {
48 49
                 confObj = configJSON.interfaceConfig;
49 50
                 confKey = key.substr("interfaceConfig.".length);
51
+            } else if (key.indexOf("loggingConfig.") === 0) {
52
+                confObj = configJSON.loggingConfig;
53
+                confKey = key.substr("loggingConfig.".length);
50 54
             }
51 55
 
52 56
             if (!confObj)
@@ -54,7 +58,8 @@ var URLProcessor = {
54 58
 
55 59
             confObj[confKey] = params[key];
56 60
         }
57
-        configUtils.overrideConfigJSON(config, interfaceConfig, configJSON);
61
+        configUtils.overrideConfigJSON(
62
+            config, interfaceConfig, loggingConfig, configJSON);
58 63
     }
59 64
 };
60 65
 

+ 10
- 2
modules/config/Util.js Wyświetl plik

@@ -7,6 +7,8 @@ var ConfigUtil = {
7 7
      * @param config the config object for which we'll be overriding properties
8 8
      * @param interfaceConfig the interfaceConfig object for which we'll be
9 9
      *                        overriding properties.
10
+     * @param loggingConfig the logging config object for which we'll be
11
+     *        overriding properties.
10 12
      * @param newConfig object containing configuration properties. Destination
11 13
      *        object is selected based on root property name:
12 14
      *        {
@@ -14,11 +16,15 @@ var ConfigUtil = {
14 16
      *             // config.js properties to be
15 17
      *          },
16 18
      *          interfaceConfig: {
17
-     *             // interfaceConfig.js properties here
19
+     *             // interface_config.js properties here
20
+     *          },
21
+     *          loggingConfig: {
22
+     *             // logging_config.js properties here
18 23
      *          }
19 24
      *        }
20 25
      */
21
-    overrideConfigJSON: function (config, interfaceConfig, newConfig) {
26
+    overrideConfigJSON: function (config,
27
+                                  interfaceConfig, loggingConfig, newConfig) {
22 28
         var configRoot, key, value, confObj;
23 29
         for (configRoot in newConfig) {
24 30
             confObj = null;
@@ -26,6 +32,8 @@ var ConfigUtil = {
26 32
                 confObj = config;
27 33
             } else if (configRoot == "interfaceConfig") {
28 34
                 confObj = interfaceConfig;
35
+            } else if (configRoot == "loggingConfig") {
36
+                confObj = loggingConfig;
29 37
             } else {
30 38
                 continue;
31 39
             }

Ładowanie…
Anuluj
Zapisz