- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在 Google Cloud Platform 中运行 Spring Boot 应用程序,并通过 Google Platform Logs Viewer 查看日志文件。在使用 Spring Boot 并仅使用简单的 servlet 之前,日志记录条目将显示为:
每个请求都会被分组,并且可以通过展开行来查看该请求的所有日志记录信息。然而,当使用 Spring Boot 时,请求不再分组,日志条目只是逐行显示。当存在多个请求时,日志条目会变得非常困惑,因为无法以分组方式查看它们。我以同样的方式设置了logging.properties:
.level = INFO
handlers=java.util.logging.ConsoleHandler
java.util.logging.ConsoleHandler.level=FINEST
java.util.logging.ConsoleHandler.formatter=java.util.logging.SimpleFormatter
java.util.logging.SimpleFormatter.format = [%1$tc] %4$s: %2$s - %5$s %6$s%n
记录器在每个类中初始化为:
private static final java.util.logging.Logger LOG = java.util.logging.Logger.getLogger(MyClass.class.getName());
然后日志记录 API 用作:LOG.info("我的消息");
我不明白为什么这些语句以不同的方式记录并且不再分组,但它必须与 Spring Boot 处理日志记录的方式有某种关系?
最佳答案
自最近的运行时以来,AppEngine
的行为越来越与基于容器的方法融合,与其他新产品(例如 Cloud Run)一样更加“开放”。
这稍微改变了我们使用 GAE
进行开发的方式,特定的遗留库不可用(SearchAPI ...),并且它还改变了日志的管理方式。
我们可以使用新的 java11
运行时重现此“嵌套日志功能”,但我们需要自己管理它。
如official docs提到:
In the Logs Viewer, log entries correlated by the same trace can be viewed in a "parent-child" format.
这意味着,如果我们检索请求的 X-Cloud-Trace-Context
HTTP header 中收到的 trace
标识符,我们就可以使用它来添加新的LogEntry
将其作为 trace
标识符属性传递。
这可以通过使用 Stackdriver Logging Client libraries 来完成
幸运的是,Spring Cloud GCP是为了让我们的生活更轻松。
您可以找到sample project它实现了它。请注意,这是一个 AppEngineFlexible
示例,但它可以在 Standard
运行时正常工作。它使用 Logback .
从 GAE Java11
上运行的 Spring Boot 项目,要遵循的步骤是:
spring-cloud-gcp-starter-logging
依赖项:<!-- Starter for Stackriver Logging -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-gcp-starter-logging</artifactId>
<version>1.2.1.RELEASE</version>
</dependency>
src/main/resources
文件夹中添加logback-spring.xml
:<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<include resource="org/springframework/cloud/gcp/autoconfigure/logging/logback-appender.xml" />
<include resource="org/springframework/boot/logging/logback/defaults.xml"/>
<include resource="org/springframework/boot/logging/logback/console-appender.xml" />
<root level="INFO">
<!-- If running in GCP, remove the CONSOLE appender otherwise logs will be duplicated. -->
<appender-ref ref="CONSOLE"/>
<appender-ref ref="STACKDRIVER" />
</root>
</configuration>
src/main/resources/application.properties
内启用 Spring GCP 日志记录功能:spring.cloud.gcp.logging.enabled=true
@SpringBootApplication
@RestController
public class DemoApplication {
private static final Log LOGGER = LogFactory.getLog(DemoApplication.class);
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
@GetMapping()
public SomeData get() {
LOGGER.info("My info message");
LOGGER.warn("My warning message");
LOGGER.error("My error message");
return new SomeData("Hello from Spring boot !");
}
}
结果将显示在 appengine.googleapis.com/request_log
的 Stackdriver Logging
查看器中:
关于google-cloud-platform - Spring Boot 日志记录和 Google Cloud Platform 日志查看器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60115784/
我创建了一个训练作业,我从大查询中获取数据、执行训练和部署模型。我想在这两种情况下自动开始训练: 向数据集添加了 1000 多个新行 有时间表(例如,每周一次) 我检查了 GCP Cloud Sche
我遇到以下警告: WARNING: You do not appear to have access to project [$PROJECT] or it does not exist. 在本地运行
我正在使用 Google Cloud Platform,我必须使用 java 非 Web 应用程序访问云功能,就像我尝试使用 Google Cloud Storage JSON API 从 Googl
我的问题是第三方开发人员如何通过我的身份平台登录用户?我查看了文档,但一无所获。 本质上,我想将 Identity Platform 用作 OIDC 提供者,但我不知道这是否受支持。 最佳答案 Clo
在我去这里的过去 12 个小时左右: https://console.developers.google.com/apis/credentials?project=MYPROJECTNAME 我只是得
我正在尝试创建一个 python 脚本来在 linux 机器上自动安装和配置某些程序。 我的想法是使用平台和多处理库来询问系统信息(platform.system、platform.linux_dis
我正在尝试创建没有控制台网页的 Google Cloud Platform 项目,因为我考虑创建多个项目。 因为我查了gcloud,目前只支持project describe和list。 https:
我正在使用 Google Cloud Scheduler 调用外部应用程序。 Google Cloud Scheduler 使用 OIDC 身份验证并使用服务帐户。我只能从 Google 服务帐户 U
如何在我的 Google Cloud Platform 帐户上启用 Google Authenticator 双重身份验证?我在 Web 界面中上下查看了“IAM 和管理员”,但没有看到在帐户上启用
我们在 Google Cloud 上设置了一个虚拟机,并希望能够自动或计划打开和关闭它。 我们内部有自动脚本,之后可以完成工作,到目前为止,我在 google 的文献中读到的更多与这些实例有关,但我找
我试图删除一个 GCP 项目,但不断弹出以下错误。 Lien origin You cannot delete this project because it is linked with a Dia
我从 Google Domains 购买了一个域,称为 example.com。 我已订阅 G Suite 基本版并创建了一个 admin@example.com 帐户以在 GCP 上使用,而不是我的
我构建了一个包含许多并行进程的 AI Platform 流水线。每个流程都会在 AI Platform 上启动一个训练作业,如下所示: gcloud ai-platform jobs submit t
我们正在验证函数输入时方法参数不为空,但这不适用于 Platform::String (或 Platform.String ,C# 或 C++ 之间没有区别),因为它们用空实例重载空字符串的语义。 考
这个问题比我想来这里的问题要简单一些,但我一直在努力寻找答案,但我绝对不能—— 谷歌云平台 HTTP 函数是否支持路由参数,如此处? http://expressjs.com/en/guide/rou
我正在使用 Kubernetes,我正在尝试创建一个 ingress resource .我使用以下方法创建它: $ kubectl create -f my-ingress.yaml 我等了一会儿,
我是 Google Cloud 的新手,所以我希望得到一些有关“组织”的指导。 我可以将项目从一个“组织”转移到另一个“组织”吗?我正在我的个人 GSuite 组织下启动一些项目,但我必须将它们转移到
在 GET 操作中,我想从返回的集合中排除具有等于“true”的“存档”字段的实体。 我希望这是我的端点(如/users 或/companies)的默认设置,并且我想避免手动添加 URL 过滤器,如
实例模板对于创建托管实例组至关重要。事实上,托管实例组对于在 GCP 中创建自动扩缩组至关重要。 这个问题是另一个问题 question's answer 的一部分,这是关于构建一个自动缩放和负载平衡
我正在将 GCP 用于多个相同的项目。对于每个新项目我都需要一个1 个 GPU 的配额(Tesla K80)。为了申请增加我的GPU配额,我打开console并导航至“IAM 和管理”>“配额”。我在
我是一名优秀的程序员,十分优秀!