You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

JitsiMeetLogStorage.js 2.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. import { getCurrentConference } from '../../react/features/base/conference';
  2. /**
  3. * Implements logs storage through the CallStats.
  4. *
  5. * FIXME: move to base/logging
  6. */
  7. export default class JitsiMeetLogStorage {
  8. /**
  9. * Creates new <tt>JitsiMeetLogStorage</tt>.
  10. *
  11. * @param {Function} getState - the Redux store's {@code getState} method.
  12. */
  13. constructor(getState) {
  14. /**
  15. * Counts each log entry, increases on every batch log entry stored.
  16. * @type {number}
  17. */
  18. this.counter = 1;
  19. /**
  20. * The Redux store's {@code getState} method.
  21. *
  22. * @type {Function}
  23. */
  24. this.getState = getState;
  25. }
  26. /**
  27. * The JitsiMeetLogStorage is ready when the CallStats are started and
  28. * before refactoring the code it was after the conference has been joined.
  29. * A conference is considered joined when the 'conference' field is defined
  30. * in the base/conference state.
  31. *
  32. * @return {boolean} <tt>true</tt> when this storage is ready or
  33. * <tt>false</tt> otherwise.
  34. */
  35. isReady() {
  36. const { conference } = this.getState()['features/base/conference'];
  37. return Boolean(conference);
  38. }
  39. /**
  40. * Called by the <tt>LogCollector</tt> to store a series of log lines into
  41. * batch.
  42. * @param {string|object[]}logEntries an array containing strings
  43. * representing log lines or aggregated lines objects.
  44. */
  45. storeLogs(logEntries) {
  46. const conference = getCurrentConference(this.getState());
  47. if (!conference || !conference.isCallstatsEnabled()) {
  48. // Discard the logs if CallStats is not enabled.
  49. return;
  50. }
  51. let logMessage = `{"log${this.counter}":"\n`;
  52. for (let i = 0, len = logEntries.length; i < len; i++) {
  53. const logEntry = logEntries[i];
  54. if (typeof logEntry === 'object') {
  55. // Aggregated message
  56. logMessage += `(${logEntry.count}) ${logEntry.text}\n`;
  57. } else {
  58. // Regular message
  59. logMessage += `${logEntry}\n`;
  60. }
  61. }
  62. logMessage += '"}';
  63. this.counter += 1;
  64. // Try catch was used, because there are many variables
  65. // on the way that could be uninitialized if the storeLogs
  66. // attempt would be made very early (which is unlikely)
  67. try {
  68. conference.sendApplicationLog(logMessage);
  69. } catch (error) {
  70. // FIXME whole objects logged
  71. // NOTE console is intentional here
  72. console.error(
  73. 'Failed to store the logs: ', logMessage, error);
  74. }
  75. }
  76. }