import { promises as fs } from 'fs';
import { LOGFILE_PATH } from './constants';

export function Logger(component: string) {

    const log = async (message: string) => {
        const date = new Date().toISOString();
        const logMessage = `[main_proc] [${date}] [${component}] ${message}`;
        console.log(logMessage);
        await fs.appendFile(LOGFILE_PATH, logMessage + '\n');
    }
    
    return {
        log
    };
}