Download logger.js from vipsphi/luadao: direct link, hf CLI and curl.
- Browser
- Download file 1.45 kB
-
https://huggingface.co/spaces/vipsphi/luadao/resolve/main/logger.js
- Command line
-
hf download hf://spaces/vipsphi/luadao/logger.js
-
curl -L -o logger.js https://huggingface.co/spaces/vipsphi/luadao/resolve/main/logger.js
1.45 kB
| const fs = require('fs'); | |
| const path = require('path'); | |
| const logFile = path.join(__dirname, 'app.log'); | |
| const logStream = fs.createWriteStream(logFile, { flags: 'a' }); | |
| class Logger { | |
| constructor() { | |
| this.queueCount = 0; | |
| this.activeCount = 0; | |
| this.lastStatusTime = 0; | |
| } | |
| info(msg) { | |
| this.writeToFile(`[INFO] ${msg}`); | |
| console.log(`[${new Date().toLocaleTimeString()}] INFO: ${msg}`); | |
| } | |
| warn(msg) { | |
| this.writeToFile(`[WARN] ${msg}`); | |
| console.warn(`[${new Date().toLocaleTimeString()}] WARN: ${msg}`); | |
| } | |
| error(msg) { | |
| this.writeToFile(`[ERROR] ${msg}`); | |
| console.error(`[${new Date().toLocaleTimeString()}] ERROR: ${msg}`); | |
| } | |
| debug(msg) { | |
| this.writeToFile(`[DEBUG] ${msg}`); | |
| } | |
| writeToFile(msg) { | |
| const timestamp = new Date().toISOString(); | |
| logStream.write(`[${timestamp}] ${msg}\n`); | |
| } | |
| // Specialized throttled stats for the console | |
| updateStats(active, queue) { | |
| this.activeCount = active; | |
| this.queueCount = queue; | |
| const now = Date.now(); | |
| if (now - this.lastStatusTime > 3000) { // Update console every 3 seconds | |
| this.lastStatusTime = now; | |
| process.stdout.write(`\r[Status] Active: ${active} | Queued: ${queue} | Logs: See app.log `); | |
| } | |
| } | |
| } | |
| module.exports = new Logger(); | |