Skip to content

Instantly share code, notes, and snippets.

@andykais
Created January 4, 2019 22:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andykais/4504501fdd81c78b05d751ffe9771107 to your computer and use it in GitHub Desktop.
Save andykais/4504501fdd81c78b05d751ffe9771107 to your computer and use it in GitHub Desktop.
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