我试图在Google Stackdriver中写日志,我找到了Google Cloud Loggin库,因此当我尝试这样做时,出现以下错误。
我在此行中有一个错误 尝试(记录日志= options.getService()){
但是我不知道发生了什么。 我已经使用GOOGLE_APPLICATION_CREDENTIALS配置访问权限
日志方法
mystr = "abcd (Read the tnc below!)"
char = ""
for c in mystr:
if c != "(":
char += c
else:
break
IllegalArgumentException:
public void printLogs() throws IOException {
LoggingOptions options = LoggingOptions.getDefaultInstance();
try(Logging logging = options.getService()) {
LogEntry firstEntry = LogEntry.newBuilder(StringPayload.of("message"))
.setLogName("test-log")
.setResource(MonitoredResource.newBuilder("global")
.addLabel("project_id", options.getProjectId())
.build())
.build();
logging.write(Collections.singleton(firstEntry));
} catch (Exception e){
log.error(e.getMessage());
log.error(e.getStackTrace().toString());
}
}
}