當前位置: 首頁>>代碼示例>>Java>>正文


Java MonitoredResource類代碼示例

本文整理匯總了Java中com.google.cloud.MonitoredResource的典型用法代碼示例。如果您正苦於以下問題:Java MonitoredResource類的具體用法?Java MonitoredResource怎麽用?Java MonitoredResource使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


MonitoredResource類屬於com.google.cloud包,在下文中一共展示了MonitoredResource類的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: main

import com.google.cloud.MonitoredResource; //導入依賴的package包/類
/** Expects a new or existing Stackdriver log name as the first argument.*/
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 = args[0];  // "my-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();

  // Writes the log entry asynchronously
  logging.write(Collections.singleton(entry));

  System.out.printf("Logged: %s%n", text);
}
 
開發者ID:GoogleCloudPlatform,項目名稱:java-docs-samples,代碼行數:24,代碼來源:QuickstartSample.java

示例2: testWriteAndListLogs

import com.google.cloud.MonitoredResource; //導入依賴的package包/類
@Test(timeout = 60000)
public void testWriteAndListLogs() throws Exception {
  // write a log entry
  LogEntry entry = LogEntry.newBuilder(StringPayload.of("Hello world again"))
      .setLogName(TEST_WRITE_LOG)
      .setResource(MonitoredResource.newBuilder("global").build())
      .build();
  logging.write(Collections.singleton(entry));
  // flush out log immediately
  logging.flush();
  bout.reset();
  // Check if the log is listed yet
  while (bout.toString().isEmpty()) {
    ListLogs.main(TEST_WRITE_LOG);
    Thread.sleep(5000);
  }
  assertThat(bout.toString().contains("Hello world again")).isTrue();
}
 
開發者ID:GoogleCloudPlatform,項目名稱:java-docs-samples,代碼行數:19,代碼來源:LoggingIT.java

示例3: doPost

import com.google.cloud.MonitoredResource; //導入依賴的package包/類
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp)
    throws ServletException, IOException {

  JsonNode body = objectMapper.readTree(req.getReader());
  String logName = body.path("log_name").asText();
  String token = body.path("token").asText();
  Severity severity = Severity.valueOf(body.path("level").asText());

  LogEntry logEntry = LogEntry.newBuilder(Payload.StringPayload.of(token))
      .setLogName(logName)
      .setSeverity(severity)
      .setResource(MonitoredResource.newBuilder("global").build())
      .build();

  logging.write(Collections.singletonList(logEntry));

  resp.setContentType("text/plain");
  resp.getWriter().println(URLEncoder.encode(logName, "UTF-8"));
}
 
開發者ID:GoogleCloudPlatform,項目名稱:tomcat-runtime,代碼行數:21,代碼來源:CustomLoggingServlet.java


注:本文中的com.google.cloud.MonitoredResource類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。