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 1.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /* global APP */
  2. /**
  3. * Implements logs storage through the CallStats.
  4. */
  5. export default class JitsiMeetLogStorage {
  6. /**
  7. * Creates new <tt>JitsiMeetLogStorage</tt>
  8. */
  9. constructor() {
  10. /**
  11. * Counts each log entry, increases on every batch log entry stored.
  12. * @type {number}
  13. */
  14. this.counter = 1;
  15. }
  16. /**
  17. * @return {boolean} <tt>true</tt> when this storage is ready or
  18. * <tt>false</tt> otherwise.
  19. */
  20. isReady() {
  21. return Boolean(APP.logCollectorStarted && APP.conference);
  22. }
  23. /**
  24. * Called by the <tt>LogCollector</tt> to store a series of log lines into
  25. * batch.
  26. * @param {string|object[]}logEntries an array containing strings
  27. * representing log lines or aggregated lines objects.
  28. */
  29. storeLogs(logEntries) {
  30. if (!APP.conference.isCallstatsEnabled()) {
  31. // Discard the logs if CallStats is not enabled.
  32. return;
  33. }
  34. let logJSON = `{"log${this.counter}":"\n`;
  35. for (let i = 0, len = logEntries.length; i < len; i++) {
  36. const logEntry = logEntries[i];
  37. if (typeof logEntry === 'object') {
  38. // Aggregated message
  39. logJSON += `(${logEntry.count}) ${logEntry.text}\n`;
  40. } else {
  41. // Regular message
  42. logJSON += `${logEntry}\n`;
  43. }
  44. }
  45. logJSON += '"}';
  46. this.counter += 1;
  47. // Try catch was used, because there are many variables
  48. // on the way that could be uninitialized if the storeLogs
  49. // attempt would be made very early (which is unlikely)
  50. try {
  51. APP.conference.logJSON(logJSON);
  52. } catch (error) {
  53. // NOTE console is intentional here
  54. console.error(
  55. 'Failed to store the logs: ', logJSON, error);
  56. }
  57. }
  58. }