-
Notifications
You must be signed in to change notification settings - Fork 66
/
start.js
60 lines (49 loc) · 1.6 KB
/
start.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
51
52
53
54
55
56
57
58
59
60
const Server = require('./lib/server');
const yaml = require('js-yaml');
const fs = require('fs');
const log4js = require('log4js');
const os = require('os');
try {
var logFile;
var configFile;
switch (os.platform()) {
case 'win32':
logFile = 'c:\\Windows\\Logs\\node-turn.log';
configFile = 'C:\\ProgramData\\node-turn.conf';
break;
default:
logFile = '/var/log/node-turn.log';
configFile = '/etc/node-turn/node-turn.conf';
break;
}
var appenders = {};
var hostname = os.hostname();
appenders[hostname] = { type: 'file', filename: logFile };
/* eslint-disable no-console */
if (!fs.existsSync(logFile)) {
appenders[hostname] = { type: 'console'};
console.log('Using STDOUT for logging');
console.log('Please create a the log file ' + logFile + ' with correct permission');
}
if (!fs.existsSync(configFile)) {
console.log('Using sample-config.conf');
console.log('Please copy with correct permission and modify sample-config.conf to ' + configFile);
configFile = 'sample-config.conf';
}
/* eslint-enable no-console */
var config = yaml.safeLoad(fs.readFileSync(configFile, 'utf8'));
log4js.configure({
appenders: appenders,
categories: { default: { appenders: [hostname], level: config['debug-level'] || 'ERROR' } }
});
const logger = log4js.getLogger(hostname);
var debug = function(level, message) {
level = level.toLowerCase();
logger[level](message);
};
config.debug = debug;
var server = new Server(config);
server.start();
} catch (e) {
console.log(e); // eslint-disable-line no-console
}