com.amazonaws.services.logs.AWSLogs Java Examples

The following examples show how to use com.amazonaws.services.logs.AWSLogs. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CloudwatchMetadataHandler.java    From aws-athena-query-federation with Apache License 2.0 5 votes vote down vote up
@VisibleForTesting
protected CloudwatchMetadataHandler(AWSLogs awsLogs,
        EncryptionKeyFactory keyFactory,
        AWSSecretsManager secretsManager,
        AmazonAthena athena,
        String spillBucket,
        String spillPrefix)
{
    super(keyFactory, secretsManager, athena, SOURCE_TYPE, spillBucket, spillPrefix);
    this.awsLogs = awsLogs;
    tableResolver = new CloudwatchTableResolver(invoker, awsLogs, MAX_RESULTS, MAX_RESULTS);
}
 
Example #2
Source File: AwsConfig.java    From cloudwatch-logback-appender with Apache License 2.0 5 votes vote down vote up
public AWSLogs createAWSLogs() {
    AWSLogsClientBuilder builder = AWSLogsClientBuilder.standard();

    if(region!=null) {
        builder.withRegion(region);
    }

    if(clientConfig!=null) {
        builder.withClientConfiguration(clientConfig);
    }

    if(profileName!=null) {
        builder.withCredentials(new ProfileCredentialsProvider(profileName));
    }
    else if(credentials!=null) {
        builder.withCredentials(new AWSStaticCredentialsProvider(credentials));
    }

    return builder.build();
}
 
Example #3
Source File: CloudwatchLogsLogEventPutter.java    From cloudwatchlogs-java-appender with Apache License 2.0 5 votes vote down vote up
/**
 * For internal use only. This constructor lets us switch the AWSLogs implementation for testing.
 */
protected CloudwatchLogsLogEventPutter(CloudwatchLogsConfig config, BlockingQueue<CloudwatchLogsLogEvent> eventQueue,
                                       AWSLogs awsLogs, boolean enabled) {
    this.config = config;
    maxFlushDelay = config.getMaxFlushDelay() * 1000000;
    logGroupName = config.getLogGroup();
    String image = config.getImage();
    app = image.substring(0, image.indexOf(":"));
    this.eventQueue = eventQueue;
    this.enabled = enabled;
    logsClient = awsLogs;
}
 
Example #4
Source File: CloudwatchLogsLogEventPutter.java    From cloudwatchlogs-java-appender with Apache License 2.0 5 votes vote down vote up
static AWSLogs createLogsClient(CloudwatchLogsConfig config) {
    AWSLogsClientBuilder builder = AWSLogsClientBuilder.standard();
    if (config.getEndpoint() != null) {
        // Non-AWS mock endpoint
        builder.setCredentials(new AWSStaticCredentialsProvider(new AnonymousAWSCredentials()));
        builder.setEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration(config.getEndpoint(), config.getRegion()));
    } else {
        builder.setRegion(config.getRegion());
    }
    return builder.build();
}
 
Example #5
Source File: PutSubscriptionFilter.java    From aws-doc-sdk-examples with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) {

        final String USAGE =
            "To run this example, supply:\n" +
            "* a filter name\n" +
            "* filter pattern\n" +
            "* log group name\n" +
            "* lambda function arn\n\n" +
            "Ex: PutSubscriptionFilter <filter-name> \\\n" +
            "                          <filter pattern> \\\n" +
            "                          <log-group-name> \\\n" +
            "                          <lambda-function-arn>\n";

        if (args.length != 4) {
            System.out.println(USAGE);
            System.exit(1);
        }

        String filter = args[0];
        String pattern = args[1];
        String log_group = args[2];
        String function_arn = args[3];

        final AWSLogs cwl = AWSLogsClientBuilder.defaultClient();

        PutSubscriptionFilterRequest request =
            new PutSubscriptionFilterRequest()
                .withFilterName(filter)
                .withFilterPattern(pattern)
                .withLogGroupName(log_group)
                .withDestinationArn(function_arn);

        PutSubscriptionFilterResult response =
            cwl.putSubscriptionFilter(request);

        System.out.printf(
            "Successfully created CloudWatch logs subscription filter %s",
            filter);
    }
 
Example #6
Source File: DeleteSubscriptionFilter.java    From aws-doc-sdk-examples with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) {

        final String USAGE =
            "To run this example, supply a filter name and log group name\n" +
            "Ex: DeleteSubscriptionFilter <filter-name> <log-group-name>\n";

        if (args.length != 2) {
            System.out.println(USAGE);
            System.exit(1);
        }

        String filter = args[0];
        String log_group = args[1];

        final AWSLogs logs = AWSLogsClientBuilder.defaultClient();

        DeleteSubscriptionFilterRequest request =
            new DeleteSubscriptionFilterRequest()
                .withFilterName(filter)
                .withLogGroupName(log_group);

        DeleteSubscriptionFilterResult response =
            logs.deleteSubscriptionFilter(request);

        System.out.printf(
            "Successfully deleted CloudWatch logs subscription filter %s",
            filter);
    }
 
Example #7
Source File: LocalstackContainerTest.java    From testcontainers-java with MIT License 5 votes vote down vote up
@Test
public void cloudWatchLogsTestOverBridgeNetwork() {
    AWSLogs logs = AWSLogsClientBuilder.standard()
            .withEndpointConfiguration(localstack.getEndpointConfiguration(CLOUDWATCHLOGS))
            .withCredentials(localstack.getDefaultCredentialsProvider()).build();

    logs.createLogGroup(new CreateLogGroupRequest("foo"));

    List<LogGroup> groups = logs.describeLogGroups().getLogGroups();
    assertEquals("One log group should be created", 1, groups.size());
    assertEquals("Name of created log group is [foo]", "foo", groups.get(0).getLogGroupName());
}
 
Example #8
Source File: CloudwatchRecordHandler.java    From aws-athena-query-federation with Apache License 2.0 4 votes vote down vote up
@VisibleForTesting
protected CloudwatchRecordHandler(AmazonS3 amazonS3, AWSSecretsManager secretsManager, AmazonAthena athena, AWSLogs awsLogs)
{
    super(amazonS3, secretsManager, athena, SOURCE_TYPE);
    this.awsLogs = awsLogs;
}
 
Example #9
Source File: DescribeSubscriptionFilters.java    From aws-doc-sdk-examples with Apache License 2.0 4 votes vote down vote up
public static void main(String[] args) {

        final String USAGE =
            "To run this example, supply a log group name\n" +
            "Ex: DescribeSubscriptionFilters <log-group-name>\n";

        if (args.length != 1) {
            System.out.println(USAGE);
            System.exit(1);
        }

        String log_group = args[0];

        final AWSLogs logs = AWSLogsClientBuilder.defaultClient();
        boolean done = false;

        DescribeSubscriptionFiltersRequest request =
                new DescribeSubscriptionFiltersRequest()
                    .withLogGroupName(log_group)
                    .withLimit(1);

        while(!done) {

            DescribeSubscriptionFiltersResult response =
                logs.describeSubscriptionFilters(request);

            for(SubscriptionFilter filter : response.getSubscriptionFilters()) {
                System.out.printf(
                    "Retrieved filter with name %s, " +
                    "pattern %s " +
                    "and destination arn %s",
                    filter.getFilterName(),
                    filter.getFilterPattern(),
                    filter.getDestinationArn());
            }

            request.setNextToken(response.getNextToken());

            if(response.getNextToken() == null) {
                done = true;
            }
        }
    }
 
Example #10
Source File: CloudwatchLogsLogEventPutter.java    From cloudwatchlogs-java-appender with Apache License 2.0 2 votes vote down vote up
/**
 * Creates a new EventPutter for the current AWS region.
 *
 * @param config     The config to use.
 * @param eventQueue The event queue to consume from.
 * @return The new EventPutter.
 */
public static CloudwatchLogsLogEventPutter create(CloudwatchLogsConfig config, BlockingQueue<CloudwatchLogsLogEvent> eventQueue) {
    boolean enabled = config.getRegion() != null || config.getEndpoint() != null;
    AWSLogs logsClient = enabled ? createLogsClient(config) : null;
    return new CloudwatchLogsLogEventPutter(config, eventQueue, logsClient, enabled);
}