diff --git a/mica-http/src/main/java/net/dreamlu/mica/http/HttpSel4jLogger.java b/mica-http/src/main/java/net/dreamlu/mica/http/HttpLogger.java similarity index 64% rename from mica-http/src/main/java/net/dreamlu/mica/http/HttpSel4jLogger.java rename to mica-http/src/main/java/net/dreamlu/mica/http/HttpLogger.java index 7ae9e4fbb..3dc8d8fba 100644 --- a/mica-http/src/main/java/net/dreamlu/mica/http/HttpSel4jLogger.java +++ b/mica-http/src/main/java/net/dreamlu/mica/http/HttpLogger.java @@ -22,21 +22,32 @@ import javax.annotation.Nonnull; /** - * OkHttp Slf4j log. + * OkHttp logger, Slf4j and console log. * * @author L.cm */ @Slf4j -public enum HttpSel4jLogger implements HttpLoggingInterceptor.Logger { +public enum HttpLogger implements HttpLoggingInterceptor.Logger { /** - * 实例 + * http 日志:Slf4j */ - INSTANCE; + Slf4j() { + @Override + public void log(@Nonnull String message) { + log.info(message); + } + }, - @Override - public void log(@Nonnull String message) { - log.info(message); - } + /** + * http 日志:Console + */ + Console() { + @Override + public void log(@Nonnull String message) { + // 统一添加前缀,方便在茫茫日志中查看 + System.out.printf("HttpLogger: %s\n", message); + } + }; } diff --git a/mica-http/src/main/java/net/dreamlu/mica/http/HttpRequest.java b/mica-http/src/main/java/net/dreamlu/mica/http/HttpRequest.java index 4b0fbd31f..5120d503f 100644 --- a/mica-http/src/main/java/net/dreamlu/mica/http/HttpRequest.java +++ b/mica-http/src/main/java/net/dreamlu/mica/http/HttpRequest.java @@ -422,7 +422,7 @@ public HttpRequest useSlf4jLog() { } public HttpRequest useSlf4jLog(LogLevel logLevel) { - return useLog(HttpSel4jLogger.INSTANCE, logLevel); + return useLog(HttpLogger.Slf4j, logLevel); } public HttpRequest useConsoleLog() { @@ -582,7 +582,25 @@ public static void setHttpClient(OkHttpClient httpClient) { * @param logLevel LogLevel */ public static void setGlobalLog(LogLevel logLevel) { - setGlobalLog(HttpSel4jLogger.INSTANCE, logLevel); + setGlobalLog(HttpLogger.Slf4j, logLevel); + } + + /** + * 设置全局日志,平台自带日志,默认 jdk 日志 + * + * @param logLevel LogLevel + */ + public static void setGlobalDefaultLog(LogLevel logLevel) { + setGlobalLog(HttpLoggingInterceptor.Logger.DEFAULT, logLevel); + } + + /** + * 设置全局日志,控制台日志 + * + * @param logLevel LogLevel + */ + public static void setGlobalConsoleLog(LogLevel logLevel) { + setGlobalLog(HttpConsoleLogger.INSTANCE, logLevel); } public static void setGlobalLog(HttpLoggingInterceptor.Logger logger, LogLevel logLevel) {