-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.js
50 lines (42 loc) · 1.42 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// main.js
/* eslint no-console: "off" */
const fs = require('fs');
const pack = require('./package.json');
const program = require('commander');
const App = require('./app');
const Logger = require('./app/lib/logger');
let config = require('./config/config');
const logr = new Logger(config);
const log = logr.log;
program
.version(pack.version)
.option('-c, --config <filename>', 'Use the specified configuration file instead of the file in ./config/');
program.on('--help', () => {
console.log('');
console.log(` LogStash-Relay v${pack.version}`);
});
program.parse(process.argv);
if (program.config) {
log.info('Loading external configuration...');
let results;
try {
if (program.config.substr(-3) === '.js') {
config = require(program.config);
} else if (program.config.substr(-5) === '.json') {
results = fs.readFileSync(program.config);
config = JSON.parse(results);
} else {
log.info('Invalid file provided, external configuration must end with .js or .json');
log.info('Falling back to default config');
}
log.debug('Settings:');
log.debug(`Listening on Port: ${config.server.port}`);
log.debug(`Logstash Host: ${config.logstash.relay.host}:${config.logstash.relay.port}`);
log.debug(`Logstash App Name: ${config.logstash.relay.appName}`);
} catch (err) {
console.log(err.stack || err);
process.exit(1);
}
}
const appl = new App();
appl.init();