mirror of https://github.com/embarklabs/embark.git
Overwrite log file so .embark doesn’t bloat
The embark log file is being overwritten each time embark is run. There is a separate log file for each context, so that running, for example, `embark run` then `embark console` doesn’t get the `run` log overwritten with the `console` log.
This commit is contained in:
parent
0fa1e11ac7
commit
0760965bda
|
@ -19,7 +19,7 @@ class EmbarkController {
|
|||
let Config = require('../lib/core/config.js');
|
||||
|
||||
this.events = new Events();
|
||||
this.logger = new Logger({logLevel: Logger.logLevels.debug, events: this.events});
|
||||
this.logger = new Logger({logLevel: Logger.logLevels.debug, events: this.events, context: this.context});
|
||||
|
||||
this.config = new Config({env: env, logger: this.logger, events: this.events, context: this.context});
|
||||
this.config.loadConfigFiles(options);
|
||||
|
|
|
@ -29,7 +29,7 @@ class Engine {
|
|||
|
||||
let options = _options || {};
|
||||
this.events = options.events || this.events || new Events();
|
||||
this.logger = options.logger || new Logger({logLevel: options.logLevel || this.logLevel || 'debug', events: this.events, logFile: this.logFile});
|
||||
this.logger = options.logger || new Logger({context: this.context, logLevel: options.logLevel || this.logLevel || 'debug', events: this.events, logFile: this.logFile});
|
||||
this.config = new Config({env: this.env, logger: this.logger, events: this.events, context: this.context, webServerConfig: this.webServerConfig});
|
||||
this.config.loadConfigFiles({embarkConfig: this.embarkConfig, interceptLogs: this.interceptLogs});
|
||||
this.plugins = this.config.plugins;
|
||||
|
|
|
@ -145,6 +145,10 @@ function copyPreserve(sourceFilePath, targetFilePath) {
|
|||
fs.copySync(sourceFilePath, targetFilePath);
|
||||
}
|
||||
|
||||
function outputFileSync(){
|
||||
return fs.outputFileSync.apply(fs.outputFile, arguments);
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
mkdirpSync,
|
||||
mkdirp,
|
||||
|
@ -172,6 +176,13 @@ module.exports = {
|
|||
dappPath,
|
||||
pkgPath,
|
||||
createWriteStream,
|
||||
<<<<<<< HEAD
|
||||
tmpDir,
|
||||
copyPreserve
|
||||
||||||| merged common ancestors
|
||||
tmpDir
|
||||
=======
|
||||
tmpDir,
|
||||
outputFileSync
|
||||
>>>>>>> Overwrite log file so .embark doesn’t bloat
|
||||
};
|
||||
|
|
|
@ -9,16 +9,16 @@ class Logger {
|
|||
this.logLevel = options.logLevel || 'info';
|
||||
this.logFunction = options.logFunction || console.log;
|
||||
this.logFile = options.logFile;
|
||||
this.context = options.context;
|
||||
this.dateFormat = 'YYYY-MM-DD HH:mm:ss:SSS';
|
||||
this.logRegex = /\[(?<date>\d\d\d\d-\d\d-\d\d \d\d:\d\d:\d\d:\d\d\d)\] (?:\[(?<logLevel>\w*)\]:?)?\s?\s?(?<msg>.*)/gmi;
|
||||
|
||||
// Use a default logFile if none is specified in the cli,
|
||||
// in the format .embark/embark-log__YYYY-MM-DD_HH-mm-ss.log.
|
||||
// This logFile is needed so that when the backend tab starts,
|
||||
// the initial logs of Embark can be displayed.
|
||||
// in the format .embark/logs/embark_<context>.log.
|
||||
if (!this.logFile) {
|
||||
const now = new Date();
|
||||
this.logFile = fs.dappPath(`.embark/embark-log__${date.format(now, 'YYYY-MM-DD_HH-mm-ss')}.log`);
|
||||
this.logFile = fs.dappPath(`.embark/logs/embark_${this.context}.log`);
|
||||
// creates log dir if it doesn't exist, and overwrites existing log file if it exists
|
||||
fs.outputFileSync(this.logFile, '');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -80,9 +80,6 @@ Logger.prototype.parseLogFile = function () {
|
|||
};
|
||||
|
||||
Logger.prototype.writeToFile = function (_txt) {
|
||||
if (!this.logFile) {
|
||||
return;
|
||||
}
|
||||
const formattedDate = [`[${date.format(new Date(), this.dateFormat)}]`]; // adds a timestamp to the logs in the logFile
|
||||
fs.appendFileSync(this.logFile, "\n" + formattedDate.concat(Array.from(arguments)).join(' '));
|
||||
};
|
||||
|
|
|
@ -13,7 +13,7 @@ class Embark {
|
|||
let Config = require('./core/config.js');
|
||||
|
||||
this.events = new Events();
|
||||
this.logger = new Logger({logLevel: 'debug', events: this.events});
|
||||
this.logger = new Logger({logLevel: 'debug', events: this.events, context: this.context});
|
||||
|
||||
this.config = new Config({env: env, logger: this.logger, events: this.events, context: this.context});
|
||||
this.config.loadConfigFiles(options);
|
||||
|
|
Loading…
Reference in New Issue