Created
January 4, 2019 22:08
-
-
Save andykais/4504501fdd81c78b05d751ffe9771107 to your computer and use it in GitHub Desktop.
Revisions
-
andykais created this gist
Jan 4, 2019 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,29 @@ import * as Rx from 'rxjs' import * as ops from 'rxjs/operators' import fs from 'fs' import VError from 'verror' /** * for now, there can only be one transport at a time * the cli will have to handle an option to directly log to terminal while also including a * "terminal ui" output default (progress bars, queued, in progress, completed, etc) * this can be accomplished by log options being done directly as command line args */ abstract class LogTransport { abstract transport: (data: string) => void } class StdoutTransport extends LogTransport { transport = console.log } class FileTransport extends LogTransport { writeStream: fs.WriteStream constructor(filename: string) { super() this.writeStream = fs.createWriteStream(filename) this.writeStream.on('error', error => { throw new VError(error, 'logger file transport') }) } transport = (data: string) => { this.writeStream.write(data) } }