You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

reducer.ts 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. import _ from 'lodash';
  2. import { AnyAction } from 'redux';
  3. import ReducerRegistry from '../redux/ReducerRegistry';
  4. import { equals, set } from '../redux/functions';
  5. import { SET_LOGGING_CONFIG, SET_LOG_COLLECTOR } from './actionTypes';
  6. const DEFAULT_LOGGING_CONFIG = {
  7. // default log level for the app and lib-jitsi-meet
  8. defaultLogLevel: 'trace' as LogLevel,
  9. // Option to disable LogCollector (which stores the logs on CallStats)
  10. // disableLogCollector: true,
  11. loggers: {
  12. // The following are too verbose in their logging with the
  13. // {@link #defaultLogLevel}:
  14. 'modules/RTC/TraceablePeerConnection.js': 'info' as LogLevel,
  15. 'modules/statistics/CallStats.js': 'info' as LogLevel,
  16. 'modules/xmpp/strophe.util.js': 'log' as LogLevel
  17. }
  18. };
  19. /**
  20. * The default/initial redux state of the feature base/logging.
  21. *
  22. * @type {{
  23. * config: Object
  24. * }}
  25. */
  26. const DEFAULT_STATE = {
  27. config: DEFAULT_LOGGING_CONFIG,
  28. /**
  29. * The log collector.
  30. */
  31. logCollector: undefined
  32. };
  33. // Reduce default verbosity on mobile, it kills performance.
  34. if (navigator.product === 'ReactNative') {
  35. const RN_LOGGERS = {
  36. 'modules/sdp/SDPUtil.js': 'info' as LogLevel,
  37. 'modules/xmpp/ChatRoom.js': 'warn' as LogLevel,
  38. 'modules/xmpp/JingleSessionPC.js': 'info' as LogLevel,
  39. 'modules/xmpp/strophe.jingle.js': 'info' as LogLevel
  40. };
  41. DEFAULT_STATE.config.loggers = {
  42. ...DEFAULT_LOGGING_CONFIG.loggers,
  43. ...RN_LOGGERS
  44. };
  45. }
  46. type LogLevel = 'trace' | 'log' | 'info' | 'warn' | 'error';
  47. export interface ILoggingState {
  48. config: {
  49. defaultLogLevel: LogLevel;
  50. disableLogCollector?: boolean;
  51. loggers: {
  52. [key: string]: LogLevel;
  53. };
  54. };
  55. logCollector?: {
  56. flush: () => void;
  57. start: () => void;
  58. stop: () => void;
  59. };
  60. }
  61. ReducerRegistry.register<ILoggingState>(
  62. 'features/base/logging',
  63. (state = DEFAULT_STATE, action): ILoggingState => {
  64. switch (action.type) {
  65. case SET_LOGGING_CONFIG:
  66. return _setLoggingConfig(state, action);
  67. case SET_LOG_COLLECTOR: {
  68. return _setLogCollector(state, action);
  69. }
  70. default:
  71. return state;
  72. }
  73. });
  74. /**
  75. * Reduces a specific Redux action SET_LOGGING_CONFIG of the feature
  76. * base/logging.
  77. *
  78. * @param {Object} state - The Redux state of the feature base/logging.
  79. * @param {Action} action - The Redux action SET_LOGGING_CONFIG to reduce.
  80. * @private
  81. * @returns {Object} The new state of the feature base/logging after the
  82. * reduction of the specified action.
  83. */
  84. function _setLoggingConfig(state: ILoggingState, action: AnyAction) {
  85. const newConfig = _.merge({}, DEFAULT_STATE.config, action.config);
  86. if (equals(state.config, newConfig)) {
  87. return state;
  88. }
  89. return {
  90. ...state,
  91. config: newConfig
  92. };
  93. }
  94. /**
  95. * Reduces a specific Redux action SET_LOG_COLLECTOR of the feature
  96. * base/logging.
  97. *
  98. * @param {Object} state - The Redux state of the feature base/logging.
  99. * @param {Action} action - The Redux action SET_LOG_COLLECTOR to reduce.
  100. * @private
  101. * @returns {Object} The new state of the feature base/logging after the
  102. * reduction of the specified action.
  103. */
  104. function _setLogCollector(state: ILoggingState, action: AnyAction) {
  105. return set(state, 'logCollector', action.logCollector);
  106. }