specpress
Version:
Export PDF and/or DOCX files from a subset of Markdown, ASN.1 and JSON files
37 lines • 1.02 kB
JavaScript
// Logger.ts — Output destination abstraction
import { createWriteStream } from "node:fs";
import { resolve } from "node:path";
class Logger {
stream = null;
filePath = null;
log(...args) {
const line = args.map(String).join(" ") + "\n";
if (this.stream) {
this.stream.write(line);
}
else {
process.stdout.write(line);
}
}
openFile(aFilePath) {
this.filePath = resolve(aFilePath);
this.stream = createWriteStream(this.filePath);
}
close() {
return new Promise((aResolve) => {
if (this.stream) {
const path = this.filePath;
this.stream.end(() => {
this.stream = null;
this.filePath = null;
aResolve(path);
});
}
else {
aResolve(null);
}
});
}
}
export const logger = new Logger();
//# sourceMappingURL=Logger.js.map