diff --git a/gulpfile.babel.js b/gulpfile.babel.js index cecae587a2e22e11052da3dc01371310086a74bd..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,12 +46,11 @@ 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', () => { +gulp.task('test', ['build'], () => { gulp.src('test/test.js', {read: false}) .pipe(mocha()) .once('error', () => { @@ -47,13 +61,12 @@ gulp.task('test', () => { }); }); -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 ecf6df026314105b02628ef0ac2736a23950374a..e71edf141bd434ae749725ef5298e200c1105e7e 100644 --- a/src/libs/log.js +++ b/src/libs/log.js @@ -10,16 +10,29 @@ function getFilePath(module) { } function logger(module) { + const logPath = `${process.cwd()}/logs`; + const maxLogFiles = 5; + const maxLogSize = 5242880; const log = new winston.Logger({ transports: [ new winston.transports.File({ name: 'info-log', level: 'info', - filename: `${process.cwd()}/logs/all.log`, + filename: `${logPath}/simcaq-info.log`, handleException: true, json: false, - maxSize: 5242880, // 5MB - maxFiles: 2, + 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: maxLogSize, // 5MB + maxFiles: maxLogFiles, colorize: false, }), new winston.transports.Console({ @@ -33,7 +46,9 @@ function logger(module) { ], exitOnError: false, }); - if (!config.get('debug')) { + const debugMode = (typeof config.get('debug') === 'undefined') ? + config.get('debug') : false; + if (!debugMode) { log.remove('debug-log'); } return log;