2022-08-17 12:32:40 +00:00
|
|
|
import _ from 'lodash';
|
|
|
|
|
2022-07-20 15:01:16 +00:00
|
|
|
import ReducerRegistry from '../redux/ReducerRegistry';
|
|
|
|
import { equals, set } from '../redux/functions';
|
2017-04-23 20:17:31 +00:00
|
|
|
|
2018-09-05 20:23:57 +00:00
|
|
|
import { SET_LOG_COLLECTOR, SET_LOGGING_CONFIG } from './actionTypes';
|
2017-04-23 20:17:31 +00:00
|
|
|
|
2022-08-17 12:32:40 +00:00
|
|
|
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
|
|
|
|
}
|
|
|
|
};
|
2021-09-01 15:26:30 +00:00
|
|
|
|
2017-04-23 20:17:31 +00:00
|
|
|
/**
|
2018-02-14 18:28:22 +00:00
|
|
|
* The default/initial redux state of the feature base/logging.
|
2017-04-23 20:17:31 +00:00
|
|
|
*
|
|
|
|
* @type {{
|
|
|
|
* config: Object
|
|
|
|
* }}
|
|
|
|
*/
|
2018-02-14 18:28:22 +00:00
|
|
|
const DEFAULT_STATE = {
|
2022-08-17 12:32:40 +00:00
|
|
|
config: DEFAULT_LOGGING_CONFIG,
|
2018-09-05 20:23:57 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The log collector.
|
|
|
|
*/
|
|
|
|
logCollector: undefined
|
2017-04-23 20:17:31 +00:00
|
|
|
};
|
|
|
|
|
2022-08-17 12:32:40 +00:00
|
|
|
// Reduce default verbosity on mobile, it kills performance.
|
2021-09-01 15:26:30 +00:00
|
|
|
if (navigator.product === 'ReactNative') {
|
2022-08-17 12:32:40 +00:00
|
|
|
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
|
2021-09-01 15:26:30 +00:00
|
|
|
};
|
|
|
|
|
2022-08-17 12:32:40 +00:00
|
|
|
DEFAULT_STATE.config.loggers = {
|
|
|
|
...DEFAULT_LOGGING_CONFIG.loggers,
|
|
|
|
...RN_LOGGERS
|
2021-09-01 15:26:30 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2022-07-20 15:01:16 +00:00
|
|
|
type LogLevel = 'trace' | 'log' | 'info' | 'warn' | 'error';
|
|
|
|
|
|
|
|
export interface ILoggingState {
|
2022-08-17 12:32:40 +00:00
|
|
|
config: {
|
2022-07-20 15:01:16 +00:00
|
|
|
defaultLogLevel: LogLevel;
|
|
|
|
disableLogCollector?: boolean;
|
2022-08-17 12:32:40 +00:00
|
|
|
loggers: {
|
|
|
|
[key: string]: LogLevel;
|
|
|
|
}
|
2022-07-20 15:01:16 +00:00
|
|
|
};
|
|
|
|
logCollector?: Object;
|
|
|
|
}
|
|
|
|
|
2017-04-23 20:17:31 +00:00
|
|
|
ReducerRegistry.register(
|
|
|
|
'features/base/logging',
|
2022-07-20 15:01:16 +00:00
|
|
|
(state: ILoggingState = DEFAULT_STATE, action) => {
|
2017-04-23 20:17:31 +00:00
|
|
|
switch (action.type) {
|
|
|
|
case SET_LOGGING_CONFIG:
|
|
|
|
return _setLoggingConfig(state, action);
|
2018-09-05 20:23:57 +00:00
|
|
|
case SET_LOG_COLLECTOR: {
|
|
|
|
return _setLogCollector(state, action);
|
|
|
|
}
|
2017-04-23 20:17:31 +00:00
|
|
|
|
|
|
|
default:
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Reduces a specific Redux action SET_LOGGING_CONFIG of the feature
|
|
|
|
* base/logging.
|
|
|
|
*
|
|
|
|
* @param {Object} state - The Redux state of the feature base/logging.
|
|
|
|
* @param {Action} action - The Redux action SET_LOGGING_CONFIG to reduce.
|
|
|
|
* @private
|
|
|
|
* @returns {Object} The new state of the feature base/logging after the
|
|
|
|
* reduction of the specified action.
|
|
|
|
*/
|
2022-07-20 15:01:16 +00:00
|
|
|
function _setLoggingConfig(state: ILoggingState, action: any) {
|
2022-08-17 12:32:40 +00:00
|
|
|
const newConfig = _.merge({}, DEFAULT_STATE.config, action.config);
|
2017-04-23 20:17:31 +00:00
|
|
|
|
2022-08-17 12:32:40 +00:00
|
|
|
if (equals(state.config, newConfig)) {
|
2017-04-23 20:17:31 +00:00
|
|
|
return state;
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
...state,
|
2022-08-17 12:32:40 +00:00
|
|
|
config: newConfig
|
2017-04-23 20:17:31 +00:00
|
|
|
};
|
|
|
|
}
|
2018-09-05 20:23:57 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Reduces a specific Redux action SET_LOG_COLLECTOR of the feature
|
|
|
|
* base/logging.
|
|
|
|
*
|
|
|
|
* @param {Object} state - The Redux state of the feature base/logging.
|
|
|
|
* @param {Action} action - The Redux action SET_LOG_COLLECTOR to reduce.
|
|
|
|
* @private
|
|
|
|
* @returns {Object} The new state of the feature base/logging after the
|
|
|
|
* reduction of the specified action.
|
|
|
|
*/
|
2022-07-20 15:01:16 +00:00
|
|
|
function _setLogCollector(state: ILoggingState, action: any) {
|
2018-09-05 20:23:57 +00:00
|
|
|
return set(state, 'logCollector', action.logCollector);
|
|
|
|
}
|