Created
January 4, 2019 22:08
-
-
Save andykais/4504501fdd81c78b05d751ffe9771107 to your computer and use it in GitHub Desktop.
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 characters
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) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment