diff --git a/app.js b/app.js index cfec93da2..7996f208e 100644 --- a/app.js +++ b/app.js @@ -1,4 +1,4 @@ -/* global $, config, getRoomName */ +/* global $, config, getRoomName, loggingConfig, JitsiMeetJS */ /* application specific logic */ const logger = require("jitsi-meet-logger").getLogger(__filename); @@ -19,6 +19,8 @@ import 'aui-experimental-css'; window.toastr = require("toastr"); +const Logger = require("jitsi-meet-logger"); + import URLProcessor from "./modules/config/URLProcessor"; import RoomnameGenerator from './modules/util/RoomnameGenerator'; @@ -32,6 +34,7 @@ import UIEvents from './service/UI/UIEvents'; import getTokenData from "./modules/tokendata/TokenData"; import translation from "./modules/translation/translation"; + /** * Tries to push history state with the following parameters: * 'VideoChat', `Room: ${roomName}`, URL. If fail, prints the error and returns @@ -79,6 +82,36 @@ function buildRoomName () { return roomName; } +/** + * Adjusts the logging levels. + * @private + */ +function configureLoggingLevels () { + // NOTE The library Logger is separated from the app loggers, so the levels + // have to be set in two places + + // Set default logging level + const defaultLogLevel + = loggingConfig.defaultLogLevel || JitsiMeetJS.logLevels.TRACE; + Logger.setLogLevel(defaultLogLevel); + JitsiMeetJS.setLogLevel(defaultLogLevel); + + // NOTE console was used on purpose here to go around the logging + // and always print the default logging level to the console + console.info("Default logging level set to: " + defaultLogLevel); + + // Set log level for each logger + if (loggingConfig) { + Object.keys(loggingConfig).forEach(function(loggerName) { + if ('defaultLogLevel' !== loggerName) { + const level = loggingConfig[loggerName]; + Logger.setLogLevelById(level, loggerName); + JitsiMeetJS.setLogLevelById(level, loggerName); + } + }); + } +} + const APP = { // Used by do_external_connect.js if we receive the attach data after // connect was already executed. status property can be "initialized", @@ -107,6 +140,7 @@ const APP = { connection: null, API, init () { + configureLoggingLevels(); this.keyboardshortcut = require("./modules/keyboardshortcut/keyboardshortcut"); this.configFetch = require("./modules/config/HttpConfigFetch"); diff --git a/conference.js b/conference.js index 6e084e682..992d0ef35 100644 --- a/conference.js +++ b/conference.js @@ -464,8 +464,6 @@ export default { */ init(options) { this.roomName = options.roomName; - JitsiMeetJS.setLogLevel(JitsiMeetJS.logLevels.TRACE); - // attaches global error handler, if there is already one, respect it if(JitsiMeetJS.getGlobalOnErrorHandler){ var oldOnErrorHandler = window.onerror; diff --git a/index.html b/index.html index f24aeb54e..4b475d906 100644 --- a/index.html +++ b/index.html @@ -14,6 +14,7 @@ "utils.js", "do_external_connect.js", "interface_config.js", + "logging_config.js", "lib-jitsi-meet.min.js", "app.bundle.min.js", "all.css" @@ -43,6 +44,7 @@ + diff --git a/logging_config.js b/logging_config.js new file mode 100644 index 000000000..00cefdf32 --- /dev/null +++ b/logging_config.js @@ -0,0 +1,8 @@ +// Logging configuration +var loggingConfig = { // eslint-disable-line no-unused-vars + //default log level for the app and lib-jitsi-meet + //defaultLogLevel: 'trace', + // Examples: + //'modules/version/ComponentsVersions.js': 'info', + //'modules/xmpp/ChatRoom.js': 'log' +}; \ No newline at end of file diff --git a/modules/config/URLProcessor.js b/modules/config/URLProcessor.js index 125d6c1d4..35dfbf2e3 100644 --- a/modules/config/URLProcessor.js +++ b/modules/config/URLProcessor.js @@ -1,4 +1,4 @@ -/* global config, interfaceConfig, getConfigParamsFromUrl */ +/* global config, interfaceConfig, loggingConfig, getConfigParamsFromUrl */ const logger = require("jitsi-meet-logger").getLogger(__filename); var configUtils = require('./Util'); @@ -27,7 +27,8 @@ var URLProcessor = { // } var configJSON = { config: {}, - interfaceConfig: {} + interfaceConfig: {}, + loggingConfig: {} }; for (var key in params) { if (typeof key !== "string") { @@ -47,6 +48,9 @@ var URLProcessor = { } else if (key.indexOf("interfaceConfig.") === 0) { confObj = configJSON.interfaceConfig; confKey = key.substr("interfaceConfig.".length); + } else if (key.indexOf("loggingConfig.") === 0) { + confObj = configJSON.loggingConfig; + confKey = key.substr("loggingConfig.".length); } if (!confObj) @@ -54,7 +58,8 @@ var URLProcessor = { confObj[confKey] = params[key]; } - configUtils.overrideConfigJSON(config, interfaceConfig, configJSON); + configUtils.overrideConfigJSON( + config, interfaceConfig, loggingConfig, configJSON); } }; diff --git a/modules/config/Util.js b/modules/config/Util.js index 29bf9e599..7d7065f56 100644 --- a/modules/config/Util.js +++ b/modules/config/Util.js @@ -7,6 +7,8 @@ var ConfigUtil = { * @param config the config object for which we'll be overriding properties * @param interfaceConfig the interfaceConfig object for which we'll be * overriding properties. + * @param loggingConfig the logging config object for which we'll be + * overriding properties. * @param newConfig object containing configuration properties. Destination * object is selected based on root property name: * { @@ -14,11 +16,15 @@ var ConfigUtil = { * // config.js properties to be * }, * interfaceConfig: { - * // interfaceConfig.js properties here + * // interface_config.js properties here + * }, + * loggingConfig: { + * // logging_config.js properties here * } * } */ - overrideConfigJSON: function (config, interfaceConfig, newConfig) { + overrideConfigJSON: function (config, + interfaceConfig, loggingConfig, newConfig) { var configRoot, key, value, confObj; for (configRoot in newConfig) { confObj = null; @@ -26,6 +32,8 @@ var ConfigUtil = { confObj = config; } else if (configRoot == "interfaceConfig") { confObj = interfaceConfig; + } else if (configRoot == "loggingConfig") { + confObj = loggingConfig; } else { continue; }