Merge pull request #370 from embark-framework/feature/log-level-as-argument
Support setting log level as an argument
This commit is contained in:
commit
e1a9023bb2
20
lib/cmd.js
20
lib/cmd.js
|
@ -87,9 +87,14 @@ class Cmd {
|
|||
build() {
|
||||
program
|
||||
.command('build [environment]')
|
||||
.option('--logfile [logfile]', 'filename to output logs (default: none)')
|
||||
.option('--loglevel [loglevel]', 'level of logging to display ["error", "warn", "info", "debug", "trace"]', /^(error|warn|info|debug|trace)$/i, 'debug')
|
||||
.description('deploy and build dapp at dist/ (default: development)')
|
||||
.action(function (env, _options) {
|
||||
embark.build({env: env || 'development'});
|
||||
_options.env = env || 'development';
|
||||
_options.logFile = _options.logfile; // fix casing
|
||||
_options.logLevel = _options.loglevel; // fix casing
|
||||
embark.build(_options);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -102,6 +107,7 @@ class Cmd {
|
|||
.option('--nodashboard', 'simple mode, disables the dashboard')
|
||||
.option('--no-color', 'no colors in case it\'s needed for compatbility purposes')
|
||||
.option('--logfile [logfile]', 'filename to output logs (default: none)')
|
||||
.option('--loglevel [loglevel]', 'level of logging to display ["error", "warn", "info", "debug", "trace"]', /^(error|warn|info|debug|trace)$/i, 'debug')
|
||||
.description('run dapp (default: development)')
|
||||
.action(function (env, options) {
|
||||
embark.run({
|
||||
|
@ -110,7 +116,8 @@ class Cmd {
|
|||
serverHost: options.host,
|
||||
runWebserver: !options.noserver,
|
||||
useDashboard: !options.nodashboard,
|
||||
logfile: options.logfile
|
||||
logFile: options.logfile,
|
||||
logLevel: options.loglevel
|
||||
});
|
||||
});
|
||||
}
|
||||
|
@ -169,15 +176,18 @@ class Cmd {
|
|||
|
||||
upload() {
|
||||
program
|
||||
.command('upload [platform] [environment]')
|
||||
.command('upload <platform> [environment]')
|
||||
.option('--logfile [logfile]', 'filename to output logs (default: none)')
|
||||
.description('upload your dapp to a decentralized storage (e.g embark upload ipfs)')
|
||||
.option('--loglevel [loglevel]', 'level of logging to display ["error", "warn", "info", "debug", "trace"]', /^(error|warn|info|debug|trace)$/i, 'debug')
|
||||
.description('Upload your dapp to a decentralized storage (e.g embark upload ipfs).')
|
||||
.action(function (platform, env, _options) {
|
||||
let environment = env || 'development';
|
||||
embark.initConfig(environment, {
|
||||
embarkConfig: 'embark.json', interceptLogs: false
|
||||
});
|
||||
_options.env = environment;
|
||||
_options.logFile = _options.logfile; // fix casing
|
||||
_options.logLevel = _options.loglevel; // fix casing
|
||||
embark.upload(platform, _options);
|
||||
});
|
||||
}
|
||||
|
@ -189,7 +199,7 @@ class Cmd {
|
|||
.action(function (env, options) {
|
||||
embark.graph({
|
||||
env: env || 'development',
|
||||
logfile: options.logfile
|
||||
logFile: options.logfile
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
|
@ -16,14 +16,16 @@ class Engine {
|
|||
this.embarkConfig = options.embarkConfig;
|
||||
this.interceptLogs = options.interceptLogs;
|
||||
this.version = options.version;
|
||||
this.logfile = options.logfile;
|
||||
this.logFile = options.logFile;
|
||||
this.logLevel = options.logLevel;
|
||||
this.events = options.events;
|
||||
}
|
||||
|
||||
init(_options) {
|
||||
let self = this;
|
||||
let options = _options || {};
|
||||
this.events = new Events();
|
||||
this.logger = options.logger || new Logger({logLevel: options.logLevel || 'debug', events: this.events, logfile: this.logfile});
|
||||
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.config = new Config({env: this.env, logger: this.logger, events: this.events});
|
||||
this.config.loadConfigFiles({embarkConfig: this.embarkConfig, interceptLogs: this.interceptLogs});
|
||||
this.plugins = this.config.plugins;
|
||||
|
|
|
@ -7,16 +7,16 @@ class Logger {
|
|||
this.logLevels = ['error', 'warn', 'info', 'debug', 'trace'];
|
||||
this.logLevel = options.logLevel || 'info';
|
||||
this.logFunction = options.logFunction || console.log;
|
||||
this.logfile = options.logfile;
|
||||
this.logFile = options.logFile;
|
||||
}
|
||||
}
|
||||
|
||||
Logger.prototype.writeToFile = function (txt) {
|
||||
if (!this.logfile) {
|
||||
if (!this.logFile) {
|
||||
return;
|
||||
}
|
||||
|
||||
fs.appendFileSync(this.logfile, "\n" + txt);
|
||||
fs.appendFileSync(this.logFile, "\n" + txt);
|
||||
};
|
||||
|
||||
Logger.prototype.error = function (txt) {
|
||||
|
|
61
lib/index.js
61
lib/index.js
|
@ -61,7 +61,8 @@ class Embark {
|
|||
env: options.env,
|
||||
version: this.version,
|
||||
embarkConfig: options.embarkConfig || 'embark.json',
|
||||
logfile: options.logfile
|
||||
logFile: options.logFile,
|
||||
logLevel: options.logLevel
|
||||
});
|
||||
engine.init();
|
||||
|
||||
|
@ -150,16 +151,20 @@ class Embark {
|
|||
});
|
||||
}
|
||||
|
||||
build(options, engine, continueProcessing) {
|
||||
if(!engine){
|
||||
engine = new Engine({
|
||||
env: options.env,
|
||||
version: this.version,
|
||||
embarkConfig: 'embark.json',
|
||||
interceptLogs: false
|
||||
});
|
||||
engine.init();
|
||||
}
|
||||
build(options, continueProcessing) {
|
||||
let engine = new Engine({
|
||||
env: options.env,
|
||||
version: this.version,
|
||||
embarkConfig: 'embark.json',
|
||||
interceptLogs: false,
|
||||
logFile: options.logFile,
|
||||
logLevel: options.logLevel,
|
||||
events: options.events,
|
||||
logger: options.logger,
|
||||
config: options.config,
|
||||
plugins: options.plugins
|
||||
});
|
||||
engine.init();
|
||||
|
||||
async.waterfall([
|
||||
function startServices(callback) {
|
||||
|
@ -207,7 +212,7 @@ class Embark {
|
|||
env: options.env,
|
||||
version: this.version,
|
||||
embarkConfig: options.embarkConfig || 'embark.json',
|
||||
logfile: options.logfile
|
||||
logFile: options.logFile
|
||||
});
|
||||
engine.init();
|
||||
|
||||
|
@ -254,29 +259,26 @@ class Embark {
|
|||
|
||||
upload(platform, options) {
|
||||
|
||||
// populate options that were instantiated with initConfig to pass around
|
||||
options.buildDir = 'dist/';
|
||||
options.storageConfig = this.config.storageConfig;
|
||||
|
||||
// initialise embark engine
|
||||
let engine = new Engine({
|
||||
env: options.env,
|
||||
version: this.version,
|
||||
embarkConfig: options.embarkConfig || 'embark.json',
|
||||
logfile: options.logfile
|
||||
});
|
||||
engine.init();
|
||||
options.events = this.events;
|
||||
options.logger = this.logger;
|
||||
options.config = this.config;
|
||||
|
||||
// load plugins
|
||||
this.plugins.loadInternalPlugin('ipfs', options);
|
||||
this.plugins.loadInternalPlugin('swarm', options);
|
||||
|
||||
let plugins = this.plugins;
|
||||
// upddate our options with loaded plugins
|
||||
options.plugins = this.plugins;
|
||||
|
||||
let cmdPlugin;
|
||||
let self = this;
|
||||
async.waterfall([
|
||||
function setupStoragePlugin(callback){
|
||||
// check use has input existing storage plugin
|
||||
let cmdPlugins = plugins.getPluginsFor('uploadCmds');
|
||||
let cmdPlugins = self.plugins.getPluginsFor('uploadCmds');
|
||||
|
||||
if (cmdPlugins.length > 0) {
|
||||
cmdPlugin = cmdPlugins.find((pluginCmd) => {
|
||||
|
@ -284,7 +286,7 @@ class Embark {
|
|||
});
|
||||
}
|
||||
if (!cmdPlugin) {
|
||||
engine.logger.info('try "embark upload ipfs" or "embark upload swarm"'.green);
|
||||
self.logger.info('try "embark upload ipfs" or "embark upload swarm"'.green);
|
||||
callback({message: 'unknown platform: ' + platform});
|
||||
} else {
|
||||
callback();
|
||||
|
@ -292,8 +294,7 @@ class Embark {
|
|||
},
|
||||
function buildAndDeployContracts(callback){
|
||||
// 2. upload to storage (outputDone event triggered after webpack finished)
|
||||
engine.events.on('outputDone', function () {
|
||||
engine.logger.info('deploying to ' + platform + '...');
|
||||
self.events.on('outputDone', function () {
|
||||
cmdPlugin.uploadCmds[0].cb()
|
||||
.then((success) => {
|
||||
callback(null, success);
|
||||
|
@ -301,14 +302,14 @@ class Embark {
|
|||
.catch(callback);
|
||||
});
|
||||
// 1. build the contracts and dapp webpack
|
||||
self.build(options, engine, true);
|
||||
self.build(options, true);
|
||||
}
|
||||
], function (err, _result) {
|
||||
if (err) {
|
||||
engine.logger.error(err.message);
|
||||
engine.logger.debug(err.stack);
|
||||
self.logger.error(err.message);
|
||||
self.logger.debug(err.stack);
|
||||
} else {
|
||||
engine.logger.info("finished building dapp and deploying to " + platform.underline);
|
||||
self.logger.info("finished building dapp and deploying to " + platform.underline);
|
||||
}
|
||||
|
||||
// needed due to child processes
|
||||
|
|
|
@ -13,7 +13,7 @@ class IPFS {
|
|||
|
||||
deploy() {
|
||||
return new Promise((resolve, reject) => {
|
||||
console.log("deploying!");
|
||||
console.log("deploying to ipfs!");
|
||||
let self = this;
|
||||
async.waterfall([
|
||||
function findBinary(callback) {
|
||||
|
@ -29,8 +29,9 @@ class IPFS {
|
|||
function runCommand(ipfs_bin, callback) {
|
||||
let cmd = `"${ipfs_bin}" add -r ${self.buildDir}`;
|
||||
console.log(("=== adding " + self.buildDir + " to ipfs").green);
|
||||
console.log(cmd.green);
|
||||
shelljs.exec(cmd, function(code, stdout, stderr){
|
||||
console.trace(cmd);
|
||||
shelljs.exec(cmd, {silent:true}, function(code, stdout, stderr){ // {silent:true}: don't echo cmd output so it can be controlled via logLevel
|
||||
console.log(stdout.green);
|
||||
callback(stderr, stdout);
|
||||
});
|
||||
},
|
||||
|
|
|
@ -10,6 +10,7 @@ class Swarm {
|
|||
|
||||
deploy() {
|
||||
return new Promise((resolve, reject) => {
|
||||
console.log("deploying to swarm!");
|
||||
let self = this;
|
||||
async.waterfall([
|
||||
function findBinary(callback) {
|
||||
|
@ -25,8 +26,9 @@ class Swarm {
|
|||
function runCommand(swarm_bin, callback) {
|
||||
let cmd = `"${swarm_bin}" --defaultpath ${self.buildDir} index.html --recursive up ${self.buildDir}`;
|
||||
console.log(("=== adding " + self.buildDir + " to swarm").green);
|
||||
console.log(cmd.green);
|
||||
shelljs.exec(cmd, function(code, stdout, stderr){
|
||||
console.trace(cmd);
|
||||
shelljs.exec(cmd, {silent:true}, function(code, stdout, stderr){ // {silent:true}: don't echo cmd output so it can be controlled via logLevel
|
||||
console.log(stdout.green);
|
||||
callback(stderr, {code: code, output: stdout});
|
||||
});
|
||||
},
|
||||
|
|
Loading…
Reference in New Issue