Add LogWithMarker to Akka Stream #28450
This commit is contained in:
parent
f1dbb79b71
commit
c46861ed26
16 changed files with 937 additions and 9 deletions
|
|
@ -35,12 +35,14 @@ import java.util.Arrays;
|
|||
// #zip
|
||||
|
||||
// #log
|
||||
import akka.event.LogMarker;
|
||||
import akka.stream.Attributes;
|
||||
|
||||
// #log
|
||||
|
||||
import java.time.Duration;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.CompletionStage;
|
||||
|
|
@ -61,6 +63,20 @@ class SourceOrFlow {
|
|||
;
|
||||
}
|
||||
|
||||
void logWithMarkerExample() {
|
||||
Flow.of(String.class)
|
||||
// #logWithMarker
|
||||
.logWithMarker(
|
||||
"myStream", (e) -> LogMarker.create("myMarker", Collections.singletonMap("element", e)))
|
||||
.addAttributes(
|
||||
Attributes.createLogLevels(
|
||||
Attributes.logLevelOff(), // onElement
|
||||
Attributes.logLevelInfo(), // onFinish
|
||||
Attributes.logLevelError())) // onFailure
|
||||
// #logWithMarker
|
||||
;
|
||||
}
|
||||
|
||||
void zipWithIndexExample() {
|
||||
// #zip-with-index
|
||||
Source.from(Arrays.asList("apple", "orange", "banana"))
|
||||
|
|
|
|||
|
|
@ -0,0 +1,26 @@
|
|||
/*
|
||||
* Copyright (C) 2019-2020 Lightbend Inc. <https://www.lightbend.com>
|
||||
*/
|
||||
|
||||
package docs.stream.operators.sourceorflow
|
||||
|
||||
import akka.stream.scaladsl.Flow
|
||||
//#logWithMarker
|
||||
import akka.event.LogMarker
|
||||
import akka.stream.Attributes
|
||||
|
||||
//#logWithMarker
|
||||
|
||||
object LogWithMarker {
|
||||
def logWithMarkerExample(): Unit = {
|
||||
Flow[String]
|
||||
//#logWithMarker
|
||||
.logWithMarker(name = "myStream", e => LogMarker(name = "myMarker", properties = Map("element" -> e)))
|
||||
.addAttributes(
|
||||
Attributes.logLevels(
|
||||
onElement = Attributes.LogLevels.Off,
|
||||
onFinish = Attributes.LogLevels.Info,
|
||||
onFailure = Attributes.LogLevels.Error))
|
||||
//#logWithMarker
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue