ReviewOS

also looking at this

stacks/ts-audio

chore: enhance logger

#28
Merged cab-mikee wants to merge chore/enhance-logger into main
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.

src/types.tsmodified+1-1
Changes to src/types.ts
@@ -14,7 +14,7 @@ export interface AudioxOptions {
1414 [key: string]: string
1515 }
1616 onError?: (error: unknown) => void
17 verbose: boolean
17 verbose: boolean | string[]
1818}
1919
2020export interface FfmpegAudioOptionsWithStreamOut {
src/utils.tsmodified+11-3
Changes to src/utils.ts
@@ -1,19 +1,27 @@
1import { Logger } from '@stacksjs/clarity'
12import { config } from './config'
23
4// Create a module-level singleton logger for the package
5const baseLogger: any = new (Logger as any)('audiox')
6
37export function debugLog(category: string, message: string, verbose?: boolean | string[]): void {
48 if (verbose === false) {
59 return
610 }
711
12 // If a category is provided, instantiate a scoped logger name
13 const logger: any = category ? new (Logger as any)(`audiox:${category}`) : baseLogger
14
815 if (verbose === true || config.verbose === true) {
9 console.debug(message)
16 // Use debug level when verbose is explicitly enabled
17 logger.debug(message)
1018 }
1119
1220 if (Array.isArray(verbose)) {
1321 // Check if any of the verbose categories match the prefix
1422 const matches = verbose.some(prefix => category.startsWith(prefix))
1523 if (matches) {
16 console.log(message)
24 logger.info(message)
1725 }
1826 }
1927
@@ -21,7 +29,7 @@ export function debugLog(category: string, message: string, verbose?: boolean |
2129 // Check if any of the verbose categories match the prefix
2230 const matches = config.verbose.some(prefix => category.startsWith(prefix))
2331 if (matches) {
24 console.log(message)
32 logger.info(message)
2533 }
2634 }
2735}