From 550f349a84214b1570babe4355c4eeb626c49201 Mon Sep 17 00:00:00 2001 From: Ace Nassri Date: Fri, 20 Mar 2020 20:48:08 -0700 Subject: [PATCH] functions/logging: add stdout/stderr + ignored logs severity note (#2422) ~@vinod-at-google @labtopia IIRC the lack of log severity info is a known issue. (If it's not, let me know so I can hold off on merging this PR.)~ --- .../src/main/java/com/example/functions/LogHelloWorld.java | 4 ++++ .../src/test/java/com/example/functions/SnippetsTests.java | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/functions/snippets/src/main/java/com/example/functions/LogHelloWorld.java b/functions/snippets/src/main/java/com/example/functions/LogHelloWorld.java index 64457523ce4..944330f348e 100644 --- a/functions/snippets/src/main/java/com/example/functions/LogHelloWorld.java +++ b/functions/snippets/src/main/java/com/example/functions/LogHelloWorld.java @@ -32,6 +32,10 @@ public class LogHelloWorld implements HttpFunction { @Override public void service(HttpRequest request, HttpResponse response) throws IOException { + System.out.println("I am a log to stdout!"); + System.err.println("I am a log to stderr!"); + + // Stackdriver does not detect severity from Cloud Functions log output LOGGER.info("I am an info log!"); LOGGER.warning("I am a warning log!"); diff --git a/functions/snippets/src/test/java/com/example/functions/SnippetsTests.java b/functions/snippets/src/test/java/com/example/functions/SnippetsTests.java index c13a6aa3b9e..e1736f63bbc 100644 --- a/functions/snippets/src/test/java/com/example/functions/SnippetsTests.java +++ b/functions/snippets/src/test/java/com/example/functions/SnippetsTests.java @@ -90,7 +90,7 @@ public void beforeTest() throws IOException { @After public void afterTest() { - System.setOut(null); + System.out.flush(); logHandler.flush(); }