From e578f6c30fed4ce740bc99842eb2459e7e7eaefa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sa=C3=BAl=20Ibarra=20Corretg=C3=A9?= Date: Wed, 17 Aug 2022 14:32:40 +0200 Subject: [PATCH] feat(logging) migrate logging to config.js --- config.js | 14 +++++ debian/jitsi-meet-web.install | 1 - index.html | 2 - logging_config.js | 26 -------- react/features/base/config/actions.js | 6 +- react/features/base/config/configWhitelist.js | 1 + react/features/base/config/functions.any.js | 28 ++------- .../base/lib-jitsi-meet/middleware.js | 11 ---- react/features/base/logging/middleware.ts | 37 ++++++++++-- react/features/base/logging/reducer.ts | 59 +++++++++++-------- 10 files changed, 87 insertions(+), 98 deletions(-) delete mode 100644 logging_config.js diff --git a/config.js b/config.js index 9fefbf7176..79ccc0d402 100644 --- a/config.js +++ b/config.js @@ -1470,4 +1470,18 @@ var config = { // // How long the GIF should be displayed on the tile (in miliseconds). // tileTime: 5000, // }, + + // Logging + // logging: { + // // Default log level for the app and lib-jitsi-meet. + // defaultLogLevel: 'trace', + // // Option to disable LogCollector (which stores the logs on CallStats). + // //disableLogCollector: true, + // // Indivual loggers are customizable. + // loggers: { + // // The following are too verbose in their logging with the default level. + // 'modules/RTC/TraceablePeerConnection.js': 'info', + // 'modules/statistics/CallStats.js': 'info', + // 'modules/xmpp/strophe.util.js': 'log', + // }, }; diff --git a/debian/jitsi-meet-web.install b/debian/jitsi-meet-web.install index 8a1852c748..c66a2ada08 100644 --- a/debian/jitsi-meet-web.install +++ b/debian/jitsi-meet-web.install @@ -1,5 +1,4 @@ interface_config.js /usr/share/jitsi-meet/ -logging_config.js /usr/share/jitsi-meet/ *.html /usr/share/jitsi-meet/ *.ico /usr/share/jitsi-meet/ libs /usr/share/jitsi-meet/ diff --git a/index.html b/index.html index 3585a77067..de935d5dda 100644 --- a/index.html +++ b/index.html @@ -67,7 +67,6 @@ "utils.js", "do_external_connect.js", "interface_config.js", - "logging_config.js", "lib-jitsi-meet.min.js", "app.bundle.min.js", "all.css" @@ -185,7 +184,6 @@ - diff --git a/logging_config.js b/logging_config.js deleted file mode 100644 index ffdb6052d7..0000000000 --- a/logging_config.js +++ /dev/null @@ -1,26 +0,0 @@ -/* eslint-disable no-unused-vars, no-var */ - -// Logging configuration -var loggingConfig = { - // default log level for the app and lib-jitsi-meet - defaultLogLevel: 'trace', - - // Option to disable LogCollector (which stores the logs on CallStats) - // disableLogCollector: true, - - // The following are too verbose in their logging with the - // {@link #defaultLogLevel}: - 'modules/RTC/TraceablePeerConnection.js': 'info', - 'modules/statistics/CallStats.js': 'info', - 'modules/xmpp/strophe.util.js': 'log' -}; - -/* eslint-enable no-unused-vars, no-var */ - -// XXX Web/React server-includes logging_config.js into index.html. -// Mobile/react-native requires it in react/features/base/logging. For the -// purposes of the latter, (try to) export loggingConfig. The following -// detection of a module system is inspired by webpack. -typeof module === 'object' - && typeof exports === 'object' - && (module.exports = loggingConfig); diff --git a/react/features/base/config/actions.js b/react/features/base/config/actions.js index cd7c592425..67be4a3114 100644 --- a/react/features/base/config/actions.js +++ b/react/features/base/config/actions.js @@ -105,11 +105,8 @@ export function setConfig(config: Object = {}) { // Now that the loading of the config was successful override the values // with the parameters passed in the hash part of the location URI. // TODO We're still in the middle ground between old Web with config, - // interfaceConfig, and loggingConfig used via global variables and new + // and interfaceConfig used via global variables and new // Web and mobile reading the respective values from the redux store. - // On React Native there's no interfaceConfig at all yet and - // loggingConfig is not loaded but there's a default value in the redux - // store. // Only the config will be overridden on React Native, as the other // globals will be undefined here. It's intentional - we do not care to // override those configs yet. @@ -120,7 +117,6 @@ export function setConfig(config: Object = {}) { // but it is resolved in the loadConfig procedure. config, window.interfaceConfig, - window.loggingConfig, locationURL); dispatch({ diff --git a/react/features/base/config/configWhitelist.js b/react/features/base/config/configWhitelist.js index 6b1c1aa64d..949128114a 100644 --- a/react/features/base/config/configWhitelist.js +++ b/react/features/base/config/configWhitelist.js @@ -187,6 +187,7 @@ export default [ 'liveStreamingEnabled', 'localRecording', 'localSubject', + 'logging', 'maxFullResolutionParticipants', 'mouseMoveCallbackInterval', 'notifications', diff --git a/react/features/base/config/functions.any.js b/react/features/base/config/functions.any.js index 20ee2404db..56ab5b1128 100644 --- a/react/features/base/config/functions.any.js +++ b/react/features/base/config/functions.any.js @@ -123,8 +123,6 @@ export function getRecordingSharingUrl(state: Object) { * properties. * @param {Object} interfaceConfig - The interfaceConfig Object in which we'll * be overriding properties. - * @param {Object} loggingConfig - The loggingConfig Object in which we'll be - * overriding properties. * @param {Object} json - Object containing configuration properties. * Destination object is selected based on root property name: * { @@ -133,16 +131,11 @@ export function getRecordingSharingUrl(state: Object) { * }, * interfaceConfig: { * // interface_config.js properties here - * }, - * loggingConfig: { - * // logging_config.js properties here * } * }. * @returns {void} */ -export function overrideConfigJSON( - config: ?Object, interfaceConfig: ?Object, loggingConfig: ?Object, - json: Object) { +export function overrideConfigJSON(config: ?Object, interfaceConfig: ?Object, json: Object) { for (const configName of Object.keys(json)) { let configObj; @@ -150,8 +143,6 @@ export function overrideConfigJSON( configObj = config; } else if (configName === 'interfaceConfig') { configObj = interfaceConfig; - } else if (configName === 'loggingConfig') { - configObj = loggingConfig; } if (configObj) { const configJSON @@ -177,12 +168,10 @@ export function overrideConfigJSON( /* eslint-enable max-params, no-shadow */ /** - * Apply whitelist filtering for configs with whitelists, skips this for others - * configs (loggingConfig). + * Apply whitelist filtering for configs with whitelists. * Only extracts overridden values for keys we allow to be overridden. * - * @param {string} configName - The config name, one of config, - * interfaceConfig, loggingConfig. + * @param {string} configName - The config name, one of config or interfaceConfig. * @param {Object} configJSON - The object with keys and values to override. * @returns {Object} - The result object only with the keys * that are whitelisted. @@ -264,7 +253,7 @@ export function restoreConfig(baseURL: string): ?Object { * Inspects the hash part of the location URI and overrides values specified * there in the corresponding config objects given as the arguments. The syntax * is: {@code https://server.com/room#config.debug=true - * &interfaceConfig.showButton=false&loggingConfig.something=1}. + * &interfaceConfig.showButton=false}. * * In the hash part each parameter will be parsed to JSON and then the root * object will be matched with the corresponding config object given as the @@ -272,15 +261,11 @@ export function restoreConfig(baseURL: string): ?Object { * * @param {Object} config - This is the general config. * @param {Object} interfaceConfig - This is the interface config. - * @param {Object} loggingConfig - The logging config. * @param {URI} location - The new location to which the app is navigating to. * @returns {void} */ export function setConfigFromURLParams( - config: ?Object, - interfaceConfig: ?Object, - loggingConfig: ?Object, - location: Object) { + config: ?Object, interfaceConfig: ?Object, location: Object) { const params = parseURLParams(location); const json = {}; @@ -302,7 +287,6 @@ export function setConfigFromURLParams( // } config && (json.config = {}); interfaceConfig && (json.interfaceConfig = {}); - loggingConfig && (json.loggingConfig = {}); for (const param of Object.keys(params)) { let base = json; @@ -316,7 +300,7 @@ export function setConfigFromURLParams( base[last] = params[param]; } - overrideConfigJSON(config, interfaceConfig, loggingConfig, json); + overrideConfigJSON(config, interfaceConfig, json); } /* eslint-enable max-params */ diff --git a/react/features/base/lib-jitsi-meet/middleware.js b/react/features/base/lib-jitsi-meet/middleware.js index 5adf8d4980..66a31a6f4d 100644 --- a/react/features/base/lib-jitsi-meet/middleware.js +++ b/react/features/base/lib-jitsi-meet/middleware.js @@ -1,7 +1,4 @@ -/* @flow */ - import { SET_CONFIG } from '../config'; -import { setLoggingConfig } from '../logging'; import { SET_NETWORK_INFO } from '../net-info'; import { PARTICIPANT_LEFT } from '../participants'; import { MiddlewareRegistry } from '../redux'; @@ -79,14 +76,6 @@ function _setConfig({ dispatch, getState }, next, action) { // from there). const result = next(action); - // FIXME Obviously, the following is bad design. However, I'm currently - // introducing the features base/config and base/logging and I'm trying to - // minimize the scope of the changes while I'm attempting to preserve - // compatibility with the existing partially React-ified Web source code and - // what was already executing on React Native. Additionally, I do not care - // to load logging_config.js on React Native. - dispatch(setLoggingConfig(window.loggingConfig)); - dispatch(initLib()); return result; diff --git a/react/features/base/logging/middleware.ts b/react/features/base/logging/middleware.ts index e78edff95f..e176eeb10f 100644 --- a/react/features/base/logging/middleware.ts +++ b/react/features/base/logging/middleware.ts @@ -5,6 +5,7 @@ import Logger from '@jitsi/logger'; import { APP_WILL_MOUNT } from '../app/actionTypes'; // @ts-ignore import { CONFERENCE_JOINED, getCurrentConference } from '../conference'; +import { SET_CONFIG } from '../config/actionTypes'; import JitsiMeetJS, { JitsiConferenceEvents } from '../lib-jitsi-meet'; @@ -17,7 +18,7 @@ import buildExternalApiLogTransport from './ExternalApiLogTransport'; import JitsiMeetInMemoryLogStorage from './JitsiMeetInMemoryLogStorage'; import JitsiMeetLogStorage from './JitsiMeetLogStorage'; import { SET_LOGGING_CONFIG } from './actionTypes'; -import { setLogCollector } from './actions'; +import { setLogCollector, setLoggingConfig } from './actions'; declare let APP: any; @@ -39,6 +40,9 @@ MiddlewareRegistry.register(store => next => action => { case LIB_WILL_INIT: return _libWillInit(store, next, action); + case SET_CONFIG: + return _setConfig(store, next, action); + case SET_LOGGING_CONFIG: return _setLoggingConfig(store, next, action); } @@ -142,8 +146,7 @@ function _initLogging({ dispatch, getState }: {dispatch: Function, getState: Fun // cached, before the JitsiMeetLogStorage gets ready (statistics module is // initialized). if (!logCollector && !loggingConfig.disableLogCollector) { - const _logCollector - = new Logger.LogCollector(new JitsiMeetLogStorage(getState)); + const _logCollector = new Logger.LogCollector(new JitsiMeetLogStorage(getState)); const { apiLogLevels } = getState()['features/base/config']; @@ -201,6 +204,28 @@ function _libWillInit({ getState }: { getState: Function }, next: Function, acti return next(action); } +/** + * This feature that the action SET_CONFIG is being + * dispatched within a specific Redux store. + * + * @param {Store} store - The Redux store in which the specified action is being + * dispatched. + * @param {Dispatch} next - The Redux dispatch function to dispatch the + * specified action to the specified store. + * @param {Action} action - The Redux action SET_CONFIG which is being + * dispatched in the specified store. + * @private + * @returns {Object} The new state that is the result of the reduction of the + * specified action. + */ +function _setConfig({ dispatch }: { dispatch: Function }, next: Function, action: any) { + const result = next(action); + + dispatch(setLoggingConfig(action.config?.logging)); + + return result; +} + /** * Notifies the feature base/logging that the action {@link SET_LOGGING_CONFIG} * is being dispatched within a specific Redux {@code store}. @@ -256,7 +281,7 @@ function _setLogLevels(logger: any, config: any) { logger.setLogLevel(config.defaultLogLevel); // Second, set the log level of each logger explicitly overridden by config. - Object.keys(config).forEach( - id => - id === 'defaultLogLevel' || logger.setLogLevelById(config[id], id)); + for (const [ id, level ] of Object.entries(config.loggers)) { + logger.setLogLevelById(level, id); + } } diff --git a/react/features/base/logging/reducer.ts b/react/features/base/logging/reducer.ts index d93def7175..060c1ebda4 100644 --- a/react/features/base/logging/reducer.ts +++ b/react/features/base/logging/reducer.ts @@ -1,10 +1,25 @@ +import _ from 'lodash'; + import ReducerRegistry from '../redux/ReducerRegistry'; import { equals, set } from '../redux/functions'; import { SET_LOG_COLLECTOR, SET_LOGGING_CONFIG } from './actionTypes'; -// eslint-disable-next-line -const LOGGING_CONFIG = require('../../../../logging_config.js'); +const DEFAULT_LOGGING_CONFIG = { + // default log level for the app and lib-jitsi-meet + defaultLogLevel: 'trace' as LogLevel, + + // Option to disable LogCollector (which stores the logs on CallStats) + // disableLogCollector: true, + + loggers: { + // The following are too verbose in their logging with the + // {@link #defaultLogLevel}: + 'modules/RTC/TraceablePeerConnection.js': 'info' as LogLevel, + 'modules/statistics/CallStats.js': 'info' as LogLevel, + 'modules/xmpp/strophe.util.js': 'log' as LogLevel + } +}; /** * The default/initial redux state of the feature base/logging. @@ -14,7 +29,7 @@ const LOGGING_CONFIG = require('../../../../logging_config.js'); * }} */ const DEFAULT_STATE = { - config: LOGGING_CONFIG, + config: DEFAULT_LOGGING_CONFIG, /** * The log collector. @@ -22,31 +37,30 @@ const DEFAULT_STATE = { logCollector: undefined }; -// Reduce verbosity on mobile, it kills performance. +// Reduce default verbosity on mobile, it kills performance. if (navigator.product === 'ReactNative') { - const RN_LOGGING_CONFIG = { - 'modules/sdp/SDPUtil.js': 'info', - 'modules/xmpp/ChatRoom.js': 'warn', - 'modules/xmpp/JingleSessionPC.js': 'info', - 'modules/xmpp/strophe.jingle.js': 'info' + const RN_LOGGERS = { + 'modules/sdp/SDPUtil.js': 'info' as LogLevel, + 'modules/xmpp/ChatRoom.js': 'warn' as LogLevel, + 'modules/xmpp/JingleSessionPC.js': 'info' as LogLevel, + 'modules/xmpp/strophe.jingle.js': 'info' as LogLevel }; - DEFAULT_STATE.config = { - ...LOGGING_CONFIG, - ...RN_LOGGING_CONFIG + DEFAULT_STATE.config.loggers = { + ...DEFAULT_LOGGING_CONFIG.loggers, + ...RN_LOGGERS }; } type LogLevel = 'trace' | 'log' | 'info' | 'warn' | 'error'; -interface LoggingLevel { - [key: string]: LogLevel; -} - export interface ILoggingState { - config: LoggingLevel & { + config: { defaultLogLevel: LogLevel; disableLogCollector?: boolean; + loggers: { + [key: string]: LogLevel; + } }; logCollector?: Object; } @@ -77,20 +91,15 @@ ReducerRegistry.register( * reduction of the specified action. */ function _setLoggingConfig(state: ILoggingState, action: any) { - const config = { - // The config of DEFAULT_STATE is the default configuration of the - // feature base/logging. - ...DEFAULT_STATE.config, - ...action.config - }; + const newConfig = _.merge({}, DEFAULT_STATE.config, action.config); - if (equals(state.config, config)) { + if (equals(state.config, newConfig)) { return state; } return { ...state, - config + config: newConfig }; }