Last active
November 23, 2022 13:11
-
-
Save iromu/db8836d338122e7b800a68b36981e929 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.jetbrains.annotations.Nullable; | |
import java.io.OutputStream; | |
import java.io.PrintStream; | |
import java.io.UnsupportedEncodingException; | |
public class PackagePrintStream extends PrintStream { | |
public PackagePrintStream(OutputStream out, boolean autoFlush, String encoding) throws UnsupportedEncodingException { | |
super(out, autoFlush, encoding); | |
} | |
@Override | |
public void println(@Nullable String x) { | |
if (allow()) { | |
super.println(x); | |
} | |
} | |
private boolean allow() { | |
String cn = inferCaller().getClassName(); | |
return !cn.startsWith("org.springframework.cloud.function.context.catalog.SimpleFunctionRegistry$FunctionInvocationWrapper"); | |
} | |
private boolean isPrintImplFrame(String cname) { | |
return PackagePrintStream.class.getName().equals(cname); | |
} | |
private StackTraceElement inferCaller() { | |
StackTraceElement stack[] = (new Throwable()).getStackTrace(); | |
int ix = 0; | |
while (ix < stack.length) { | |
StackTraceElement frame = stack[ix]; | |
String cname = frame.getClassName(); | |
if (isPrintImplFrame(cname)) { | |
break; | |
} | |
ix++; | |
} | |
while (ix < stack.length) { | |
StackTraceElement frame = stack[ix]; | |
String cname = frame.getClassName(); | |
if (!isPrintImplFrame(cname)) { | |
return frame; | |
} | |
ix++; | |
} | |
return new StackTraceElement(PackagePrintStream.class.getName(), "write", | |
PackagePrintStream.class.getName(), -1); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://github.com/spring-cloud/spring-cloud-function/issues/962 | |
static { | |
try { | |
System.setOut(new PackagePrintStream(System.out, true, "UTF-8")); | |
} catch (UnsupportedEncodingException e) { | |
throw new RuntimeException(e); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment