Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/322.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如果我们在Google云平台上部署了Spring Boot应用程序,如何查看日志?_Java_Spring_Tomcat_Google Cloud Platform_Ubuntu 16.04 - Fatal编程技术网

Java 如果我们在Google云平台上部署了Spring Boot应用程序,如何查看日志?

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或异常 有两种方法

我们已经开发了一个Spring Boot应用程序,并部署在Google云平台(GCP)中。它是一个计算引擎,我们有
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;
}
}