mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-11 10:00:13 -06:00
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:
parent
1237df7304
commit
b15d6a48cb
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user