Skip to content

Commit

Permalink
Adds in memory log storage, to be used while testing. (jitsi#2858)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
damencho authored and guusdk committed May 11, 2018
1 parent 8e43520 commit aae8126
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 2 deletions.
50 changes: 50 additions & 0 deletions modules/util/JitsiMeetInMemoryLogStorage.js
Original file line number Diff line number Diff line change
@@ -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;
}
}
20 changes: 18 additions & 2 deletions react/features/base/logging/middleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand All @@ -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();
}
}
}

Expand Down Expand Up @@ -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.
Expand All @@ -131,7 +147,7 @@ function _setLoggingConfig({ getState }, next, action) {
_setLogLevels(Logger, newValue);
_setLogLevels(JitsiMeetJS, newValue);

_initLogging(newValue);
_initLogging(newValue, isTestingEnabled);

return result;
}
Expand Down
Empty file.

0 comments on commit aae8126

Please sign in to comment.