首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用新的Google日志记录jar时,在Google平台堆栈驱动程序中没有显示日志

使用新的Google日志记录jar时,在Google平台堆栈驱动程序中没有显示日志
EN

Stack Overflow用户
提问于 2019-08-24 13:19:53
回答 1查看 982关注 0票数 1

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

代码语言:javascript
复制
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位

分级版本3.0 (也使用maven 3.6.1,结果相同)

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

我需要将Stackdriver集成到我的项目中,我想使用更新的版本。有人知道可能是什么原因吗?

EN

回答 1

Stack Overflow用户

发布于 2020-07-17 14:55:28

我遇到了一个类似的问题,我让它在两个方面发挥作用:

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

我用的是com.google.cloud:google-cloud-logging:1.101.2

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/57638323

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档