当前位置: 首页>>代码示例>>Java>>正文


Java Context.getLogger方法代码示例

本文整理汇总了Java中com.amazonaws.services.lambda.runtime.Context.getLogger方法的典型用法代码示例。如果您正苦于以下问题:Java Context.getLogger方法的具体用法?Java Context.getLogger怎么用?Java Context.getLogger使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.amazonaws.services.lambda.runtime.Context的用法示例。


在下文中一共展示了Context.getLogger方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: handleRequest

import com.amazonaws.services.lambda.runtime.Context; //导入方法依赖的package包/类
public TestResult handleRequest(TestRequest testRequest, Context context) {
    LoggerContainer.LOGGER = new Logger(context.getLogger());
    System.setProperty("target.test.uuid", testRequest.getTestRunUUID());

    Optional<Result> result = Optional.empty();
    try {
        BlockJUnit4ClassRunner runner = new BlockJUnit4ClassRunner(getTestClass(testRequest));
        runner.filter(new MethodFilter(testRequest.getFrameworkMethod()));

        result = ofNullable(new JUnitCore().run(runner));
    } catch (Exception e) {
        testResult.setThrowable(e);
        LOGGER.log(e);
    }

    if (result.isPresent()) {
        testResult.setRunCount(result.get().getRunCount());
        testResult.setRunTime(result.get().getRunTime());
        LOGGER.log("Run count: " + result.get().getRunCount());
        result.get().getFailures().forEach(failure -> {
            LOGGER.log(failure.getException());
            testResult.setThrowable(failure.getException());
        });
    }

    return testResult;
}
 
开发者ID:blackboard,项目名称:lambda-selenium,代码行数:28,代码来源:LambdaTestHandler.java

示例2: handleRequest

import com.amazonaws.services.lambda.runtime.Context; //导入方法依赖的package包/类
public Response handleRequest(Request input, Context context) {
    context.getLogger().log("Environment variables:");
    for (String env : System.getenv().keySet())
        context.getLogger().log(String.format("  %s = %s", env, System.getenv(env)));

    String response = "";

    try (
            CacheApi cache = new SyncMemcachedCache(
                    System.getenv("memcachedEndpoint"), 1, TimeUnit.SECONDS, context.getLogger()
            )
    ) {
        Object cached = cache.get("result");
        context.getLogger().log(String.format("Retrieved value from cache: %s", cached));
        response = (String) cache.getOrElse("result", 15 * 60, () -> {
            Long currentEpochTime = System.currentTimeMillis();
            try (
                    Connection conn = DriverManager.getConnection(
                            String.format("jdbc:postgresql://%s/%s", System.getenv("postgresEndpoint"), System.getenv("postgresDatabase")),
                            System.getenv("postgresUser"),
                            System.getenv("postgresPassword")
                    )
            ) {
                Statement stmt = conn.createStatement();
                ResultSet resultSet = stmt.executeQuery("SELECT EXTRACT(EPOCH FROM NOW())");
                if (resultSet.next()) {
                    context.getLogger().log(String.format("Successfully executed query.  Result: %s", resultSet.getLong(1)));
                    currentEpochTime = resultSet.getLong(1) * 1000L;
                }
            } catch (Exception e) {
                context.getLogger().log(String.format("Exception during access to RDS. %s", e.getMessage()));
            }
            return String.format("My message at %s", currentEpochTime);
        });
    } catch (Exception e) {
        context.getLogger().log(String.format("Exception during access to ElastiCache. %s", e.getMessage()));
    }

    return new Response("200", serialize(new ResponseBody(String.format("Message at %s is: %s", System.currentTimeMillis(), response), input)));
}
 
开发者ID:mugglmenzel,项目名称:serverless-examples-cached-rds-ws,代码行数:41,代码来源:Handler.java

示例3: handleRequest

import com.amazonaws.services.lambda.runtime.Context; //导入方法依赖的package包/类
@Override
public Object handleRequest(SNSEvent request, Context context) {
    final LambdaLogger logger = context.getLogger();
    final String message = request.getRecords().get(0).getSNS().getMessage();
    logger.log("Handle message '" + message + "'");

    final List<Recipient> recipients = new CloudNoticeDAO(false)
            .getRecipients();
    final List<String> emailAddresses = recipients.stream()
            .filter(r -> "email".equalsIgnoreCase(r.getType()))
            .map(r -> r.getAddress())
            .collect(Collectors.toList());
    final List<String> phoneNumbers = recipients.stream()
            .filter(r -> "sms".equalsIgnoreCase(r.getType()))
            .map(r -> r.getAddress())
            .collect(Collectors.toList());
    final SesClient sesClient = new SesClient();
    final SnsClient snsClient = new SnsClient();

    sesClient.sendEmails(emailAddresses, "[email protected]",
                    "Cloud Notification", message);
    snsClient.sendTextMessages(phoneNumbers, message);
    sesClient.shutdown();
    snsClient.shutdown();

    logger.log("Message handling complete.");

    return null;
}
 
开发者ID:PacktPublishing,项目名称:Java-9-Programming-Blueprints,代码行数:30,代码来源:SnsEventHandler.java


注:本文中的com.amazonaws.services.lambda.runtime.Context.getLogger方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。