-
Notifications
You must be signed in to change notification settings - Fork 202
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2361 from tgodzik/print-out
bugfix: Forward standard output to logger
- Loading branch information
Showing
6 changed files
with
101 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package bloop.logging | ||
|
||
import java.io.PrintStream | ||
import java.io.ByteArrayOutputStream | ||
import scala.collection.concurrent.TrieMap | ||
|
||
class TeeOutputStream(targetPS: PrintStream) extends PrintStream(targetPS) { | ||
|
||
private val allStreams = TrieMap.empty[Int, ByteArrayOutputStream]; | ||
|
||
override def write(b: Int): Unit = { | ||
allStreams.values.foreach( | ||
_.write(b) | ||
) | ||
targetPS.write(b) | ||
} | ||
|
||
override def write(buf: Array[Byte], off: Int, len: Int): Unit = { | ||
allStreams.values.foreach( | ||
_.write(buf, off, len) | ||
) | ||
targetPS.write(buf, off, len) | ||
} | ||
|
||
override def flush(): Unit = { | ||
targetPS.flush() | ||
} | ||
|
||
def addListener(baos: ByteArrayOutputStream): Unit = { | ||
allStreams += baos.hashCode -> baos | ||
} | ||
|
||
def removeListener(baos: ByteArrayOutputStream): Unit = { | ||
allStreams -= baos.hashCode | ||
} | ||
} |