@Component
public class SysEnv {
private static final Log logger = LogFactory.getLog(SysEnv.class);
private static String developer = "developer";
private static String release = "release";
private static String master = "master";
@Value("${sys.env}")
private String env;
@Value("${services.active.profile}")
private String activeProfile;
@PostConstruct
public void init() {
System.setProperty("services.active.profile", activeProfile);
logger.info("当前环境为:" + env + ", activeProfile " + activeProfile);
}
private Boolean isDeveloper() {
return developer.equalsIgnoreCase(env);
}
private Boolean isRelease() {
return release.equalsIgnoreCase(env);
}
private Boolean isMaster() {
return master.equalsIgnoreCase(env);
}
private Boolean isNotMaster() {
return !isMaster();
}
/**
* 非生产环境,打印日志
*/
public void logDev(String log, Class clazz) {
if (isNotMaster()) {
logger.info(log + "\n Print By :" + clazz.getName());
}
}
}