Download src/sse/utils/logger.js from heyeyydss/api9nin: direct link, hf CLI and curl.
- Browser
- Download file 2.02 kB
-
https://huggingface.co/spaces/heyeyydss/api9nin/resolve/main/src/sse/utils/logger.js
- Command line
-
hf download hf://spaces/heyeyydss/api9nin/src/sse/utils/logger.js
-
curl -L -o logger.js https://huggingface.co/spaces/heyeyydss/api9nin/resolve/main/src/sse/utils/logger.js
2.02 kB
| // Logger utility for cloud | |
| const LOG_LEVELS = { | |
| DEBUG: 0, | |
| INFO: 1, | |
| WARN: 2, | |
| ERROR: 3 | |
| }; | |
| const LEVEL = LOG_LEVELS.DEBUG; | |
| function formatTime() { | |
| return new Date().toLocaleTimeString("en-US", { hour12: false }); | |
| } | |
| function formatData(data) { | |
| if (!data) return ""; | |
| if (typeof data === "string") return data; | |
| try { | |
| return JSON.stringify(data); | |
| } catch { | |
| return String(data); | |
| } | |
| } | |
| export function debug(tag, message, data) { | |
| if (LEVEL <= LOG_LEVELS.DEBUG) { | |
| const dataStr = data ? ` ${formatData(data)}` : ""; | |
| console.log(`[${formatTime()}] π [${tag}] ${message}${dataStr}`); | |
| } | |
| } | |
| export function info(tag, message, data) { | |
| if (LEVEL <= LOG_LEVELS.INFO) { | |
| const dataStr = data ? ` ${formatData(data)}` : ""; | |
| console.log(`[${formatTime()}] βΉοΈ [${tag}] ${message}${dataStr}`); | |
| } | |
| } | |
| export function warn(tag, message, data) { | |
| if (LEVEL <= LOG_LEVELS.WARN) { | |
| const dataStr = data ? ` ${formatData(data)}` : ""; | |
| // console.warn(`[${formatTime()}] β οΈ [${tag}] ${message}${dataStr}`); | |
| } | |
| } | |
| export function error(tag, message, data) { | |
| if (LEVEL <= LOG_LEVELS.ERROR) { | |
| const dataStr = data ? ` ${formatData(data)}` : ""; | |
| console.log(`[${formatTime()}] β [${tag}] ${message}${dataStr}`); | |
| } | |
| } | |
| export function request(method, path, extra) { | |
| const dataStr = extra ? ` ${formatData(extra)}` : ""; | |
| console.log(`\x1b[36m[${formatTime()}] π₯ ${method} ${path}${dataStr}\x1b[0m`); | |
| } | |
| export function response(status, duration, extra) { | |
| const icon = status < 400 ? "π€" : "π₯"; | |
| const dataStr = extra ? ` ${formatData(extra)}` : ""; | |
| console.log(`[${formatTime()}] ${icon} ${status} (${duration}ms)${dataStr}`); | |
| } | |
| export function stream(event, data) { | |
| const dataStr = data ? ` ${formatData(data)}` : ""; | |
| console.log(`[${formatTime()}] π [STREAM] ${event}${dataStr}`); | |
| } | |
| // Mask sensitive data | |
| export function maskKey(key) { | |
| if (!key || key.length < 8) return "***"; | |
| return `${key.slice(0, 4)}...${key.slice(-4)}`; | |
| } | |