also looking at this
chore: enhance logger
#28
2 files
+12
-4
Review threads live on the whole diff, not on one commit, so none are shown here - a thread's line means something in the branch's final form, and painting it into an intermediate step would put it on code it is not about.
| @@ -1,19 +1,27 @@ | ||
| 1 | import { Logger } from '@stacksjs/clarity' | |
| 1 | 2 | import { config } from './config' |
| 2 | 3 | |
| 4 | // Create a module-level singleton logger for the package | |
| 5 | const baseLogger: any = new (Logger as any)('audiox') | |
| 6 | ||
| 3 | 7 | export function debugLog(category: string, message: string, verbose?: boolean | string[]): void { |
| 4 | 8 | if (verbose === false) { |
| 5 | 9 | return |
| 6 | 10 | } |
| 7 | 11 | |
| 12 | // If a category is provided, instantiate a scoped logger name | |
| 13 | const logger: any = category ? new (Logger as any)(`audiox:${category}`) : baseLogger | |
| 14 | ||
| 8 | 15 | if (verbose === true || config.verbose === true) { |
| 9 | console.debug(message) | |
| 16 | // Use debug level when verbose is explicitly enabled | |
| 17 | logger.debug(message) | |
| 10 | 18 | } |
| 11 | 19 | |
| 12 | 20 | if (Array.isArray(verbose)) { |
| 13 | 21 | // Check if any of the verbose categories match the prefix |
| 14 | 22 | const matches = verbose.some(prefix => category.startsWith(prefix)) |
| 15 | 23 | if (matches) { |
| 16 | console.log(message) | |
| 24 | logger.info(message) | |
| 17 | 25 | } |
| 18 | 26 | } |
| 19 | 27 | |
| @@ -21,7 +29,7 @@ export function debugLog(category: string, message: string, verbose?: boolean | | ||
| 21 | 29 | // Check if any of the verbose categories match the prefix |
| 22 | 30 | const matches = config.verbose.some(prefix => category.startsWith(prefix)) |
| 23 | 31 | if (matches) { |
| 24 | console.log(message) | |
| 32 | logger.info(message) | |
| 25 | 33 | } |
| 26 | 34 | } |
| 27 | 35 | } |