【问题标题】:Logs not showing in Google Cloud Platform Stackdriver when using new Google Cloud logging jar使用新的 Google Cloud 日志记录 jar 时,日志未显示在 Google Cloud Platform Stackdriver 中
【发布时间】:2019-12-29 11:44:15
【问题描述】:

我遵循了Java logging libraries 上的文档,QuickstartSample.java 是一个简单的 API 调用,用于将数据记录到 Stackdriver。

public class QuickstartSample {

  public static void main(String... args) throws Exception {

    // Instantiates a client
    Logging logging = LoggingOptions.getDefaultInstance().getService();

    // The name of the log to write to
    String logName = "test-log";

    // The data to write to the log
    String text = "Hello, world!";

    LogEntry entry = LogEntry.newBuilder(StringPayload.of(text))
            .setSeverity(Severity.ERROR)
            .setLogName(logName)
            .setResource(MonitoredResource.newBuilder("global").build())
            .build();

            logging.write(Collections.singleton(entry));

     System.out.printf("Logged: %s%n", text);

  }
}

当我使用com.google.cloud:google-cloud-logging:1.87.0 版本时,没有显示任何日志条目。

它可以在旧版本com.google.cloud:google-cloud-logging:1.2.1 上正常工作

Windows 7 64 位

OpenJDK 8 64 位

Gradle 3.0 版 (也与 maven 3.6.1 相同的结果)

运行代码时控制台没有错误,两种情况下都执行了完整的程序,但只有在使用 1.2.1 版本时才会将日志发送到 Stackdriver。

我需要将 Stackdriver 与我的项目集成,并且我想使用更新的版本。有谁知道这可能的原因吗?

【问题讨论】:

  • 您能告诉我们您正在使用哪个构建器吗? Gradle,您是否尝试过任何故障排除工具以了解日志信息的确切存储位置 [1]。我建议您尽可能详细地分享您的通话方式。注意 com.google.cloud:google-cloud-logging 最新版本是 1.88.0 看看这个 github 文档 (github.com/googleapis/google-cloud-java/tree/master/…) [1] cloud.google.com/logging/docs/agent/troubleshooting
  • 我已在问题中添加了详细信息。我尝试了 1.88.0 版本,但结果与 1.87.0 相同。我的项目密钥已经到位,它可以与旧 jar 一起正常工作。我没有使用任何调试工具,您有什么建议可以帮助我吗?
  • 嗨 Divya,你找到解决方案了吗,我也遇到了同样的问题。

标签: java google-cloud-platform stackdriver google-cloud-stackdriver google-cloud-logging


【解决方案1】:

我遇到了类似的问题,我通过两种方式解决了问题:

  1. 通过将写入同步性设置为同步来运行同步调用:
// Writes the log entry synchronously
logging.setWriteSynchronicity(Synchronicity.SYNC);
logging.write(Collections.singleton(entry));
  1. 通过刷新异步调用:
// Writes the log entry asynchronously
logging.write(Collections.singleton(entry));
logging.flush();

我正在使用com.google.cloud:google-cloud-logging:1.101.2

【讨论】:

    猜你喜欢
    • 2017-08-15
    • 2019-02-21
    • 2020-02-26
    • 2023-03-12
    • 2017-11-08
    • 1970-01-01
    • 2020-06-26
    • 2020-09-12
    • 1970-01-01
    相关资源
    最近更新 更多