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,12 +1,14 @@ | ||
| 1 | 1 | import type { AudioxOptions } from '../src/types' |
| 2 | 2 | import process from 'node:process' |
| 3 | 3 | import { CLI } from '@stacksjs/clapp' |
| 4 | import { Logger } from '@stacksjs/clarity' | |
| 4 | 5 | import { version } from '../package.json' |
| 5 | 6 | import { audio } from '../src/audio' |
| 6 | 7 | import { audioInfo } from '../src/audio-info' |
| 7 | 8 | import { debugLog } from '../src/utils' |
| 8 | 9 | |
| 9 | 10 | const cli = new CLI('audiox') |
| 11 | const logger = new Logger('cli') | |
| 10 | 12 | |
| 11 | 13 | cli |
| 12 | 14 | .command('convert <input> [output]', 'Convert audio file to different format/settings') |
| @@ -68,7 +70,7 @@ cli | ||
| 68 | 70 | debugLog('cli', 'Conversion complete', options.verbose) |
| 69 | 71 | } |
| 70 | 72 | catch (error: any) { |
| 71 | console.error('Error:', error.message) | |
| 73 | await logger.error('Error:', error.message) | |
| 72 | 74 | process.exit(1) |
| 73 | 75 | } |
| 74 | 76 | }) |
| @@ -89,39 +91,39 @@ cli | ||
| 89 | 91 | const info = await audioInfo(input, infoOptions) |
| 90 | 92 | |
| 91 | 93 | // Pretty print the audio information |
| 92 | console.log('\nAudio Information:') | |
| 93 | console.log('----------------') | |
| 94 | await logger.info('\nAudio Information:') | |
| 95 | await logger.info('----------------') | |
| 94 | 96 | for (const stream of info) { |
| 95 | console.log(`Codec: ${stream.codec}`) | |
| 96 | console.log(`Channels: ${stream.channels}`) | |
| 97 | console.log(`Sample Rate: ${stream.sampleRate} Hz`) | |
| 98 | console.log(`Bitrate: ${Math.round(Number.parseInt(stream.bitrate) / 1000)}k`) | |
| 99 | console.log(`Duration: ${Math.round(Number.parseFloat(stream.duration) * 100) / 100}s`) | |
| 97 | await logger.info(`Codec: ${stream.codec}`) | |
| 98 | await logger.info(`Channels: ${stream.channels}`) | |
| 99 | await logger.info(`Sample Rate: ${stream.sampleRate} Hz`) | |
| 100 | await logger.info(`Bitrate: ${Math.round(Number.parseInt(stream.bitrate) / 1000)}k`) | |
| 101 | await logger.info(`Duration: ${Math.round(Number.parseFloat(stream.duration) * 100) / 100}s`) | |
| 100 | 102 | |
| 101 | 103 | if (stream.metadata && Object.keys(stream.metadata).length > 0) { |
| 102 | console.log('\nMetadata:') | |
| 104 | await logger.info('\nMetadata:') | |
| 103 | 105 | for (const [key, value] of Object.entries(stream.metadata)) { |
| 104 | console.log(`${key}: ${value}`) | |
| 106 | await logger.info(`${key}: ${value}`) | |
| 105 | 107 | } |
| 106 | 108 | } |
| 107 | console.log('----------------') | |
| 109 | await logger.info('----------------') | |
| 108 | 110 | } |
| 109 | 111 | } |
| 110 | 112 | catch (error: any) { |
| 111 | console.error('Error:', error.message) | |
| 113 | await logger.error('Error:', error.message) | |
| 112 | 114 | process.exit(1) |
| 113 | 115 | } |
| 114 | 116 | }) |
| 115 | 117 | |
| 116 | 118 | cli |
| 117 | 119 | .command('completion', 'Generate shell completion script') |
| 118 | .action(() => { | |
| 120 | .action(async () => { | |
| 119 | 121 | // TODO: Implement shell completion generation |
| 120 | console.log('Shell completion not implemented yet') | |
| 122 | await logger.info('Shell completion not implemented yet') | |
| 121 | 123 | }) |
| 122 | 124 | |
| 123 | cli.command('version', 'Show the version of the Reverse Proxy CLI').action(() => { | |
| 124 | console.log(version) | |
| 125 | cli.command('version', 'Show the version of the Reverse Proxy CLI').action(async () => { | |
| 126 | await logger.info(version) | |
| 125 | 127 | }) |
| 126 | 128 | |
| 127 | 129 | cli.version(version) |
| @@ -1,6 +1,8 @@ | ||
| 1 | import { Logger } from '@stacksjs/clarity' | |
| 1 | 2 | import { dts } from 'bun-plugin-dtsx' |
| 2 | 3 | |
| 3 | console.log('Building...') | |
| 4 | const logger = new Logger('build') | |
| 5 | await logger.info('Building...') | |
| 4 | 6 | |
| 5 | 7 | await Bun.build({ |
| 6 | 8 | entrypoints: ['./src/index.ts', './bin/cli.ts'], |
| @@ -12,4 +14,4 @@ await Bun.build({ | ||
| 12 | 14 | plugins: [dts()], |
| 13 | 15 | }) |
| 14 | 16 | |
| 15 | console.log('Built') | |
| 17 | await logger.success('Built') | |
| @@ -6,6 +6,7 @@ | ||
| 6 | 6 | "devDependencies": { |
| 7 | 7 | "@stacksjs/bumpx": "^0.1.17", |
| 8 | 8 | "@stacksjs/clapp": "^0.1.16", |
| 9 | "@stacksjs/clarity": "^0.3.17", | |
| 9 | 10 | "@stacksjs/docs": "^0.70.23", |
| 10 | 11 | "@stacksjs/eslint-config": "^3.13.1-beta.2", |
| 11 | 12 | "@stacksjs/gitlint": "^0.1.5", |
| @@ -501,6 +502,8 @@ | ||
| 501 | 502 | |
| 502 | 503 | "@stacksjs/clapp": ["@stacksjs/clapp@0.1.16", "", { "bin": { "clapp": "dist/bin/cli.js", "@stacksjs/clapp": "dist/bin/cli.js" } }, "sha512-BDmYu9Rk/HHIVc4vQjgQO6MzXNMJvPG6ZGiiEAPQT8EAidx3/6S6O7kyY2UdfJSksiCd5SKFK+WYd1uAs88BrQ=="], |
| 503 | 504 | |
| 505 | "@stacksjs/clarity": ["@stacksjs/clarity@0.3.17", "", { "bin": { "clarity": "dist/bin/cli.js" } }, "sha512-uopKQuFzed7y5RvIyYmswjEDbh/vvt8szJpa+BfdLrZyXmmfZH900DuAvWhmrQd1uu1Lq0a7E/aVagP7ocf//A=="], | |
| 506 | ||
| 504 | 507 | "@stacksjs/docs": ["@stacksjs/docs@0.70.23", "", { "dependencies": { "@iconify-json/carbon": "^1.2.8", "@shikijs/vitepress-twoslash": "^3.2.1", "@vite-pwa/assets-generator": "^1.0.0", "@vite-pwa/vitepress": "^1.0.0", "unocss": "^66.0.0", "unplugin-icons": "^22.1.0", "unplugin-vue-components": "^28.4.1", "vite-plugin-pwa": "^1.0.0", "vitepress": "1.6.3" } }, "sha512-kRk/aza/wQAAgF0fhUhG8bUHhqk3RnjBkZyoRW0fvYs3dLaAArJYX/uVquZixlQnqgizGeGZT986tEFjs5Ly+A=="], |
| 505 | 508 | |
| 506 | 509 | "@stacksjs/dtsx": ["@stacksjs/dtsx@0.8.1", "", { "bin": { "dtsx": "dist/cli.js" } }, "sha512-QjCoPsmxfd3VJA2+G/pa6wA1sYPzC0S9wUuJPRCtWlcGWBTUvz9nFLBxdKWwbvIJBJ9gc7BmIoAo18pvTlvSRg=="], |
| @@ -1,21 +1,24 @@ | ||
| 1 | import { Logger } from '@stacksjs/clarity' | |
| 1 | 2 | import { config } from './config' |
| 2 | 3 | |
| 4 | const baseLogger = new Logger('audiox') | |
| 5 | ||
| 3 | 6 | export function debugLog(category: string, message: string, verbose?: boolean | string[]): void { |
| 4 | 7 | if (verbose === false) { |
| 5 | 8 | return |
| 6 | 9 | } |
| 7 | 10 | |
| 11 | const logger = baseLogger.extend(category) | |
| 12 | ||
| 8 | 13 | if (verbose === true || config.verbose === true) { |
| 9 | // eslint-disable-next-line no-console | |
| 10 | console.debug(`[audiox:${category}] ${message}`) | |
| 14 | logger.debug(message) | |
| 11 | 15 | } |
| 12 | 16 | |
| 13 | 17 | if (Array.isArray(verbose)) { |
| 14 | 18 | // Check if any of the verbose categories match the prefix |
| 15 | 19 | const matches = verbose.some(prefix => category.startsWith(prefix)) |
| 16 | 20 | if (matches) { |
| 17 | // eslint-disable-next-line no-console | |
| 18 | console.log(`[audiox:${category}] ${message}`) | |
| 21 | logger.info(message) | |
| 19 | 22 | } |
| 20 | 23 | } |
| 21 | 24 | |
| @@ -23,8 +26,7 @@ export function debugLog(category: string, message: string, verbose?: boolean | | ||
| 23 | 26 | // Check if any of the verbose categories match the prefix |
| 24 | 27 | const matches = config.verbose.some(prefix => category.startsWith(prefix)) |
| 25 | 28 | if (matches) { |
| 26 | // eslint-disable-next-line no-console | |
| 27 | console.log(`[audiox:${category}] ${message}`) | |
| 29 | logger.info(message) | |
| 28 | 30 | } |
| 29 | 31 | } |
| 30 | 32 | } |