Java 如果我们在Google云平台上部署了Spring Boot应用程序,如何查看日志?
我们已经开发了一个Spring Boot应用程序,并部署在Google云平台(GCP)中。它是一个计算引擎,我们有Java 如果我们在Google云平台上部署了Spring Boot应用程序,如何查看日志?,java,spring,tomcat,google-cloud-platform,ubuntu-16.04,Java,Spring,Tomcat,Google Cloud Platform,Ubuntu 16.04,我们已经开发了一个Spring Boot应用程序,并部署在Google云平台(GCP)中。它是一个计算引擎,我们有ubuntu16.04.5lts作为操作系统和apachetomcat8.5.3作为Web服务器 在这个应用程序中,我们使用了System.out.println()语句,有时我们也会抛出异常 现在我想查看由System.out.println()或通过Exceptions生成的日志,但是如何在谷歌云平台中查看控制台呢 您无法通过System.out.println或异常 有两种方法
ubuntu16.04.5lts
作为操作系统和apachetomcat8.5.3
作为Web服务器
在这个应用程序中,我们使用了System.out.println()语句,有时我们也会抛出异常
现在我想查看由System.out.println()
或通过Exceptions
生成的日志,但是如何在谷歌云平台中查看控制台呢
您无法通过System.out.println
或异常
有两种方法可以实现这一点:
可能但不推荐使用:使用filewriter将日志写入文件,访问文件并读取
推荐:将记录器添加到应用程序中。
为此,请将apache commons登录到应用程序的pom.xml
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.2</version>
</dependency>
公用记录
任何日志级别都将显示所有类型的日志。假设我有30个控制器,那么我是否需要编写这一行private static final log LOGGER=LogFactory.getLog(ExampleController.class)代码>在所有控制器中?是的,您将需要。只是类名会改变。例如,ExampleController.class
将被替换。class
我使用了Apache Commons日志,但如何在计算引擎google云平台中查看日志。请回复gcp控制台,当您登录project时,您可以在菜单中找到logger,如下所示:
@RestController
public class ExampleController {
private static final Log LOGGER = LogFactory.getLog(ExampleController.class);
@RequestMapping("/<custom-url>")
public String function() {
String message = "Example message written to the log";
String secondMessage = "Second example written to the log";
LOGGER.info(message);
LOGGER.info(secondMessage);
return message;
}
}