我正在使用带有SLF4J的Logback进行Stackdriver日志记录,并且我遵循Google Cloud中的示例。我的应用程序是用scala编写的,并且在GCP的Dataproc集群上运行。
logback.xml具有以下内容。
<configuration>
<appender name="CLOUD" class="com.google.cloud.logging.logback.LoggingAppender">
<!-- Optional : filter logs at or above a level -->
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
<level>INFO</level>
</filter>
<log>application.log</log> <!-- Optional : default java.log -->
<resourceType>gae_app</resourceType> <!-- Optional : default: auto-detected, fallback: global -->
<enhancer>com.company.customer.utils.MyLoggingEnhancer</enhancer> <!-- Optional -->
<flushLevel>WARN</flushLevel> <!-- Optional : default ERROR -->
</appender>
<root level="info">
<appender-ref ref="CLOUD" />
</root>
</configuration>
并且MyLoggingEnhancer是
package com.company.customer.utils
import com.google.cloud.logging.LogEntry.Builder
import com.google.cloud.logging.LoggingEnhancer
class MyLoggingEnhancer extends LoggingEnhancer {
override def enhanceLogEntry(builder: Builder): Unit = {
builder
.addLabel("test-label-1", "test-value-1") //also not showing on the stack driver
}
}
我正在构造类中的日志记录对象
private val LOGGER: Logger = LoggerFactory.getLogger(this.getClass)
我从
这样的记录器对象记录了一条消息LOGGER.info("Spark Streaming Started for MyApplication")
问题是resourceType,并且在堆栈驱动程序日志中未正确设置logName。 logName自动设置为 yarn-userlogs ,resourceType设置为 cloud_dataproc_cluster 。我要设置 resourceType = Global 和 logName = MyApp ,以便我可以在“全局”层次结构下过滤MyApp日志。
从logback.xml中删除此行后,我尝试了
<resourceType>gae_app</resourceType>
并添加此行
<resourceType>global</resourceType>
但是没有运气。任何形式的帮助都值得赞赏。我在LoggingEnhancer中提供的标签 test-label-1 也未显示在堆栈驱动程序上。
我的Json堆栈驱动程序有效载荷为
{
insertId: "gn8clokwpjqptwo5h"
jsonPayload: {
application: "application_1568634817510_0189"
class: "com.MyClass"
container: "container_e01_1568634817510_0189_01_000001"
container_logname: "stderr"
filename: "application_1568634817510_0189.container_e01_1568634817510_0189_01_000001.stderr"
message: "Spark Streaming Started for MyApplication"
}
labels: {
compute.googleapis.com / resource_id: "1437319101399877659"
compute.googleapis.com / resource_name: "e-spark-w-2"
compute.googleapis.com / zone: "us"
}
logName: "projects/myProject/logs/yarn-userlogs"
receiveTimestamp: "2019-10-01T05:25:16.044579001Z"
resource: {
labels: {
cluster_name: "shuttle-spark"
cluster_uuid: "d1557db6-72ee-4873-a276-4bd4ea0e89bb"
project_id: "MyProjectId"
region: "us"
}
type: "cloud_dataproc_cluster"
}
severity: "INFO"
timestamp: "2019-10-01T05:25:10Z"
}