Download src/utils/logger.js from VanyaJ/bada-terminal: direct link, hf CLI and curl.
- Browser
- Download file 2.18 kB
-
https://huggingface.co/VanyaJ/bada-terminal/resolve/main/src/utils/logger.js
- Command line
-
hf download hf://VanyaJ/bada-terminal/src/utils/logger.js
-
curl -L -o logger.js https://huggingface.co/VanyaJ/bada-terminal/resolve/main/src/utils/logger.js
2.18 kB
| const { writeDebugLog } = require('./debug-log'); | |
| // ๊ฒฝ๋ ๊ตฌ์กฐํ ๋ก๊ฑฐ. | |
| // troubleshooting_guide.md 4.2 ๊ถ์ฅ ํ์: { message, errorName, stack, context, timestamp } | |
| // - ์ฝ์์๋ ์ฌ๋์ด ์ฝ๊ธฐ ์ฌ์ด ํ ์ค ์์ฝ์ ์ถ๋ ฅ | |
| // - ๋๋ฒ๊ทธ ๋ก๊ทธ ํ์ผ(desktop-cli-debug.log)์๋ JSON ํ ์ค์ ๊ธฐ๋ก (writeDebugLog ๊ฒฝ์ , ๋กํ ์ด์ ํฌํจ) | |
| const LEVELS = { debug: 10, info: 20, warn: 30, error: 40 }; | |
| function serializeError(err) { | |
| if (!err) return null; | |
| if (err instanceof Error) { | |
| return { name: err.name, message: err.message, stack: err.stack }; | |
| } | |
| // ๋ฌธ์์ด/๊ฐ์ฒด ๋ฑ ๋น-Error ๊ฐ๋ ํก์ | |
| return { name: 'NonError', message: String(err.message || err), stack: null }; | |
| } | |
| function emit(level, scope, message, context, err) { | |
| const error = serializeError(err); | |
| const record = { | |
| level, | |
| scope: scope || 'app', | |
| message, | |
| errorName: error ? error.name : undefined, | |
| stack: error ? error.stack : undefined, | |
| context: context && Object.keys(context).length ? context : undefined, | |
| timestamp: new Date().toISOString(), | |
| }; | |
| // ์ฝ์ ์์ฝ (๊ฐ๋ฐ ์ค ๊ฐ์์ฑ) | |
| const summary = `[${record.scope}] ${message}` + (error ? ` :: ${error.name}: ${error.message}` : ''); | |
| if (LEVELS[level] >= LEVELS.error) console.error(summary); | |
| else if (LEVELS[level] >= LEVELS.warn) console.warn(summary); | |
| else if (process.env.BADA_LOG_ALL || process.env.NODE_ENV === 'test') console.log(summary); | |
| // ๊ตฌ์กฐํ JSON ํ ์ค (ํ์ผ). writeDebugLog๋ ์คํจํด๋ ์์ฒด fallback ์ฒ๋ฆฌ. | |
| try { | |
| writeDebugLog(JSON.stringify(record)); | |
| } catch (_) { | |
| // ๋ก๊น ์์ฒด ์คํจ๋ ๋ฌด์ (๋ก๊น ์ผ๋ก ์ฑ ํ๋ฆ์ ๊นจ์ง ์์) | |
| } | |
| } | |
| function makeLogger(scope) { | |
| return { | |
| debug: (message, context) => emit('debug', scope, message, context, null), | |
| info: (message, context) => emit('info', scope, message, context, null), | |
| warn: (message, context, err) => emit('warn', scope, message, context, err), | |
| error: (message, err, context) => emit('error', scope, message, context, err), | |
| }; | |
| } | |
| module.exports = { | |
| makeLogger, | |
| // ์ค์ฝํ ์๋ ์ง์ ํธ์ถ์ฉ | |
| ...makeLogger('app'), | |
| }; | |