From d8a52802e6b62e093854ec084029b00014e3befd Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jo=C3=A3o=20Victor=20Tozatti=20Risso?= <jvtr12@inf.ufpr.br>
Date: Wed, 14 Sep 2016 13:27:02 -0300
Subject: [PATCH 1/3] Fix runtime error when the logs directory is not found
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Signed-off-by: João Victor Tozatti Risso <jvtr12@inf.ufpr.br>
---
 src/libs/log.js | 19 +++++++++++++++++--
 1 file changed, 17 insertions(+), 2 deletions(-)

diff --git a/src/libs/log.js b/src/libs/log.js
index ecf6df02..befd5ad3 100644
--- a/src/libs/log.js
+++ b/src/libs/log.js
@@ -2,6 +2,8 @@ const config = require('./config');
 
 const winston = require('winston');
 
+const fs = require('fs');
+
 winston.emitErrs = true;
 
 function getFilePath(module) {
@@ -10,12 +12,22 @@ 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 log = new winston.Logger({
         transports: [
             new winston.transports.File({
                 name: 'info-log',
                 level: 'info',
-                filename: `${process.cwd()}/logs/all.log`,
+                filename: `${logPath}/all.log`,
                 handleException: true,
                 json: false,
                 maxSize: 5242880, // 5MB
@@ -33,7 +45,10 @@ 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;
-- 
GitLab


From 69ecb4bed5ff671abbc0a6600cfd6bc9f8559e25 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jo=C3=A3o=20Victor=20Tozatti=20Risso?= <jvtr12@inf.ufpr.br>
Date: Wed, 14 Sep 2016 13:27:40 -0300
Subject: [PATCH 2/3] Add build as dependency of rule test in Gulpfile
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Signed-off-by: João Victor Tozatti Risso <jvtr12@inf.ufpr.br>
---
 gulpfile.babel.js | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gulpfile.babel.js b/gulpfile.babel.js
index cecae587..37ab19c3 100644
--- a/gulpfile.babel.js
+++ b/gulpfile.babel.js
@@ -36,7 +36,7 @@ function compile() {
 
 gulp.task('build', compile);
 
-gulp.task('test', () => {
+gulp.task('test', ['build'], () => {
   gulp.src('test/test.js', {read: false})
     .pipe(mocha())
     .once('error', () => {
-- 
GitLab


From 3ab6e0425a97484186774696e62bb61002d996b0 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jo=C3=A3o=20Victor=20Tozatti=20Risso?= <jvtr12@inf.ufpr.br>
Date: Thu, 15 Sep 2016 11:33:48 -0300
Subject: [PATCH 3/3] Change directory creation to gulpfile
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Signed-off-by: João Victor Tozatti Risso <jvtr12@inf.ufpr.br>
---
 gulpfile.babel.js | 29 +++++++++++++++++++++--------
 src/libs/log.js   | 30 +++++++++++++++---------------
 2 files changed, 36 insertions(+), 23 deletions(-)

diff --git a/gulpfile.babel.js b/gulpfile.babel.js
index 37ab19c3..78fda960 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 befd5ad3..e71edf14 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) {
-- 
GitLab