郑永安
2023-06-19 7a6abd05683528032687c75e80e0bd2030a3e46c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package com.gkhy.safePlatform.safeCheck.util;
 
 
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.PropertySource;
import org.springframework.stereotype.Component;
 
import javax.annotation.PostConstruct;
import java.text.SimpleDateFormat;
import java.util.Date;
 
 
@Component
public class ConsolePrintIfEnvIsDevUtil {
 
    private static String currentActiveEnv;
 
    private static Boolean currentEnvIsDev = false;
 
    @Value("${spring.profiles.active}")
    public void setEnv(String activeEnv){
        currentActiveEnv = activeEnv;
    }
 
 
    @PostConstruct
    private void currentEnvIsDev(){
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String dateTime = df.format(new Date());
 
        if ("dev".equals(currentActiveEnv)){
            currentEnvIsDev = true;
            System.out.println("【##】"+dateTime + " - 当前环境:【"+currentActiveEnv+"】 - 控制台 打印内容");
        }else {
            System.out.println("【##】"+dateTime + " - 当前环境:【"+currentActiveEnv+"】 - 控制台✖不输出内容");
        }
    }
 
    public static void consolePrintIfEnvIsDev(String printContent){
        if (currentEnvIsDev){
            System.out.println("当前环境:"+currentActiveEnv+" 控制台输出-->>"+printContent);
        }
    }
}