当前位置: 首页>>代码示例>>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;未经允许,请勿转载。