log.js 632 B

12345678910111213141516171819
  1. const fs = require('fs')
  2. var ogWrite = process.stdout.write;
  3. function init (_projectName, TAG) {
  4. const isExists = fs.existsSync(`${process.cwd()}/logs/${_projectName}`)
  5. if (!isExists) {
  6. fs.mkdirSync(`${process.cwd()}/logs/${_projectName}`)
  7. }
  8. if (!fs.existsSync(`${process.cwd()}/logs/${_projectName}/${TAG}`)) {
  9. fs.mkdirSync(`${process.cwd()}/logs/${_projectName}/${TAG}`)
  10. }
  11. process.stdout.write = function( chunk ){
  12. fs.appendFile( `./logs/${_projectName}/${TAG}/log.txt`, chunk, () => {} );
  13. // this will write the output to the console
  14. ogWrite.apply( this, arguments );
  15. }
  16. }
  17. module.exports = init