Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/2.7.x'
Browse files Browse the repository at this point in the history
  • Loading branch information
li-xunhuan committed Dec 1, 2023
2 parents be7d374 + 55ee81f commit 4db8b20
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
};

}
22 changes: 20 additions & 2 deletions mica-http/src/main/java/net/dreamlu/mica/http/HttpRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 4db8b20

Please sign in to comment.