Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 3 commits into from
Apr 24, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

where does logEntry.text come from ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh I see it's an aggregated msg

} 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.