我遵循了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正确地工作。
Windows 7 64位
OpenJDK 8 64位
分级版本3.0 (也使用maven 3.6.1,结果相同)
当我运行代码时,控制台中没有错误,在这两种情况下都会执行完整的程序,但是只有在使用1.2.1版本时,日志才会被发送到Stackdriver。
我需要将Stackdriver集成到我的项目中,我想使用更新的版本。有人知道可能是什么原因吗?
发布于 2020-07-17 14:55:28
我遇到了一个类似的问题,我让它在两个方面发挥作用:
// Writes the log entry synchronously
logging.setWriteSynchronicity(Synchronicity.SYNC);
logging.write(Collections.singleton(entry));// Writes the log entry asynchronously
logging.write(Collections.singleton(entry));
logging.flush();我用的是com.google.cloud:google-cloud-logging:1.101.2
https://stackoverflow.com/questions/57638323
复制相似问题