繁体   English   中英

使用新的 Google Cloud 日志记录 jar 时,日志未显示在 Google Cloud Platform Stackdriver 中

[英]Logs not showing in Google Cloud Platform Stackdriver when using new Google Cloud logging jar

我遵循有关Java 日志记录库的文档, 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

视窗 7 64 位

OpenJDK 8 64 位

Gradle 3.0 版(还有 maven 3.6.1,结果相同)

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

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

我遇到了类似的问题,我让它以两种方式工作:

  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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM