"Fossies" - the Fresh Open Source Software Archive 
Member "jitsi-meet-7309/react/features/base/logging/JitsiMeetLogStorage.ts" (31 May 2023, 4247 Bytes) of package /linux/misc/jitsi-meet-7309.tar.gz:
As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) TypeScript source code syntax highlighting (style:
standard) with prefixed line numbers and
code folding option.
Alternatively you can here
view or
download the uninterpreted source code file.
See also the last
Fossies "Diffs" side-by-side code changes report for "JitsiMeetLogStorage.ts":
7292_vs_7293.
1 import { IStore } from '../../app/types';
2 import RTCStats from '../../rtcstats/RTCStats';
3 import { canSendRtcstatsData } from '../../rtcstats/functions';
4 import { getCurrentConference } from '../conference/functions';
5
6 /**
7 * Implements log storage interface from the @jitsi/logger lib. Captured
8 * logs are sent to CallStats.
9 */
10 export default class JitsiMeetLogStorage {
11 counter: number;
12 getState: IStore['getState'];
13
14 /**
15 * Creates new <tt>JitsiMeetLogStorage</tt>.
16 *
17 * @param {Function} getState - The Redux store's {@code getState} method.
18 */
19 constructor(getState: IStore['getState']) {
20 /**
21 * Counts each log entry, increases on every batch log entry stored.
22 *
23 * @type {number}
24 */
25 this.counter = 1;
26
27 /**
28 * The Redux store's {@code getState} method.
29 *
30 * @type {Function}
31 */
32 this.getState = getState;
33 }
34
35 /**
36 * The JitsiMeetLogStorage is ready when the CallStats are started and
37 * before refactoring the code it was after the conference has been joined.
38 * A conference is considered joined when the 'conference' field is defined
39 * in the base/conference state.
40 *
41 * @returns {boolean} <tt>true</tt> when this storage is ready or
42 * <tt>false</tt> otherwise.
43 */
44 isReady() {
45 const { conference } = this.getState()['features/base/conference'];
46
47 return Boolean(conference);
48 }
49
50 /**
51 * Checks whether rtcstats logs storage is enabled.
52 *
53 * @returns {boolean} <tt>true</tt> when this storage can store logs to
54 * rtcstats, <tt>false</tt> otherwise.
55 */
56 canStoreLogsRtcstats() {
57
58 const config = this.getState()['features/base/config'];
59
60 // Saving the logs in RTCStats is a new feature and so there is no prior behavior that needs to be maintained.
61 // That said, this is still experimental and needs to be rolled out gradually so we want this to be off by
62 // default.
63 return config?.analytics?.rtcstatsStoreLogs && canSendRtcstatsData(this.getState());
64 }
65
66 /**
67 * Called by the <tt>LogCollector</tt> to store a series of log lines into
68 * batch.
69 *
70 * @param {Array<string|Object>} logEntries - An array containing strings
71 * representing log lines or aggregated lines objects.
72 * @returns {void}
73 */
74 storeLogs(logEntries: Array<string | any>) {
75
76 // XXX the config.callStatsApplicationLogsDisabled controls whether or not the logs will be sent to callstats.
77 // this is done in LJM
78 this.storeLogsCallstats(logEntries);
79
80 if (this.canStoreLogsRtcstats()) {
81 RTCStats.sendLogs(logEntries);
82 }
83 }
84
85 /**
86 * Store the console logs in callstats (if callstats is enabled).
87 *
88 * @param {Array<string|any>} logEntries - The log entries to send to the rtcstats server.
89 * @returns {void}
90 */
91 storeLogsCallstats(logEntries: Array<string | any>) {
92 const conference = getCurrentConference(this.getState());
93
94 if (!conference?.isCallstatsEnabled()) {
95 // Discard the logs if CallStats is not enabled.
96 return;
97 }
98
99 let logMessage = `{"log${this.counter}":"\n`;
100
101 for (let i = 0, len = logEntries.length; i < len; i++) {
102 const logEntry = logEntries[i];
103
104 if (logEntry.timestamp) {
105 logMessage += `${logEntry.timestamp} `;
106 }
107 if (logEntry.count > 1) {
108 logMessage += `(${logEntry.count}) `;
109 }
110 logMessage += `${logEntry.text}\n`;
111 }
112 logMessage += '"}';
113
114 this.counter += 1;
115
116 // Try catch was used, because there are many variables
117 // on the way that could be uninitialized if the storeLogs
118 // attempt would be made very early (which is unlikely)
119 try {
120 conference.sendApplicationLog(logMessage);
121 } catch (error) {
122 // NOTE console is intentional here
123 console.error(
124 `Failed to store the logs, msg length: ${logMessage.length}`
125 + `error: ${JSON.stringify(error)}`);
126 }
127 }
128 }