mirror of
https://github.com/Hello-hao/Tbed.git
synced 2024-04-21 12:32:10 +00:00
44 lines
1.2 KiB
Java
44 lines
1.2 KiB
Java
package cn.hellohao.config;
|
|
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.LoggerFactory;
|
|
import org.springframework.context.annotation.Configuration;
|
|
import javax.annotation.PostConstruct;
|
|
import java.io.PrintStream;
|
|
import java.util.function.Consumer;
|
|
|
|
@Configuration
|
|
public class LogSystemProxy {
|
|
|
|
private final static Logger log = LoggerFactory.getLogger("proxy.system.log");
|
|
|
|
@PostConstruct
|
|
public void initProxy(){
|
|
log.debug("LogSystemProxy init .....");
|
|
System.setOut(getLoggerProxy(StdType.OUT));
|
|
System.setErr(getLoggerProxy(StdType.ERR));
|
|
}
|
|
|
|
|
|
private enum StdType{
|
|
OUT(System.out, log::info),
|
|
ERR(System.err, log::error),
|
|
;
|
|
PrintStream stream;
|
|
Consumer<String> consumer;
|
|
StdType(PrintStream stream,Consumer<String> consumer){
|
|
this.stream = stream;
|
|
this.consumer = consumer;
|
|
}
|
|
}
|
|
|
|
private PrintStream getLoggerProxy(StdType stdType){
|
|
return new PrintStream(stdType.stream){
|
|
@Override
|
|
public void print(String s) {
|
|
stdType.stream.print(s);
|
|
stdType.consumer.accept(s);
|
|
}
|
|
};
|
|
}
|
|
} |