2022-08-25 12:41:05 +00:00
|
|
|
import RTCStats from '../../rtcstats/RTCStats';
|
|
|
|
import { canSendRtcstatsData } from '../../rtcstats/functions';
|
2022-09-30 09:08:03 +00:00
|
|
|
import { getCurrentConference } from '../conference/functions';
|
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 {
|
2022-08-04 08:51:33 +00:00
|
|
|
counter: number;
|
|
|
|
getState: Function;
|
2016-11-29 17:28:42 +00:00
|
|
|
|
|
|
|
/**
|
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
|
|
|
*/
|
2022-08-04 08:51:33 +00:00
|
|
|
constructor(getState: Function) {
|
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
|
|
|
}
|
|
|
|
|
2022-08-25 12:41:05 +00:00
|
|
|
/**
|
|
|
|
* Checks whether rtcstats logs storage is enabled.
|
|
|
|
*
|
|
|
|
* @returns {boolean} <tt>true</tt> when this storage can store logs to
|
|
|
|
* rtcstats, <tt>false</tt> otherwise.
|
|
|
|
*/
|
|
|
|
canStoreLogsRtcstats() {
|
|
|
|
|
|
|
|
const config = this.getState()['features/base/config'];
|
|
|
|
|
|
|
|
// Saving the logs in RTCStats is a new feature and so there is no prior behavior that needs to be maintained.
|
|
|
|
// That said, this is still experimental and needs to be rolled out gradually so we want this to be off by
|
|
|
|
// default.
|
|
|
|
return config?.analytics?.rtcstatsStoreLogs && canSendRtcstatsData(this.getState());
|
|
|
|
}
|
|
|
|
|
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
|
|
|
*/
|
2022-09-08 09:52:36 +00:00
|
|
|
storeLogs(logEntries: Array<string | any>) {
|
2022-08-25 12:41:05 +00:00
|
|
|
|
2022-09-16 14:15:52 +00:00
|
|
|
// XXX the config.callStatsApplicationLogsDisabled controls whether or not the logs will be sent to callstats.
|
|
|
|
// this is done in LJM
|
|
|
|
this.storeLogsCallstats(logEntries);
|
2022-08-25 12:41:05 +00:00
|
|
|
|
|
|
|
if (this.canStoreLogsRtcstats()) {
|
|
|
|
RTCStats.sendLogs(logEntries);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Store the console logs in callstats (if callstats is enabled).
|
|
|
|
*
|
|
|
|
* @param {Array<string|any>} logEntries - The log entries to send to the rtcstats server.
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
2022-09-08 09:52:36 +00:00
|
|
|
storeLogsCallstats(logEntries: Array<string | any>) {
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|