|
| 1 | +# Skill: Use log.debug Instead of console.log |
| 2 | + |
| 3 | +When adding debug logging in JavaScript/TypeScript files in this codebase, use the `@deephaven/log` module instead of `console.log` or `console.debug`. |
| 4 | + |
| 5 | +## Pattern |
| 6 | + |
| 7 | +1. **Import the Log module** at the top of the file: |
| 8 | + ```typescript |
| 9 | + import Log from '@deephaven/log'; |
| 10 | + ``` |
| 11 | + |
| 12 | +2. **Create a module-specific logger** after imports: |
| 13 | + ```typescript |
| 14 | + const log = Log.module('ModuleName'); |
| 15 | + ``` |
| 16 | + Replace `'ModuleName'` with the name of the current file/module (e.g., `'ChartUtils'`, `'TableUtils'`). |
| 17 | + |
| 18 | +3. **Use the logger** for debug output: |
| 19 | + ```typescript |
| 20 | + log.debug('message', data); |
| 21 | + log.debug2('more verbose message', data); // For very verbose logging |
| 22 | + ``` |
| 23 | + |
| 24 | +## Why |
| 25 | + |
| 26 | +- Consistent logging across the codebase |
| 27 | +- Log levels can be configured at runtime |
| 28 | +- Module-specific filtering is possible |
| 29 | +- Avoids ESLint `no-console` warnings |
| 30 | +- Better production behavior (logs can be silenced) |
| 31 | + |
| 32 | +## Example |
| 33 | + |
| 34 | +```typescript |
| 35 | +import Log from '@deephaven/log'; |
| 36 | + |
| 37 | +const log = Log.module('MyComponent'); |
| 38 | + |
| 39 | +function processData(data: SomeType): void { |
| 40 | + log.debug('Processing data:', data); |
| 41 | + // ... processing logic |
| 42 | + log.debug2('Detailed step completed'); |
| 43 | +} |
| 44 | +``` |
| 45 | + |
| 46 | +## Avoid |
| 47 | + |
| 48 | +```typescript |
| 49 | +// ❌ Don't use console directly |
| 50 | +console.log('Processing data:', data); |
| 51 | +console.debug('Step completed'); |
| 52 | + |
| 53 | +// ❌ Don't add eslint-disable for console |
| 54 | +// eslint-disable-next-line no-console |
| 55 | +console.log('debug info'); |
| 56 | +``` |
0 commit comments