jiti-meet/react/features/base/logging/JitsiMeetLogStorage.ts

148 lines
4.8 KiB
TypeScript
Raw Permalink Normal View History

/* eslint-disable lines-around-comment */
// @ts-ignore
import RTCStats from '../../rtcstats/RTCStats';
// @ts-ignore
import { canSendRtcstatsData } from '../../rtcstats/functions';
2022-08-04 08:51:33 +00:00
// @ts-ignore
import { getCurrentConference } from '../conference';
/**
* Implements log storage interface from the @jitsi/logger lib. Captured
* logs are sent to CallStats.
*/
export default class JitsiMeetLogStorage {
2022-08-04 08:51:33 +00:00
counter: number;
getState: Function;
/**
* Creates new <tt>JitsiMeetLogStorage</tt>.
*
* @param {Function} getState - The Redux store's {@code getState} method.
*/
2022-08-04 08:51:33 +00:00
constructor(getState: Function) {
/**
* Counts each log entry, increases on every batch log entry stored.
2021-11-04 21:10:43 +00:00
*
* @type {number}
*/
this.counter = 1;
/**
* The Redux store's {@code getState} method.
*
* @type {Function}
*/
this.getState = getState;
}
/**
* 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.
*
* @returns {boolean} <tt>true</tt> when this storage is ready or
* <tt>false</tt> otherwise.
*/
isReady() {
const { conference } = this.getState()['features/base/conference'];
return Boolean(conference);
}
/**
* Checks whether callstats logs storage is enabled.
*
* @returns {boolean} <tt>true</tt> when this storage can store logs to
* callstats, <tt>false</tt> otherwise.
*/
canStoreLogsCallstats() {
const { callstatsStoreLogs } = this.getState()['features/base/config'];
// The behavior prior to adding this configuration parameter, is to send logs to callstats (if callstats is
// enabled). So, in order to maintain backwards compatibility I set the default of this option to be true, i.e.
// if the config.callstatsStoreLogs is not set, the JS console logs will be sent to callstats (if callstats is
// enabled)
return callstatsStoreLogs || callstatsStoreLogs === undefined;
}
/**
* 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());
}
/**
* Called by the <tt>LogCollector</tt> to store a series of log lines into
* batch.
*
* @param {Array<string|Object>} logEntries - An array containing strings
* representing log lines or aggregated lines objects.
* @returns {void}
*/
storeLogs(logEntries: Array<string | any>) {
if (this.canStoreLogsCallstats()) {
this.storeLogsCallstats(logEntries);
}
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}
*/
storeLogsCallstats(logEntries: Array<string | any>) {
const conference = getCurrentConference(this.getState());
if (!conference || !conference.isCallstatsEnabled()) {
// Discard the logs if CallStats is not enabled.
return;
}
Restructures the analytics events (#2333) * ref: Restructures the pinned/unpinned events. * ref: Refactors the "audio only disabled" event. * ref: Refactors the "stream switch delay" event. * ref: Refactors the "select participant failed" event. * ref: Refactors the "initially muted" events. * ref: Refactors the screen sharing started/stopped events. * ref: Restructures the "device list changed" events. * ref: Restructures the "shared video" events. * ref: Restructures the "start muted" events. * ref: Restructures the "start audio only" event. * ref: Restructures the "sync track state" event. * ref: Restructures the "callkit" events. * ref: Restructures the "replace track". * ref: Restructures keyboard shortcuts events. * ref: Restructures most of the toolbar events. * ref: Refactors the API events. * ref: Restructures the video quality, profile button and invite dialog events. * ref: Refactors the "device changed" events. * ref: Refactors the page reload event. * ref: Removes an unused function. * ref: Removes a method which is needlessly exposed under a different name. * ref: Refactors the events from the remote video menu. * ref: Refactors the events from the profile pane. * ref: Restructures the recording-related events. Removes events fired when recording with something other than jibri (which isn't currently supported anyway). * ref: Cleans up AnalyticsEvents.js. * ref: Removes an unused function and adds documentation. * feat: Adds events for all API calls. * fix: Addresses feedback. * fix: Brings back mistakenly removed code. * fix: Simplifies code and fixes a bug in toggleFilmstrip when the 'visible' parameter is defined. * feat: Removes the resolution change application log. * ref: Uses consistent naming for events' attributes. Uses "_" as a separator instead of camel case or ".". * ref: Don't add the user agent and conference name as permanent properties. The library does this on its own now. * ref: Adapts the GA handler to changes in lib-jitsi-meet. * ref: Removes unused fields from the analytics handler initializaiton. * ref: Renames the google analytics file and add docs. * fix: Fixes the push-to-talk events and logs. * npm: Updates lib-jitsi-meet to 515374c8d383cb17df8ed76427e6f0fb5ea6ff1e. * fix: Fixes a recently introduced bug in the google analytics handler. * ref: Uses "value" instead of "delay" since this is friendlier to GA.
2018-01-03 21:24:07 +00:00
let logMessage = `{"log${this.counter}":"\n`;
for (let i = 0, len = logEntries.length; i < len; i++) {
const logEntry = logEntries[i];
if (logEntry.timestamp) {
logMessage += `${logEntry.timestamp} `;
}
if (logEntry.count > 1) {
logMessage += `(${logEntry.count}) `;
}
logMessage += `${logEntry.text}\n`;
}
Restructures the analytics events (#2333) * ref: Restructures the pinned/unpinned events. * ref: Refactors the "audio only disabled" event. * ref: Refactors the "stream switch delay" event. * ref: Refactors the "select participant failed" event. * ref: Refactors the "initially muted" events. * ref: Refactors the screen sharing started/stopped events. * ref: Restructures the "device list changed" events. * ref: Restructures the "shared video" events. * ref: Restructures the "start muted" events. * ref: Restructures the "start audio only" event. * ref: Restructures the "sync track state" event. * ref: Restructures the "callkit" events. * ref: Restructures the "replace track". * ref: Restructures keyboard shortcuts events. * ref: Restructures most of the toolbar events. * ref: Refactors the API events. * ref: Restructures the video quality, profile button and invite dialog events. * ref: Refactors the "device changed" events. * ref: Refactors the page reload event. * ref: Removes an unused function. * ref: Removes a method which is needlessly exposed under a different name. * ref: Refactors the events from the remote video menu. * ref: Refactors the events from the profile pane. * ref: Restructures the recording-related events. Removes events fired when recording with something other than jibri (which isn't currently supported anyway). * ref: Cleans up AnalyticsEvents.js. * ref: Removes an unused function and adds documentation. * feat: Adds events for all API calls. * fix: Addresses feedback. * fix: Brings back mistakenly removed code. * fix: Simplifies code and fixes a bug in toggleFilmstrip when the 'visible' parameter is defined. * feat: Removes the resolution change application log. * ref: Uses consistent naming for events' attributes. Uses "_" as a separator instead of camel case or ".". * ref: Don't add the user agent and conference name as permanent properties. The library does this on its own now. * ref: Adapts the GA handler to changes in lib-jitsi-meet. * ref: Removes unused fields from the analytics handler initializaiton. * ref: Renames the google analytics file and add docs. * fix: Fixes the push-to-talk events and logs. * npm: Updates lib-jitsi-meet to 515374c8d383cb17df8ed76427e6f0fb5ea6ff1e. * fix: Fixes a recently introduced bug in the google analytics handler. * ref: Uses "value" instead of "delay" since this is friendlier to GA.
2018-01-03 21:24:07 +00:00
logMessage += '"}';
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 {
conference.sendApplicationLog(logMessage);
} catch (error) {
// NOTE console is intentional here
console.error(
`Failed to store the logs, msg length: ${logMessage.length}`
+ `error: ${JSON.stringify(error)}`);
}
}
}