photo_server_json_flutter_c.../api_v1/scanner/logger.js.ok
2026-03-18 09:34:41 +01:00

31 lines
783 B
Text

// scanner/logger.js
const fs = require('fs');
const path = require('path');
const LOG_MODE = process.env.LOG_MODE || "console"; // console | file | both
const LOG_FILE = process.env.LOG_FILE || "scan.log";
let stream = null;
if (LOG_MODE === "file" || LOG_MODE === "both") {
const logPath = path.resolve(__dirname, "..", LOG_FILE);
stream = fs.createWriteStream(logPath, { flags: "a" });
}
function ts() {
return new Date().toISOString().replace("T", " ").split(".")[0];
}
function log(message) {
const line = `${ts()} ${message}\n`;
if (LOG_MODE === "console" || LOG_MODE === "both") {
process.stdout.write(line);
}
if (LOG_MODE === "file" || LOG_MODE === "both") {
stream.write(line);
}
}
module.exports = { log };