File size: 1,139 Bytes
246d201
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/* eslint-disable no-console */

/**

 * A utility class for logging events. This class will only log events in development mode.

 */
class EventLogger {
  static isDevMode = process.env.NODE_ENV === "development";

  /**

   * Format and log a message event

   * @param event The raw event object

   */
  static message(event: MessageEvent) {
    if (this.isDevMode) {
      console.warn(JSON.stringify(JSON.parse(event.data.toString()), null, 2));
    }
  }

  /**

   * Log an event with a name

   * @param event The raw event object

   * @param name The name of the event

   */
  static event(event: Event, name?: string) {
    if (this.isDevMode) {
      console.warn(name || "EVENT", event);
    }
  }

  /**

   * Log a warning message

   * @param warning The warning message

   */
  static warning(warning: string) {
    if (this.isDevMode) {
      console.warn(warning);
    }
  }

  /**

   * Log an error message

   * @param error The error message

   */
  static error(error: string) {
    if (this.isDevMode) {
      console.error(error);
    }
  }
}

export default EventLogger;