{"size": 1357, "ext": "js", "max_stars_repo_path": "bin/logger.js", "max_stars_repo_name": "syntacstudio/tini-deployer", "max_stars_repo_stars_event_min_datetime": "2020-06-09T15:05:40.000Z", "max_stars_repo_stars_event_max_datetime": "2020-06-09T15:05:40.000Z", "max_issues_repo_path": "bin/logger.js", "max_issues_repo_name": "syntacstudio/tini-deployer", "max_issues_repo_issues_event_min_datetime": "2021-03-10T20:34:46.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-27T05:52:13.000Z", "max_forks_repo_path": "bin/logger.js", "max_forks_repo_name": "syntacstudio/tini-deployer", "max_forks_repo_forks_event_min_datetime": "2020-06-18T06:27:14.000Z", "max_forks_repo_forks_event_max_datetime": "2020-06-18T06:27:14.000Z"}
{"max_stars_count": 1, "max_issues_count": 4, "max_forks_count": 1, "avg_line_length": 27.14, "max_line_length": 80, "alphanum_fraction": 0.4038319823}
const logger = require('log-to-file');
const path =  require('path')
const mkdirp = require('mkdirp');
const fs =  require('fs')


const create = (message, type) => {
    const date = new Date();  
    const timing = `${date.getFullYear()}-${date.getMonth()}-${date.getDay()}`;
    const file = path.join(__dirname, `../logs/${timing}/${type}.log`)
    const dir  = path.join(__dirname, `../logs/${timing}`);
    const createLoger = () => {
        logger(message, file)
    }
    const creator = () => {
        fs.exists(file, (res) => {
            if(!res) {
                fs.writeFile(file, `---  ${type} ---`, (err) => {
                    if(err) {
                        return console.log(err)
                    } else {
                        createLoger()
                    }
                })
            } else {
                createLoger()
            }
        })
    }

    fs.exists(path.join(__dirname, `../logs/${timing}`), (res)=>{
       if(!res) {
            mkdirp(dir)
            .then(res => {
                console.log(`Directory ${dir} created`);
                createLoger();
            })
            .catch(err => {
                console.error(err)
            })
       } else {
         createLoger();
       }
    })
   
}

module.exports = {
    create
}