Fix GH#18217 issue for FileLog. (#27430)

* Fix GH#18217 issue for FileLog.

* Refactor FileLog class to not use isEnabled property.
This commit is contained in:
Valera Rozuvan 2018-10-02 19:09:51 +03:00 committed by Andy
parent 1237df7304
commit b15d6a48cb

View File

@ -1,5 +1,3 @@
// tslint:disable no-unnecessary-type-assertion (TODO: tslint can't find node types)
namespace ts.server.typingsInstaller {
const fs: {
appendFileSync(file: string, content: string): void
@ -12,19 +10,20 @@ namespace ts.server.typingsInstaller {
} = require("path");
class FileLog implements Log {
private logEnabled = true;
constructor(private readonly logFile?: string) {
constructor(private logFile: string | undefined) {
}
isEnabled = () => {
return this.logEnabled && this.logFile !== undefined;
return typeof this.logFile === "string";
}
writeLine = (text: string) => {
if (typeof this.logFile !== "string") return;
try {
fs.appendFileSync(this.logFile!, `[${nowString()}] ${text}${sys.newLine}`); // TODO: GH#18217
fs.appendFileSync(this.logFile, `[${nowString()}] ${text}${sys.newLine}`);
}
catch (e) {
this.logEnabled = false;
this.logFile = undefined;
}
}
}