Skip to content
This repository has been archived by the owner on Apr 11, 2022. It is now read-only.

Stream Stdout/Stderr instead of buffering #26

Open
muuki88 opened this issue Jul 4, 2014 · 2 comments
Open

Stream Stdout/Stderr instead of buffering #26

muuki88 opened this issue Jul 4, 2014 · 2 comments

Comments

@muuki88
Copy link

muuki88 commented Jul 4, 2014

Currently all logging is buffered inside a ByteString builder,
which let's long running tasks appear unresponsive (e.g. rjs
optimize).

I tried to get my head around the Engine class and implementing a simple
logging trait where other logging implementations, such as sbt.streams,
can easily be wrapped.

However I failed handling the ByteStrings and the context.become calls.
My Logger trait looks essentially like this

trait Logger {
    // var in trait?
    var outputBuilder = ByteString.newBuilder

    def info(msg: => String): Unit

    def infoRaw(bytes: => ByteString): Unit = {
      outputBuilder ++= bytes
      outputBuilder = outputBuilder.result.utf8String match {
        case content if !content.contains("\n") => outputBuilder ++= bytes
        case content =>
          val rest = content.split("\n") match {
            case Array(out, rest) => info(out); rest
          }
          ByteString.newBuilder ++= ByteString(rest, "UTF-8")
      }
    }
}
@huntc
Copy link

huntc commented Jul 7, 2014

The fix for this is essentially on declaring a new type of message extending this:

https://github.com/typesafehub/js-engine/blob/master/src/main/scala/com/typesafe/jse/Engine.scala#L100

Taking Trireme as an example, where the message is handled:

https://github.com/typesafehub/js-engine/blob/master/src/main/scala/com/typesafe/jse/Trireme.scala#L36

...an addition handler is required for the new message, passing in the stdinSink, stdoutSource and stderrSource actors. Your communication will then be with these sink and source actors.

So that you know: the source and sink abstractions will be replaced in a few months with their equivalents from akka-streams. :-) However they will be semantically similar.

HTH.

@huntc
Copy link

huntc commented Apr 29, 2016

On a related note, I've observed the following when using sbt-mocha:

[trace] Stack trace suppressed: run last conductrHaproxy/*:mochaExecuteTests for the full output.
[error] (conductrHaproxy/*:mochaExecuteTests) spray.json.JsonParser$ParsingException: Unexpected end-of-input at input index 1023 (line 1, position 1024), expected '}':
[error]  {"title":"","suites":[{"title":"generate","filename":"/Users/huntc/Projects/typesafe/conductr/conductr-haproxy/target/web/public/test/generateSpec.js","suites":[{"title":"Handlebars helper functions","suites":[{"title":"haproxyHost","suites":[],"tests":[{"title":"returns HAProxy Host value","status":"pass","duration":6}]},{"title":"overrideConfigDir","suites":[],"tests":[{"title":"returns empty string if undefined","status":"pass","duration":3},{"title":"returns supplied value","status":"pass","duration":2}]},{"title":"haproxyConf","suites":[],"tests":[{"title":"returns nested result when declared as block template","status":"pass","duration":9},{"title":"returns an empty string if not declared as block helper","status":"pass","duration":2}]},{"title":"serviceFrontends","suites":[],"tests":[{"title":"returns the result from TemplatingFunctions","status":"pass","duration":4}]},{"title":"serviceBackends","suites":[],"tests":[{"title":"returns the result from TemplatingFunctions","status":"pass","duration":2}]
[error]                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                ^

This means that there's some overflow going on...

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants