-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #31 from HuaTru/dev
修改dockerfile环境变量默认值 添加日志处理 docker-compose.yml添加注释
- Loading branch information
Showing
8 changed files
with
503 additions
and
7 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
45 changes: 45 additions & 0 deletions
45
src/main/java/com/coco/boot/config/core/CustomizedApplicationIP.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package com.coco.boot.config.core; | ||
|
||
import ch.qos.logback.classic.pattern.ClassicConverter; | ||
import ch.qos.logback.classic.spi.ILoggingEvent; | ||
import ch.qos.logback.core.spi.PropertyDefiner; | ||
import lombok.extern.slf4j.Slf4j; | ||
|
||
import java.net.InetAddress; | ||
import java.net.UnknownHostException; | ||
|
||
/** | ||
* 自定义logbackIp获取. | ||
* | ||
* @author Hua | ||
* @since 2024-03-20 10:20 | ||
*/ | ||
@Slf4j | ||
public class CustomizedApplicationIP extends ClassicConverter implements PropertyDefiner { | ||
private static String ip; | ||
|
||
static { | ||
try { | ||
ip = InetAddress.getLocalHost().getHostAddress(); | ||
} catch (UnknownHostException e) { | ||
log.error("自定义logbackIp获取异常", e); | ||
} | ||
} | ||
|
||
@Override | ||
public String convert(ILoggingEvent event) { | ||
return ip; | ||
} | ||
|
||
/** | ||
* 用于更新使用IP | ||
*/ | ||
static void updateIp(String eurekaIp) { | ||
ip = eurekaIp; | ||
} | ||
|
||
@Override | ||
public String getPropertyValue() { | ||
return ip; | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
src/main/java/com/coco/boot/config/core/CustomizedRemoteIp.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.coco.boot.config.core; | ||
|
||
import ch.qos.logback.classic.pattern.ClassicConverter; | ||
import ch.qos.logback.classic.spi.ILoggingEvent; | ||
import com.coco.boot.utils.IpUtils; | ||
import jakarta.servlet.http.HttpServletRequest; | ||
import org.springframework.web.context.request.RequestAttributes; | ||
import org.springframework.web.context.request.RequestContextHolder; | ||
import org.springframework.web.context.request.ServletRequestAttributes; | ||
|
||
/** | ||
* 自定义logbackIp获取. | ||
* @author Hua | ||
* @since 2024-03-20 10:20 | ||
*/ | ||
public class CustomizedRemoteIp extends ClassicConverter{ | ||
@Override | ||
public String convert(ILoggingEvent event) { | ||
RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes(); | ||
if (requestAttributes == null) { | ||
return "127.0.0.1"; | ||
} | ||
HttpServletRequest request = ((ServletRequestAttributes) requestAttributes).getRequest(); | ||
return IpUtils.getIpAddr(request); | ||
} | ||
} |
Oops, something went wrong.