Add log() in stream-error.md (#24522)

* Add log() in stream-error.md (#23722)
This commit is contained in:
Richard Imaoka 2018-02-12 23:30:54 +09:00 committed by Christopher Batey
parent cb048457c8
commit b3a27d1c9f
4 changed files with 59 additions and 10 deletions

View file

@ -68,14 +68,14 @@ public class RecipeLoggingElements extends RecipeTest {
{
final Source<String, NotUsed> mySource = Source.from(Arrays.asList("1", "2", "3"));
final int onElement = Logging.WarningLevel();
final int onFinish = Logging.ErrorLevel();
final int onFailure = Logging.ErrorLevel();
//#log-custom
// customise log levels
mySource.log("before-map")
.withAttributes(Attributes.createLogLevels(onElement, onFinish, onFailure))
.withAttributes(Attributes.createLogLevels(
Logging.WarningLevel(), //onElement
Logging.InfoLevel(), //onFinish
Logging.DebugLevel() //onFailure
))
.map(i -> analyse(i));
// or provide custom logging adapter
@ -94,4 +94,18 @@ public class RecipeLoggingElements extends RecipeTest {
};
}
@Test
public void errorLog() throws Exception {
new TestKit(system) {
{
//#log-error
Source.from(Arrays.asList(-1, 0, 1))
.map(x -> 1 / x) //throwing ArithmeticException: / by zero
.log("error logging")
.runWith(Sink.ignore(), mat);
//#log-error
}
};
}
}