sven-lange-last commented on a change in pull request #2878: Streamingly read 
user-logs.
URL: 
https://github.com/apache/incubator-openwhisk/pull/2878#discussion_r152260025
 
 

 ##########
 File path: 
common/scala/src/main/scala/whisk/core/containerpool/logging/DockerLogStore.scala
 ##########
 @@ -17,13 +17,37 @@
 
 package whisk.core.containerpool.logging
 
+import akka.NotUsed
 import akka.actor.ActorSystem
+import akka.stream.ActorMaterializer
+import akka.stream.scaladsl.Sink
+import akka.stream.scaladsl.Flow
+import akka.util.ByteString
 import whisk.common.TransactionId
 import whisk.core.containerpool.Container
 import whisk.core.entity.{ActivationLogs, ExecutableWhiskAction, 
WhiskActivation}
+import spray.json._
 
 import scala.concurrent.{ExecutionContext, Future}
 
+/**
+ * Represents a single log line as read from a docker log
+ */
+protected[core] case class LogLine(time: String, stream: String, log: String) {
+  def toFormattedString = f"$time%-30s $stream: ${log.trim}"
+}
+
+protected[core] object LogLine extends DefaultJsonProtocol {
+  implicit val serdes = jsonFormat3(LogLine.apply)
+}
+
+object DockerLogStore {
+
+  /** Transforms chunked JsObjects into formatted strings */
+  val toFormattedString: Flow[ByteString, String, NotUsed] =
+    
Flow[ByteString].map(_.utf8String.parseJson.convertTo[LogLine].toFormattedString)
+}
 
 Review comment:
   What's the behaviour of the `toFormattedString` flow if a truncated log line 
arrives? This may happen if a log limit is reached while reading.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to