mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 17:28:26 -04:00
make devmode support --silent and --quiet
This commit is contained in:
parent
5eb9bedb1b
commit
eb317804b5
5 changed files with 89 additions and 75 deletions
|
@ -8,6 +8,11 @@ let log = _.restParam(function (color, label, rest1) {
|
|||
});
|
||||
|
||||
let color = require('./color');
|
||||
exports.green = _.partial(log, color.green);
|
||||
exports.red = _.partial(log, color.red);
|
||||
exports.yellow = _.partial(log, color.yellow);
|
||||
|
||||
module.exports = class Log {
|
||||
constructor(quiet, silent) {
|
||||
this.good = quiet || silent ? _.noop : _.partial(log, color.green);
|
||||
this.warn = quiet || silent ? _.noop : _.partial(log, color.yellow);
|
||||
this.bad = silent ? _.noop : _.partial(log, color.red);
|
||||
}
|
||||
};
|
||||
|
|
|
@ -28,7 +28,8 @@ module.exports = function (program) {
|
|||
.option('-e, --elasticsearch <uri>', 'Elasticsearch instance')
|
||||
.option('-c, --config <path>', 'Path to the config file')
|
||||
.option('-p, --port <port>', 'The port to bind to', parseInt)
|
||||
.option('-q, --quiet', 'Turns off logging')
|
||||
.option('-q, --quiet', 'Prevent all logging except errors')
|
||||
.option('-Q, --silent', 'Prevent all logging')
|
||||
.option('--verbose', 'Turns on verbose logging')
|
||||
.option('-H, --host <host>', 'The host to bind to')
|
||||
.option('-l, --log-file <path>', 'The file to log to')
|
||||
|
@ -53,10 +54,9 @@ module.exports = function (program) {
|
|||
.option('--dev', 'Run the server with development mode defaults')
|
||||
.option('--no-watch', 'Prevent watching, use with --dev to prevent server restarts')
|
||||
.action(function (opts) {
|
||||
|
||||
if (opts.dev && opts.watch && !isWorker) {
|
||||
// stop processing the action and handoff to watch cluster manager
|
||||
return require('../watch/watch');
|
||||
return require('../watch/watch')(opts);
|
||||
}
|
||||
|
||||
let settings = readYamlConfig(opts.config || fromRoot('config/kibana.yml'));
|
||||
|
@ -71,7 +71,9 @@ module.exports = function (program) {
|
|||
if (opts.elasticsearch) set('elasticsearch.url', opts.elasticsearch);
|
||||
if (opts.port) set('server.port', opts.port);
|
||||
if (opts.host) set('server.host', opts.host);
|
||||
if (opts.quiet) set('logging.quiet', opts.quiet);
|
||||
if (opts.quiet) set('logging.quiet', true);
|
||||
if (opts.silent) set('logging.silent', true);
|
||||
if (opts.verbose) set('logging.verbose', true);
|
||||
if (opts.logFile) set('logging.dest', opts.logFile);
|
||||
|
||||
set('plugins.scanDirs', _.compact([].concat(
|
||||
|
|
|
@ -5,7 +5,6 @@ let cluster = require('cluster');
|
|||
let resolve = require('path').resolve;
|
||||
let EventEmitter = require('events').EventEmitter;
|
||||
|
||||
let log = require('../../cli/log');
|
||||
let fromRoot = require('../../utils/fromRoot');
|
||||
|
||||
let cliPath = fromRoot('src/cli/cli.js');
|
||||
|
@ -22,14 +21,16 @@ module.exports = class Worker extends EventEmitter {
|
|||
opts = opts || {};
|
||||
super();
|
||||
|
||||
this.log = opts.log;
|
||||
this.type = opts.type;
|
||||
this.title = opts.title || opts.type;
|
||||
this.filter = opts.filter || _.constant(true);
|
||||
this.changeBuffer = [];
|
||||
this.changes = [];
|
||||
|
||||
let argv = _.union(baseArgv, opts.argv || []);
|
||||
this.env = {
|
||||
kbnWorkerType: this.type,
|
||||
kbnWorkerArgv: JSON.stringify(baseArgv.concat(opts.args || []))
|
||||
kbnWorkerArgv: JSON.stringify(argv)
|
||||
};
|
||||
|
||||
_.bindAll(this, ['onExit', 'onMessage', 'start']);
|
||||
|
@ -40,13 +41,13 @@ module.exports = class Worker extends EventEmitter {
|
|||
|
||||
onExit(fork, code) {
|
||||
if (this.fork !== fork) return;
|
||||
if (code) log.red(`${this.title} crashed`, 'with status code', code);
|
||||
if (code) this.log.bad(`${this.title} crashed`, 'with status code', code);
|
||||
else this.start(); // graceful shutdowns happen on restart
|
||||
}
|
||||
|
||||
onChange(path) {
|
||||
if (!this.filter(path)) return;
|
||||
this.changeBuffer.push(path);
|
||||
this.changes.push(path);
|
||||
this.start();
|
||||
}
|
||||
|
||||
|
@ -56,7 +57,7 @@ module.exports = class Worker extends EventEmitter {
|
|||
}
|
||||
|
||||
flushChangeBuffer() {
|
||||
let files = _.unique(this.changeBuffer.splice(0));
|
||||
let files = _.unique(this.changes.splice(0));
|
||||
let prefix = files.length > 1 ? '\n - ' : '';
|
||||
return files.reduce(function (list, file, i, files) {
|
||||
return `${list || ''}${prefix}"${file}"`;
|
||||
|
@ -64,20 +65,17 @@ module.exports = class Worker extends EventEmitter {
|
|||
}
|
||||
|
||||
start() {
|
||||
if (this.fork) {
|
||||
if (!this.fork.isDead()) {
|
||||
this.fork.kill();
|
||||
this.fork.removeListener('message', this.onMessage);
|
||||
// once "exit" event is received with 0 status, start() is called again
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.changeBuffer.length) {
|
||||
log.yellow(`${this.title} restarting`, `due to changes in ${this.flushChangeBuffer()}`);
|
||||
}
|
||||
if (this.fork && !this.fork.isDead()) {
|
||||
this.fork.kill();
|
||||
this.fork.removeListener('message', this.onMessage);
|
||||
// once "exit" event is received with 0 status, start() is called again
|
||||
return;
|
||||
}
|
||||
else {
|
||||
log.yellow(`${this.title} starting`);
|
||||
|
||||
if (this.fork && this.changes.length) {
|
||||
this.log.warn(`${this.title} restarting`, `due to changes in ${this.flushChangeBuffer()}`);
|
||||
} else {
|
||||
this.log.warn(`${this.title} starting`);
|
||||
}
|
||||
|
||||
this.fork = cluster.fork(this.env);
|
||||
|
|
|
@ -2,65 +2,74 @@
|
|||
|
||||
let cluster = require('cluster');
|
||||
let join = require('path').join;
|
||||
|
||||
let _ = require('lodash');
|
||||
let Gaze = require('gaze').Gaze;
|
||||
|
||||
let log = require('../../cli/log');
|
||||
let Log = require('../../cli/Log');
|
||||
let fromRoot = require('../../utils/fromRoot');
|
||||
|
||||
let Worker = require('./Worker');
|
||||
|
||||
let gaze = new Gaze([
|
||||
'src/{cli,commands,server,utils}/**/*',
|
||||
'src/plugins/*/*', // files at the root of a plugin
|
||||
'src/plugins/*/lib/**/*', // files within a lib directory for a plugin
|
||||
'config/**/*',
|
||||
], {
|
||||
cwd: fromRoot('.'),
|
||||
debounceDelay: 200
|
||||
});
|
||||
module.exports = function (opts) {
|
||||
|
||||
let workers = [
|
||||
new Worker(gaze, {
|
||||
type: 'optmzr',
|
||||
title: 'optimizer',
|
||||
args: [
|
||||
'--logging.quiet=true',
|
||||
'--plugins.initialize=false',
|
||||
'--server.autoListen=false',
|
||||
'--optimize._workerRole=send'
|
||||
],
|
||||
filter: function (path) {
|
||||
return /\/src\/server\/optimize\//.test(path);
|
||||
}
|
||||
}),
|
||||
let gaze = new Gaze([
|
||||
'src/{cli,commands,server,utils}/**/*',
|
||||
'src/plugins/*/*', // files at the root of a plugin
|
||||
'src/plugins/*/lib/**/*', // files within a lib directory for a plugin
|
||||
'config/**/*',
|
||||
], {
|
||||
cwd: fromRoot('.'),
|
||||
debounceDelay: 200
|
||||
});
|
||||
|
||||
new Worker(gaze, {
|
||||
type: 'server',
|
||||
args: ['--optimize._workerRole=receive']
|
||||
})
|
||||
];
|
||||
let log = new Log(opts.quiet, opts.silent);
|
||||
let customLogging = opts.quiet || opts.silent || opts.verbose;
|
||||
|
||||
workers.forEach(function (worker) {
|
||||
worker.on('broadcast', function (msg) {
|
||||
workers.forEach(function (broadcastTo) {
|
||||
if (broadcastTo === worker) return;
|
||||
broadcastTo.fork.send(msg);
|
||||
let workers = [
|
||||
new Worker(gaze, {
|
||||
type: 'optmzr',
|
||||
title: 'optimizer',
|
||||
log: log,
|
||||
argv: _.compact([
|
||||
customLogging ? null : '--quiet',
|
||||
'--plugins.initialize=false',
|
||||
'--server.autoListen=false',
|
||||
'--optimize._workerRole=send'
|
||||
]),
|
||||
filter: function (path) {
|
||||
return /\/src\/server\/optimize\//.test(path);
|
||||
}
|
||||
}),
|
||||
|
||||
new Worker(gaze, {
|
||||
type: 'server',
|
||||
log: log,
|
||||
argv: [
|
||||
'--optimize._workerRole=receive'
|
||||
]
|
||||
})
|
||||
];
|
||||
|
||||
workers.forEach(function (worker) {
|
||||
worker.on('broadcast', function (msg) {
|
||||
workers.forEach(function (broadcastTo) {
|
||||
if (broadcastTo === worker) return;
|
||||
broadcastTo.fork.send(msg);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
gaze.on('all', function (e, path) {
|
||||
_.invoke(workers, 'onChange', path);
|
||||
});
|
||||
gaze.on('all', function (e, path) {
|
||||
_.invoke(workers, 'onChange', path);
|
||||
});
|
||||
|
||||
gaze.on('ready', function (watcher) {
|
||||
log.green('Watching for changes', `(${_.size(watcher.watched())} files)`);
|
||||
_.invoke(workers, 'start');
|
||||
});
|
||||
gaze.on('ready', function (watcher) {
|
||||
log.good('Watching for changes', `(${_.size(watcher.watched())} files)`);
|
||||
_.invoke(workers, 'start');
|
||||
});
|
||||
|
||||
gaze.on('error', function (err) {
|
||||
log.red('Failed to watch files!\n', err.stack);
|
||||
process.exit(1);
|
||||
});
|
||||
gaze.on('error', function (err) {
|
||||
log.bad('Failed to watch files!\n', err.stack);
|
||||
process.exit(1);
|
||||
});
|
||||
|
||||
};
|
||||
|
|
|
@ -35,7 +35,7 @@ let workerType = process.env.kbnWorkerType ? `${type(process.env.kbnWorkerType)}
|
|||
|
||||
module.exports = class KbnLoggerJsonFormat extends LogFormat {
|
||||
format(data) {
|
||||
let time = color('time')(moment(data.timestamp).format('LTS'));
|
||||
let time = color('time')(moment(data.timestamp).format('HH:mm:ss.SSS'));
|
||||
let msg = data.error ? color('error')(data.error.stack) : color('message')(data.message);
|
||||
|
||||
let tags = _(data.tags)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue