Adding events and fixing call stack in one line problem

This commit is contained in:
2017-09-16 19:12:58 +02:00
parent 836935ac8a
commit 3562efdd6f
5 changed files with 22 additions and 4 deletions

View File

@ -1,5 +1,6 @@
import * as util from "util";
import * as fs from "fs";
import { EventEmitter } from "events";
const Reset = "\x1b[0m"
const Bright = "\x1b[1m"
@ -37,6 +38,8 @@ export class Logging {
private static writing = false;
private static queue = new Array<{ message: string, error: boolean }>();
static events: EventEmitter = new EventEmitter();
static config(logfolder: string, stdout: boolean) {
this.logFileLocation = logfolder;
this.stdout = stdout;
@ -59,7 +62,11 @@ export class Logging {
Logging.errorMessage(error);
return;
}
var message = error.name + " " + error.message + "\n" + error.stack;
let m = "";
(<any>error.stack).forEach(e => {
m += e.toString() + "\n";
})
var message = error.name + " " + error.message + "\n" + m;
Logging.message(LoggingTypes.Error, [message]);
}
@ -104,6 +111,7 @@ export class Logging {
}
Logging.writeMessageToFile(m, type === LoggingTypes.Error);
}
Logging.events.emit("message", { type: type, message: mb });
if (this.stdout) console.log(consoleLogFormat + m + Reset);
}