如何在日志记录信息下获取主机名或帖子号?这不起作用:
logging.pattern.console=%d{yyyy-MM-dd HH:mm:ss.SSS} %d{localhost} ---- %msg%n
答案 0 :(得分:0)
ApplicationListener<EmbeddedServletContainerInitializedEvent>
。供参考:
@SpringBootApplication
@EnableSwagger2
public class SpringBootAppMain implements ApplicationListener<EmbeddedServletContainerInitializedEvent> {
@Autowired
Environment environment;
public static void main(String[] args) {
SpringApplication.run(SpringBootAppMain.class, args);
}
@Override
public void onApplicationEvent(EmbeddedServletContainerInitializedEvent embeddedServletContainerInitializedEvent) {
System.out.println("Port " + embeddedServletContainerInitializedEvent.getApplicationContext().getEmbeddedServletContainer().getPort());
try {
System.out.println("HOST Address " + InetAddress.getLocalHost().getHostAddress());
System.out.println("Host Name " + InetAddress.getLocalHost().getHostName());
} catch (UnknownHostException e) {
}
}
}