feat(logging) migrate logging to config.js

This commit is contained in:
Saúl Ibarra Corretgé 2022-08-17 14:32:40 +02:00 committed by GitHub
parent 77d687952d
commit e578f6c30f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 87 additions and 98 deletions

View File

@ -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',
// },
};

View File

@ -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/

View File

@ -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 @@
<!--#include virtual="connection_optimization/connection_optimization.html" -->
<script src="libs/do_external_connect.min.js?v=1"></script>
<script><!--#include virtual="/interface_config.js" --></script>
<script><!--#include virtual="/logging_config.js" --></script>
<script src="libs/lib-jitsi-meet.min.js?v=139"></script>
<script src="libs/app.bundle.min.js?v=139"></script>
<!--#include virtual="title.html" -->

View File

@ -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);

View File

@ -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({

View File

@ -187,6 +187,7 @@ export default [
'liveStreamingEnabled',
'localRecording',
'localSubject',
'logging',
'maxFullResolutionParticipants',
'mouseMoveCallbackInterval',
'notifications',

View File

@ -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 */

View File

@ -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;

View File

@ -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);
}
}

View File

@ -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
};
}