gpt4 book ai didi

Spring Boot 日志打印到 Google App Engine 每条日志一行,没有元数据

转载 作者:行者123 更新时间:2023-12-03 04:04:25 25 4
gpt4 key购买 nike

我正在将一个 SpringBoot 应用程序部署到 Docker 容器内的 Google Appengine,该应用程序按预期工作,但日志记录非常糟糕。出于某种原因,它会将每个应该输出的日志作为单独的行打印出来。此外,日志似乎丢失了一些元数据,因为日志级别被打印出来但 Google App Engine 日志查看器无法理解。知道可以做些什么来帮助控制台理解日志吗?

这是我所看到的一些图像。您可以看到日志正在单独打印每一行,即使是明确的信息、警告或错误的日志也不会在 google appengine 日志查看器中显示为这些级别。

This image shows logs made using the java.util.logging.Logger where I've logged something as info, warning, and sever.  We see the logs have their appropriate log level but the appengine console does not

This image shows the spring boot startup logs where every log has been cut into its own individual line and printed out.

这是我的项目的 gradle 构建文件的摘录:

apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'spring-boot'
apply plugin: 'sonar-runner'
apply plugin: 'appengine'
apply plugin: 'io.spring.dependency-management'
apply plugin: 'war'

jar {
baseName = 'consumer'
version = '0.0.1-SNAPSHOT'
}
sourceCompatibility = 1.7
targetCompatibility = 1.7

repositories {
mavenCentral()
}

dependencies {
compile("org.springframework.boot:spring-boot-starter-amqp")
compile("org.springframework.boot:spring-boot-starter-web")
exclude module: "spring-boot-starter-tomcat"
compile("org.springframework.boot:spring-boot-starter-jetty")
compile("org.codehaus.jackson:jackson-mapper-asl:1.9.10")
testCompile("org.springfraework.boot:spring-boot-starter-test")
}


eclipse {
classpath {
containers.remove('org.eclipse.jdt.launching.JRE_CONTAINER')
containers 'org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7'
}
}

task wrapper(type: Wrapper) {
gradleVersion = '2.3'
}

最佳答案

docs在托管虚拟机/自定义运行时状态下,您应该将日志写入虚拟机文件系统上的某个位置:/var/log/app_engine/custom_logs .然后您可以阅读 logs viewer确定是否可以根据日志行内容识别日志级别。

可以简单地使用标准 Java Logger如果你的 Dockerfile 的镜像是 gcr.io/google_appengine/java-compat (未指定 Dockerfile 时使用的图像),只需使用 gcloud preview app deploy命令(此命令的名称将来会更改)根据您的 WAR 文件夹进行部署。

在这种情况下,使用 the standard Logger class and it's method log() 如果您适本地设置日志级别,则可能会起作用,而不是仅将预期级别作为日志行的前缀,如您的输出中所见。

我不熟悉 Spring 本身以及您将如何指示它执行此操作,因为似乎您不是负责它只是为其预期日志级别添加前缀的方式的人,但至少我的回答包括让您知道这是在您使用 java appengine docker 镜像 (gcr.io/google_appengine/java-compat) 的情况下正确显示开发人员控制台日志的关键。

关于Spring Boot 日志打印到 Google App Engine 每条日志一行,没有元数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30399521/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com