@progress/telerik-blazor-mcp
Version:
Model Context Protocol for Blazor
27 lines (26 loc) • 931 B
JavaScript
import fs from 'node:fs';
let LOG_ENABLED = false;
const LOG_FILE = process.env.DEBUG_LOG_FILE;
const LOG_FILE_DEFINED = !!(LOG_FILE && typeof LOG_FILE === 'string');
// check if the log file is a valid path
if (LOG_FILE_DEFINED) {
const logDir = LOG_FILE.substring(0, LOG_FILE.lastIndexOf('/'));
if (!fs.existsSync(logDir)) {
fs.mkdirSync(logDir, { recursive: true });
fs.writeFileSync(LOG_FILE, '');
}
}
LOG_ENABLED = LOG_FILE_DEFINED && fs.existsSync(LOG_FILE);
export function log(...args) {
if (LOG_ENABLED) {
// write a new line to the file with the date and time
const date = new Date();
const dateString = date.toISOString();
const logString = `${dateString}: ${args.join(' ')}\n`;
fs.appendFile(LOG_FILE, logString, (err) => {
if (err) {
console.error('Error writing to log file:', err);
}
});
}
}