2018-09-05 20:34:26 +00:00
|
|
|
|
|
|
|
import { getCurrentConference } from '../conference';
|
2016-11-29 17:28:42 +00:00
|
|
|
|
|
|
|
/**
|
2021-11-10 10:11:29 +00:00
|
|
|
* Implements log storage interface from the @jitsi/logger lib. Captured
|
2018-09-05 20:34:26 +00:00
|
|
|
* logs are sent to CallStats.
|
2016-11-29 17:28:42 +00:00
|
|
|
*/
|
|
|
|
export default class JitsiMeetLogStorage {
|
|
|
|
|
|
|
|
/**
|
2018-09-05 20:23:57 +00:00
|
|
|
* Creates new <tt>JitsiMeetLogStorage</tt>.
|
|
|
|
*
|
2018-09-05 20:34:26 +00:00
|
|
|
* @param {Function} getState - The Redux store's {@code getState} method.
|
2016-11-29 17:28:42 +00:00
|
|
|
*/
|
2018-09-05 20:23:57 +00:00
|
|
|
constructor(getState) {
|
2016-11-29 17:28:42 +00:00
|
|
|
/**
|
|
|
|
* Counts each log entry, increases on every batch log entry stored.
|
2021-11-04 21:10:43 +00:00
|
|
|
*
|
2016-11-29 17:28:42 +00:00
|
|
|
* @type {number}
|
|
|
|
*/
|
|
|
|
this.counter = 1;
|
2018-09-05 20:23:57 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The Redux store's {@code getState} method.
|
|
|
|
*
|
|
|
|
* @type {Function}
|
|
|
|
*/
|
|
|
|
this.getState = getState;
|
2016-11-29 17:28:42 +00:00
|
|
|
}
|
|
|
|
|
2016-11-30 13:34:38 +00:00
|
|
|
/**
|
2018-09-05 20:23:57 +00:00
|
|
|
* The JitsiMeetLogStorage is ready when the CallStats are started and
|
|
|
|
* before refactoring the code it was after the conference has been joined.
|
|
|
|
* A conference is considered joined when the 'conference' field is defined
|
|
|
|
* in the base/conference state.
|
|
|
|
*
|
2018-09-05 20:34:26 +00:00
|
|
|
* @returns {boolean} <tt>true</tt> when this storage is ready or
|
2016-11-30 13:34:38 +00:00
|
|
|
* <tt>false</tt> otherwise.
|
|
|
|
*/
|
|
|
|
isReady() {
|
2018-09-05 20:23:57 +00:00
|
|
|
const { conference } = this.getState()['features/base/conference'];
|
|
|
|
|
|
|
|
return Boolean(conference);
|
2016-11-30 13:34:38 +00:00
|
|
|
}
|
|
|
|
|
2016-11-29 17:28:42 +00:00
|
|
|
/**
|
|
|
|
* Called by the <tt>LogCollector</tt> to store a series of log lines into
|
|
|
|
* batch.
|
2018-09-05 20:34:26 +00:00
|
|
|
*
|
|
|
|
* @param {Array<string|Object>} logEntries - An array containing strings
|
2016-11-29 17:28:42 +00:00
|
|
|
* representing log lines or aggregated lines objects.
|
2018-09-05 20:34:26 +00:00
|
|
|
* @returns {void}
|
2016-11-29 17:28:42 +00:00
|
|
|
*/
|
|
|
|
storeLogs(logEntries) {
|
2018-09-05 20:23:57 +00:00
|
|
|
const conference = getCurrentConference(this.getState());
|
2016-11-29 17:28:42 +00:00
|
|
|
|
2018-09-05 20:23:57 +00:00
|
|
|
if (!conference || !conference.isCallstatsEnabled()) {
|
2016-11-30 13:34:38 +00:00
|
|
|
// Discard the logs if CallStats is not enabled.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-01-03 21:24:07 +00:00
|
|
|
let logMessage = `{"log${this.counter}":"\n`;
|
2017-10-12 23:02:29 +00:00
|
|
|
|
2016-11-29 17:28:42 +00:00
|
|
|
for (let i = 0, len = logEntries.length; i < len; i++) {
|
2017-10-12 23:02:29 +00:00
|
|
|
const logEntry = logEntries[i];
|
|
|
|
|
2019-10-15 20:47:23 +00:00
|
|
|
if (logEntry.timestamp) {
|
|
|
|
logMessage += `${logEntry.timestamp} `;
|
2016-11-29 17:28:42 +00:00
|
|
|
}
|
2019-10-15 20:47:23 +00:00
|
|
|
if (logEntry.count > 1) {
|
|
|
|
logMessage += `(${logEntry.count}) `;
|
|
|
|
}
|
|
|
|
logMessage += `${logEntry.text}\n`;
|
2016-11-29 17:28:42 +00:00
|
|
|
}
|
2018-01-03 21:24:07 +00:00
|
|
|
logMessage += '"}';
|
2016-11-29 17:28:42 +00:00
|
|
|
|
|
|
|
this.counter += 1;
|
|
|
|
|
|
|
|
// Try catch was used, because there are many variables
|
|
|
|
// on the way that could be uninitialized if the storeLogs
|
|
|
|
// attempt would be made very early (which is unlikely)
|
|
|
|
try {
|
2018-09-05 20:23:57 +00:00
|
|
|
conference.sendApplicationLog(logMessage);
|
2016-11-29 17:28:42 +00:00
|
|
|
} catch (error) {
|
|
|
|
// NOTE console is intentional here
|
|
|
|
console.error(
|
2018-09-05 20:38:59 +00:00
|
|
|
`Failed to store the logs, msg length: ${logMessage.length}`
|
|
|
|
+ `error: ${JSON.stringify(error)}`);
|
2016-11-29 17:28:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|