-
Notifications
You must be signed in to change notification settings - Fork 11
/
index.js
38 lines (30 loc) · 1.08 KB
/
index.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
const fs = require('fs');
const { setLogBackend, Logger, LogLevel } = require('@calzoneman/jsli');
const { version } = require('./package.json');
let defaultLevel = process.env.DEBUG ? LogLevel.DEBUG : LogLevel.INFO;
let logfile = fs.createWriteStream('aeiou.log', { flags: 'a' });
class FileLogger extends Logger {
constructor(name, level) {
super(name, level);
}
emitMessage(level, message) {
let formatted = `${new Date().toISOString()} [${level.name}] ${this.loggerName}: ${message}`;
logfile.write(formatted + '\n');
console.log(formatted);
}
}
setLogBackend((loggerName, level) => {
return new FileLogger(loggerName, level || defaultLevel);
});
const LOGGER = require('@calzoneman/jsli')('main');
LOGGER.info('Starting aeiou version %s', version);
process.on('uncaughtException', error => {
LOGGER.fatal(`Uncaught exception: ${error.stack}`);
process.exit(1);
});
process.on('SIGINT', () => {
LOGGER.fatal('Exiting on SIGINT');
process.exit(1);
});
const config = require('./config');
require('./lib/webserver').start(config);