Download src/utils/logger.ts from Collabos/chatapi: direct link, hf CLI and curl.
- Browser
- Download file 967 Bytes
-
https://huggingface.co/spaces/Collabos/chatapi/resolve/main/src/utils/logger.ts
- Command line
-
hf download hf://spaces/Collabos/chatapi/src/utils/logger.ts
-
curl -L -o logger.ts https://huggingface.co/spaces/Collabos/chatapi/resolve/main/src/utils/logger.ts
967 Bytes
| import { CONFIG } from '../config'; | |
| type Level = 'info' | 'warn' | 'error' | 'debug'; | |
| const LEVELS: Record<Level, number> = { debug: 0, info: 1, warn: 2, error: 3 }; | |
| const MIN_LEVEL = CONFIG.NODE_ENV === 'production' ? LEVELS.info : LEVELS.debug; | |
| function log(level: Level, msg: string, meta?: Record<string, unknown>): void { | |
| if (LEVELS[level] < MIN_LEVEL) return; | |
| const entry = JSON.stringify({ | |
| ts: new Date().toISOString(), | |
| level, | |
| msg, | |
| ...(meta ?? {}), | |
| }); | |
| if (level === 'error') { | |
| process.stderr.write(entry + '\n'); | |
| } else { | |
| process.stdout.write(entry + '\n'); | |
| } | |
| } | |
| export const logger = { | |
| info: (msg: string, meta?: Record<string, unknown>) => log('info', msg, meta), | |
| warn: (msg: string, meta?: Record<string, unknown>) => log('warn', msg, meta), | |
| error: (msg: string, meta?: Record<string, unknown>) => log('error', msg, meta), | |
| debug: (msg: string, meta?: Record<string, unknown>) => log('debug', msg, meta), | |
| }; | |