diff --git a/gulpfile.babel.js b/gulpfile.babel.js index 37ab19c3a1ef729a8abaf0b154301e316480736f..78fda96077da6dea606cf5d6da422c182e185bd5 100644 --- a/gulpfile.babel.js +++ b/gulpfile.babel.js @@ -1,3 +1,5 @@ +const fs = require('fs'); + const gulp = require('gulp'); const babel = require('gulp-babel'); @@ -12,10 +14,23 @@ const Cache = require('gulp-file-cache'); const cache = new Cache(); +function createLogDir() { + const logDirPath = 'build/logs'; + fs.access(logDirPath, fs.F_OK, (err) => { + if (err) { + console.info(`Logs directory not found, creating it.`); + fs.mkdir(logDirPath, 0o700, (dirErr) => { + console.error(`Failed to create logs directory.\n\tError: ${dirErr}`); + }); + } + }); +} + /** * Compile source files */ -function compile() { +gulp.task('compile', () => { + createLogDir(); // run ESLint gulp.src('src/**/*.js') .pipe(eslint()) @@ -31,10 +46,9 @@ function compile() { // copy configuration file to build directory gulp.src('config.json') .pipe(gulp.dest('build')); +}); -} - -gulp.task('build', compile); +gulp.task('build', ['compile']); gulp.task('test', ['build'], () => { gulp.src('test/test.js', {read: false}) @@ -47,13 +61,12 @@ gulp.task('test', ['build'], () => { }); }); -gulp.task('watch', [], () => { +gulp.task('watch', ['compile'], () => { console.log('Watching source directory for changes'); - compile(); gulp.watch('src/**/*.js').on('change', () => { console.log('Recompiling source'); - compile(); - console.log('Source recompilation done') + gulp.start('compile'); + console.log('Source recompilation done'); }); }); diff --git a/src/libs/log.js b/src/libs/log.js index befd5ad326ade75fcbe0e0e1749d0d5360aa9da7..e71edf141bd434ae749725ef5298e200c1105e7e 100644 --- a/src/libs/log.js +++ b/src/libs/log.js @@ -2,8 +2,6 @@ const config = require('./config'); const winston = require('winston'); -const fs = require('fs'); - winston.emitErrs = true; function getFilePath(module) { @@ -13,25 +11,28 @@ function getFilePath(module) { function logger(module) { const logPath = `${process.cwd()}/logs`; - /* Check if logs directory exists */ - try { - fs.accessSync(logPath, fs.F_OK, () => {}); - } catch (err) { - // if logs directory does not exist, create it. - fs.mkdirSync(logPath, 0o700, (dirErr) => { - throw new Error(`Failed to create logs directory!\n\tError: ${dirErr}`); - }); - } + const maxLogFiles = 5; + const maxLogSize = 5242880; const log = new winston.Logger({ transports: [ new winston.transports.File({ name: 'info-log', level: 'info', - filename: `${logPath}/all.log`, + filename: `${logPath}/simcaq-info.log`, + handleException: true, + json: false, + maxSize: maxLogSize, // 5MB + maxFiles: maxLogFiles, + colorize: false, + }), + new winston.transports.File({ + name: 'error-log', + level: 'error', + filename: `${logPath}/simcaq-error.log`, handleException: true, json: false, - maxSize: 5242880, // 5MB - maxFiles: 2, + maxSize: maxLogSize, // 5MB + maxFiles: maxLogFiles, colorize: false, }), new winston.transports.Console({ @@ -45,7 +46,6 @@ function logger(module) { ], exitOnError: false, }); - const debugMode = (typeof config.get('debug') === 'undefined') ? config.get('debug') : false; if (!debugMode) {