(context: string)
| 125 | * Create a logger instance with a context prefix |
| 126 | */ |
| 127 | export function createLogger(context: string): Logger { |
| 128 | if (isBrowser) { |
| 129 | // Browser implementation with CSS styling |
| 130 | return { |
| 131 | error: (...args: unknown[]): void => { |
| 132 | if (currentLogLevel >= LogLevel.ERROR) { |
| 133 | console.error( |
| 134 | `%cERROR%c %c${formatShortTime()}%c %c[${context}]%c`, |
| 135 | BROWSER_STYLES.levels.ERROR, |
| 136 | BROWSER_STYLES.reset, |
| 137 | BROWSER_STYLES.timestamp, |
| 138 | BROWSER_STYLES.reset, |
| 139 | BROWSER_STYLES.context, |
| 140 | BROWSER_STYLES.reset, |
| 141 | ...args |
| 142 | ); |
| 143 | } |
| 144 | }, |
| 145 | |
| 146 | warn: (...args: unknown[]): void => { |
| 147 | if (currentLogLevel >= LogLevel.WARN) { |
| 148 | console.warn( |
| 149 | `%cWARN%c %c${formatShortTime()}%c %c[${context}]%c`, |
| 150 | BROWSER_STYLES.levels.WARN, |
| 151 | BROWSER_STYLES.reset, |
| 152 | BROWSER_STYLES.timestamp, |
| 153 | BROWSER_STYLES.reset, |
| 154 | BROWSER_STYLES.context, |
| 155 | BROWSER_STYLES.reset, |
| 156 | ...args |
| 157 | ); |
| 158 | } |
| 159 | }, |
| 160 | |
| 161 | info: (...args: unknown[]): void => { |
| 162 | if (currentLogLevel >= LogLevel.INFO) { |
| 163 | console.log( |
| 164 | `%cINFO%c %c${formatShortTime()}%c %c[${context}]%c`, |
| 165 | BROWSER_STYLES.levels.INFO, |
| 166 | BROWSER_STYLES.reset, |
| 167 | BROWSER_STYLES.timestamp, |
| 168 | BROWSER_STYLES.reset, |
| 169 | BROWSER_STYLES.context, |
| 170 | BROWSER_STYLES.reset, |
| 171 | ...args |
| 172 | ); |
| 173 | } |
| 174 | }, |
| 175 | |
| 176 | debug: (...args: unknown[]): void => { |
| 177 | if (currentLogLevel >= LogLevel.DEBUG) { |
| 178 | console.log( |
| 179 | `%cDEBUG%c %c${formatShortTime()}%c %c[${context}]%c`, |
| 180 | BROWSER_STYLES.levels.DEBUG, |
| 181 | BROWSER_STYLES.reset, |
| 182 | BROWSER_STYLES.timestamp, |
| 183 | BROWSER_STYLES.reset, |
| 184 | BROWSER_STYLES.context, |
no test coverage detected