Adds in memory log storage, to be used while testing. (#2858)

* Adds in memory log storage, to be used while testing.

Enabling it only when config.debug is set, a configuration provided by jitsi-meet-torture.

* Moves to using config.testing.testMode property for logs storage.

* Fixes comments.
This commit is contained in:
Дамян Минков 2018-04-24 13:56:54 -05:00 committed by Paweł Domas
parent d7103c1c4c
commit 8b1aff5512
3 changed files with 68 additions and 2 deletions

View File

@ -0,0 +1,50 @@
/**
* Implements in memory logs storage, used for testing/debugging.
*/
export default class JitsiMeetInMemoryLogStorage {
/**
* Creates new <tt>JitsiMeetInMemoryLogStorage</tt>
*/
constructor() {
/**
* Array of the log entries to keep.
* @type {array}
*/
this.logs = [];
}
/**
* @returns {boolean} <tt>true</tt> when this storage is ready or
* <tt>false</tt> otherwise.
*/
isReady() {
return true;
}
/**
* Called by the <tt>LogCollector</tt> to store a series of log lines into
* batch.
* @param {string|object[]} logEntries an array containing strings
* representing log lines or aggregated lines objects.
*/
storeLogs(logEntries) {
for (let i = 0, len = logEntries.length; i < len; i++) {
const logEntry = logEntries[i];
if (typeof logEntry === 'object') {
this.logs.push(logEntry.text);
} else {
// Regular message
this.logs.push(logEntry);
}
}
}
/**
* @returns {array} the collected log entries.
*/
getLogs() {
return this.logs;
}
}

View File

@ -6,8 +6,12 @@ import { APP_WILL_MOUNT } from '../../app';
import JitsiMeetJS, { LIB_WILL_INIT } from '../lib-jitsi-meet';
import { MiddlewareRegistry } from '../redux';
import JitsiMeetInMemoryLogStorage
from '../../../../modules/util/JitsiMeetInMemoryLogStorage';
import JitsiMeetLogStorage from '../../../../modules/util/JitsiMeetLogStorage';
import { isTestModeEnabled } from '../testing';
import { SET_LOGGING_CONFIG } from './actionTypes';
declare var APP: Object;
@ -67,10 +71,11 @@ function _appWillMount({ getState }, next, action) {
*
* @param {Object} loggingConfig - The configuration with which logging is to be
* initialized.
* @param {boolean} isTestingEnabled - Is debug logging enabled.
* @private
* @returns {void}
*/
function _initLogging(loggingConfig) {
function _initLogging(loggingConfig, isTestingEnabled) {
// Create the LogCollector and register it as the global log transport. It
// is done early to capture as much logs as possible. Captured logs will be
// cached, before the JitsiMeetLogStorage gets ready (statistics module is
@ -81,6 +86,16 @@ function _initLogging(loggingConfig) {
APP.logCollector = new Logger.LogCollector(new JitsiMeetLogStorage());
Logger.addGlobalTransport(APP.logCollector);
JitsiMeetJS.addGlobalLogTransport(APP.logCollector);
if (isTestingEnabled) {
APP.debugLogs = new JitsiMeetInMemoryLogStorage();
const debugLogCollector = new Logger.LogCollector(
APP.debugLogs, { storeInterval: 1000 });
Logger.addGlobalTransport(debugLogCollector);
JitsiMeetJS.addGlobalLogTransport(debugLogCollector);
debugLogCollector.start();
}
}
}
@ -121,6 +136,7 @@ function _libWillInit({ getState }, next, action) {
function _setLoggingConfig({ getState }, next, action) {
const result = next(action);
const newValue = getState()['features/base/logging'].config;
const isTestingEnabled = isTestModeEnabled(getState());
// TODO Generally, we'll want to _setLogLevels and _initLogging only if the
// logging config values actually change.
@ -131,7 +147,7 @@ function _setLoggingConfig({ getState }, next, action) {
_setLogLevels(Logger, newValue);
_setLogLevels(JitsiMeetJS, newValue);
_initLogging(newValue);
_initLogging(newValue, isTestingEnabled);
return result;
}