20 lines
666 B
TypeScript
20 lines
666 B
TypeScript
import * as fs from 'fs';
|
|
import * as path from 'path';
|
|
|
|
export function log(message: string, filename: string) {
|
|
console.log(filename + " : " + message);
|
|
const workingPath = process.cwd();
|
|
const logDir = path.join(workingPath, 'duelfi_validator_logs');
|
|
const logFile = path.join(logDir, `${filename}.txt`);
|
|
|
|
// Create directory if it doesn't exist
|
|
if (!fs.existsSync(logDir)) {
|
|
fs.mkdirSync(logDir, { recursive: true });
|
|
}
|
|
|
|
// Append message with timestamp to the log file
|
|
const timestamp = new Date().toISOString();
|
|
const logMessage = `[${timestamp}] ${message}\n`;
|
|
|
|
fs.appendFileSync(logFile, logMessage);
|
|
} |