From 9a830c342362be059e28730b5a047b1749bd1fd3 Mon Sep 17 00:00:00 2001 From: emizzle Date: Wed, 24 Oct 2018 09:28:27 +0300 Subject: [PATCH] Remove default behavior of logging to file Default behavior of logging to file is no longer needed now that Embark log history can be properly served using the `ProcessLogsApi` and `LogHandler` classes. # Conflicts: # lib/core/logger.js # lib/modules/blockchain_process/blockchain.js --- lib/core/logger.js | 10 +++------- lib/modules/blockchain_process/blockchain.js | 4 ++-- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/lib/core/logger.js b/lib/core/logger.js index 0f6a1eba..50030ff5 100644 --- a/lib/core/logger.js +++ b/lib/core/logger.js @@ -14,13 +14,6 @@ class Logger { this.logFunction = options.logFunction || console.log; this.logFile = options.logFile; this.context = options.context; - // Use a default logFile if none is specified in the cli, - // in the format .embark/logs/embark_.log. - if (!this.logFile) { - this.logFile = fs.dappPath(`${constants.logs.logPath}embark_${this.context}.log`); - // creates log dir if it doesn't exist, and overwrites existing log file if it exists - fs.outputFileSync(this.logFile, ''); - } } /** @@ -86,6 +79,9 @@ Logger.prototype.registerAPICall = function (plugins) { }; Logger.prototype.writeToFile = function (_txt) { + if (!this.logFile) { + return; + } const formattedDate = [`[${date.format(new Date(), DATE_FORMAT)}]`]; // adds a timestamp to the logs in the logFile fs.appendFileSync(this.logFile, "\n" + formattedDate.concat(Array.from(arguments)).join(' ')); }; diff --git a/lib/modules/blockchain_process/blockchain.js b/lib/modules/blockchain_process/blockchain.js index b92471a3..7ffe7f05 100644 --- a/lib/modules/blockchain_process/blockchain.js +++ b/lib/modules/blockchain_process/blockchain.js @@ -22,7 +22,7 @@ var Blockchain = function(userConfig, clientClass) { this.isDev = userConfig.isDev; this.onReadyCallback = userConfig.onReadyCallback || (() => {}); this.onExitCallback = userConfig.onExitCallback; - this.logger = userConfig.logger || new Logger({logLevel: 'debug'}); + this.logger = userConfig.logger || new Logger({logLevel: 'debug', context: constants.contexts.blockchain}); // do not pass in events as we don't want any log events emitted this.events = userConfig.events; this.proxyIpc = null; this.isStandalone = userConfig.isStandalone; @@ -222,7 +222,7 @@ Blockchain.prototype.run = function () { // TOCHECK I don't understand why stderr and stdout are reverted. // This happens with Geth and Parity, so it does not seems a client problem self.child.stdout.on('data', (data) => { - this.logger.info(`${self.client.name} error: ${data}`); + self.logger.info(`${self.client.name} error: ${data}`); }); self.child.stderr.on('data', async (data) => {