File size: 1,089 Bytes
2f49513
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
/* eslint-disable no-console */
/**
 * Logger utility that only logs messages in development mode or when debug parameter is present
 */

// Check if we're in development mode
const isDevelopment = process.env.NODE_ENV === "development";

// Check if debug parameter is in URL
const hasDebugParam = (): boolean => {
  if (typeof window !== "undefined") {
    const urlParams = new URLSearchParams(window.location.search);
    return urlParams.has("debug");
  }
  return false;
};

// Only log if in development mode or debug param is present
const shouldLog = (): boolean => isDevelopment || hasDebugParam();

const logger = {
  log: (...args: unknown[]): void => {
    if (shouldLog()) {
      console.log(...args);
    }
  },

  warn: (...args: unknown[]): void => {
    if (shouldLog()) {
      console.warn(...args);
    }
  },

  error: (...args: unknown[]): void => {
    // Always log errors regardless of environment
    console.error(...args);
  },

  info: (...args: unknown[]): void => {
    if (shouldLog()) {
      console.info(...args);
    }
  },
};

export default logger;