diff --git a/.nvmrc b/.nvmrc index 762ed9162..2a5dd0d63 100644 --- a/.nvmrc +++ b/.nvmrc @@ -1 +1 @@ -8.11.2 +8.14.0 diff --git a/Jenkinsfile b/Jenkinsfile index c7bb9788d..d0ab9aa7c 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -12,31 +12,35 @@ pipeline { stages { stage ('Build dependencies') { steps { - script { - cache_file = restoreCache("package.json") - sh 'npm install' - saveCache(cache_file, './node_modules', 10) + nvm(getNodejsVersion()) { + sh 'npm ci' } } } stage ('Run ESLint') { steps { - sh 'npm run eslint' + nvm(getNodejsVersion()) { + sh 'npm run eslint' + } } } stage ('Build bundles') { steps { - sh 'npm run build' + nvm(getNodejsVersion()) { + sh 'npm run build' + } } } stage ('Build candles') { steps { - // marketwatcher needs to be enabled to builds candles - sh ''' - cp ./test/known.test.json ./known.json - redis-cli -n $REDIS_DB flushdb - grunt candles:build - ''' + nvm(getNodejsVersion()) { + // marketwatcher needs to be enabled to builds candles + sh ''' + cp ./test/known.test.json ./known.json + redis-cli -n $REDIS_DB flushdb + grunt candles:build + ''' + } } } stage ('Start Lisk') { @@ -65,29 +69,33 @@ pipeline { } stage ('Start Explorer') { steps { - sh ''' - cd $WORKSPACE/$BRANCH_NAME - LISK_PORT=$( docker-compose port lisk 4000 |cut -d ":" -f 2 ) - cd - - LISK_PORT=$LISK_PORT node app.js -p $EXPLORER_PORT &>/dev/null & - sleep 20 - ''' + nvm(getNodejsVersion()) { + sh ''' + cd $WORKSPACE/$BRANCH_NAME + LISK_PORT=$( docker-compose port lisk 4000 |cut -d ":" -f 2 ) + cd - + LISK_PORT=$LISK_PORT node app.js -p $EXPLORER_PORT &>/dev/null & + sleep 20 + ''' + } } } stage ('Run API tests') { steps { - sh ''' - sed -i -r -e "s/6040/$EXPLORER_PORT/" test/node.js - npm run test - ''' + nvm(getNodejsVersion()) { + sh ''' + sed -i -r -e "s/6040/$EXPLORER_PORT/" test/node.js + npm run test + ''' + } } } // stage ('Run E2E tests') { // steps { // wrap([$class: 'Xvfb']) { - // sh ''' - // npm run e2e -- --params.baseURL http://localhost:$EXPLORER_PORT - // ''' + // nvm(getNodejsVersion()) { + // sh 'npm run e2e -- --params.baseURL http://localhost:$EXPLORER_PORT' + // } // } // } // } diff --git a/config.js b/config.js index f525f1de9..06a68f374 100644 --- a/config.js +++ b/config.js @@ -55,7 +55,7 @@ config.cacheTTL = 20; // Collect logs (true - enabled, false - disabled) config.log.enabled = true; // Output for logs - can be device file or ordinary path -config.log.file = './logs/explorer.log'; +config.log.output = ['/dev/stdout', './logs/explorer.log']; // Log level - (trace, debug, info, warn, error) config.log.level = 'info'; diff --git a/utils/logger.js b/utils/logger.js index 3ca782e53..45c26f13b 100644 --- a/utils/logger.js +++ b/utils/logger.js @@ -19,8 +19,22 @@ const flatstr = require('flatstr'); const newConsole = require('console').Console; const config = require('../config'); -const output = fs.createWriteStream(config.log.file, { flags: 'a' }); -const myConsole = new newConsole(output, output); +const defaultOutput = '/dev/stdout'; + +if (!Array.isArray(config.log.output)) { + if (typeof config.log.output === 'string') { + config.log.output = [config.log.output]; + } else if (typeof config.log.file === 'string') { + config.log.output = [config.log.file]; + } else { + config.log.output = [defaultOutput]; + } +} + +const logOutputs = config.log.output.map((outputPath) => { + const fileOutput = fs.createWriteStream(outputPath, { flags: 'a' }); + return new newConsole(fileOutput, fileOutput); +}); const levels = { trace: 0, @@ -35,25 +49,24 @@ const logger = {}; logger.doLog = function doLog(level, msg, extra) { if (config.log.enabled) { const timestamp = Date.now(); - - // const stringMsg = typeof msg === 'string' ? msg : JSON.stringify(msg); - // const parsedMsg = stringMsg.replace(/(\r\n|\n|\r)/gm, ' '); + let outputString; if (extra) { const stringExtra = typeof extra === 'string' ? extra : JSON.stringify(extra); const parsedExtra = stringExtra.replace(/(\r\n|\n|\r)/gm, ' '); - myConsole.log(flatstr(safeStringify({ - level, - timestamp, - message: `${msg} ${parsedExtra}`, - }))); + outputString = `${msg} ${parsedExtra}`; } else { - myConsole.log(flatstr(safeStringify({ + outputString = msg; + } + + logOutputs.map((logOutput) => { + logOutput.log(flatstr(safeStringify({ level, timestamp, - message: msg, + message: outputString, }))); - } + return logOutput; + }); } };