Search in sources :

Example 6 with AWSLogsClient

use of com.amazonaws.services.logs.AWSLogsClient in project cloudwatch-logback-appender by j256.

the class SystemPropertyConverterTest method testStuff.

@Test(timeout = 5000)
public void testStuff() throws InterruptedException {
    String propName = "os.version";
    String propValue = System.getProperty(propName);
    assertNotNull(propValue);
    AWSLogsClient awsLogClient = createMock(AWSLogsClient.class);
    appender.setAwsLogsClient(awsLogClient);
    String prefix = "logstream-";
    appender.setLogStream(prefix + "%systemProperty{" + propName + "}");
    final String expectedLogStream = prefix + propValue;
    PatternLayout layout = new PatternLayout();
    layout.setPattern("%msg");
    layout.setContext(LOGGER_CONTEXT);
    layout.start();
    appender.setLayout(layout);
    LoggingEvent event = new LoggingEvent();
    event.setTimeStamp(System.currentTimeMillis());
    event.setLoggerName("name");
    event.setLevel(Level.DEBUG);
    event.setMessage("message");
    final PutLogEventsResult result = new PutLogEventsResult();
    result.setNextSequenceToken("ewopjfewfj");
    expect(awsLogClient.putLogEvents(isA(PutLogEventsRequest.class))).andAnswer(new IAnswer<PutLogEventsResult>() {

        @Override
        public PutLogEventsResult answer() {
            PutLogEventsRequest request = (PutLogEventsRequest) getCurrentArguments()[0];
            assertEquals(LOG_GROUP, request.getLogGroupName());
            assertEquals(expectedLogStream, request.getLogStreamName());
            return result;
        }
    });
    awsLogClient.shutdown();
    // =====================================
    replay(awsLogClient);
    appender.start();
    appender.append(event);
    while (appender.getEventsWrittenCount() < 1) {
        Thread.sleep(10);
    }
    appender.stop();
    verify(awsLogClient);
}
Also used : LoggingEvent(ch.qos.logback.classic.spi.LoggingEvent) AWSLogsClient(com.amazonaws.services.logs.AWSLogsClient) PatternLayout(ch.qos.logback.classic.PatternLayout) PutLogEventsResult(com.amazonaws.services.logs.model.PutLogEventsResult) PutLogEventsRequest(com.amazonaws.services.logs.model.PutLogEventsRequest) Test(org.junit.Test)

Example 7 with AWSLogsClient

use of com.amazonaws.services.logs.AWSLogsClient in project cloudwatch-logback-appender by j256.

the class Ec2InstanceIdConverterTest method testInstanceId.

@Test(timeout = 10000)
public void testInstanceId() throws InterruptedException {
    String instanceId = "fewhwehpewpf";
    Ec2InstanceIdConverter.setInstanceId(instanceId);
    AWSLogsClient awsLogClient = createMock(AWSLogsClient.class);
    appender.setAwsLogsClient(awsLogClient);
    String prefix = "logstream-";
    appender.setLogStream(prefix + "%instanceId");
    final String expectedLogStream = prefix + instanceId;
    PatternLayout layout = new PatternLayout();
    layout.setPattern("%msg");
    layout.setContext(LOGGER_CONTEXT);
    layout.start();
    appender.setLayout(layout);
    LoggingEvent event = new LoggingEvent();
    event.setTimeStamp(System.currentTimeMillis());
    event.setLoggerName("name");
    event.setLevel(Level.DEBUG);
    event.setMessage("message");
    final PutLogEventsResult result = new PutLogEventsResult();
    result.setNextSequenceToken("ewopjfewfj");
    expect(awsLogClient.putLogEvents(isA(PutLogEventsRequest.class))).andAnswer(new IAnswer<PutLogEventsResult>() {

        @Override
        public PutLogEventsResult answer() {
            PutLogEventsRequest request = (PutLogEventsRequest) getCurrentArguments()[0];
            assertEquals(LOG_GROUP, request.getLogGroupName());
            assertEquals(expectedLogStream, request.getLogStreamName());
            return result;
        }
    });
    awsLogClient.shutdown();
    // =====================================
    replay(awsLogClient);
    appender.start();
    appender.append(event);
    while (appender.getEventsWrittenCount() < 1) {
        Thread.sleep(10);
    }
    appender.stop();
    verify(awsLogClient);
}
Also used : LoggingEvent(ch.qos.logback.classic.spi.LoggingEvent) AWSLogsClient(com.amazonaws.services.logs.AWSLogsClient) PatternLayout(ch.qos.logback.classic.PatternLayout) PutLogEventsResult(com.amazonaws.services.logs.model.PutLogEventsResult) PutLogEventsRequest(com.amazonaws.services.logs.model.PutLogEventsRequest) Test(org.junit.Test)

Example 8 with AWSLogsClient

use of com.amazonaws.services.logs.AWSLogsClient in project cloudwatch-logback-appender by j256.

the class SystemEnvironConverterTest method testStuff.

@Test(timeout = 5000)
public void testStuff() throws InterruptedException {
    String envName = "SHELL";
    String envValue = System.getenv(envName);
    AWSLogsClient awsLogClient = createMock(AWSLogsClient.class);
    appender.setAwsLogsClient(awsLogClient);
    String prefix = "logstream-";
    appender.setLogStream(prefix + "%systemEnviron{" + envName + "}");
    final String expectedLogStream = prefix + envValue;
    PatternLayout layout = new PatternLayout();
    layout.setPattern("%msg");
    layout.setContext(LOGGER_CONTEXT);
    layout.start();
    appender.setLayout(layout);
    LoggingEvent event = new LoggingEvent();
    event.setTimeStamp(System.currentTimeMillis());
    event.setLoggerName("name");
    event.setLevel(Level.DEBUG);
    event.setMessage("message");
    final PutLogEventsResult result = new PutLogEventsResult();
    result.setNextSequenceToken("ewopjfewfj");
    expect(awsLogClient.putLogEvents(isA(PutLogEventsRequest.class))).andAnswer(new IAnswer<PutLogEventsResult>() {

        @Override
        public PutLogEventsResult answer() {
            PutLogEventsRequest request = (PutLogEventsRequest) getCurrentArguments()[0];
            assertEquals(LOG_GROUP, request.getLogGroupName());
            assertEquals(expectedLogStream, request.getLogStreamName());
            return result;
        }
    });
    awsLogClient.shutdown();
    // =====================================
    replay(awsLogClient);
    appender.start();
    appender.append(event);
    while (appender.getEventsWrittenCount() < 1) {
        Thread.sleep(10);
    }
    appender.stop();
    verify(awsLogClient);
}
Also used : LoggingEvent(ch.qos.logback.classic.spi.LoggingEvent) AWSLogsClient(com.amazonaws.services.logs.AWSLogsClient) PatternLayout(ch.qos.logback.classic.PatternLayout) PutLogEventsResult(com.amazonaws.services.logs.model.PutLogEventsResult) PutLogEventsRequest(com.amazonaws.services.logs.model.PutLogEventsRequest) Test(org.junit.Test)

Example 9 with AWSLogsClient

use of com.amazonaws.services.logs.AWSLogsClient in project cloudwatch-logback-appender by j256.

the class UuidConverterTest method testStuff.

@Test(timeout = 5000)
public void testStuff() throws InterruptedException {
    String uuidString = UUID.randomUUID().toString();
    UuidConverter.setUuidString(uuidString);
    AWSLogsClient awsLogClient = createMock(AWSLogsClient.class);
    appender.setAwsLogsClient(awsLogClient);
    String prefix = "logstream-";
    appender.setLogStream(prefix + "%uuid");
    final String expectedLogStream = prefix + uuidString;
    PatternLayout layout = new PatternLayout();
    layout.setPattern("%msg");
    layout.setContext(LOGGER_CONTEXT);
    layout.start();
    appender.setLayout(layout);
    LoggingEvent event = new LoggingEvent();
    event.setTimeStamp(System.currentTimeMillis());
    event.setLoggerName("name");
    event.setLevel(Level.DEBUG);
    event.setMessage("message");
    final PutLogEventsResult result = new PutLogEventsResult();
    result.setNextSequenceToken("ewopjfewfj");
    expect(awsLogClient.putLogEvents(isA(PutLogEventsRequest.class))).andAnswer(new IAnswer<PutLogEventsResult>() {

        @Override
        public PutLogEventsResult answer() {
            PutLogEventsRequest request = (PutLogEventsRequest) getCurrentArguments()[0];
            assertEquals(LOG_GROUP, request.getLogGroupName());
            assertEquals(expectedLogStream, request.getLogStreamName());
            return result;
        }
    });
    awsLogClient.shutdown();
    // =====================================
    replay(awsLogClient);
    appender.start();
    appender.append(event);
    while (appender.getEventsWrittenCount() < 1) {
        Thread.sleep(10);
    }
    appender.stop();
    verify(awsLogClient);
}
Also used : LoggingEvent(ch.qos.logback.classic.spi.LoggingEvent) AWSLogsClient(com.amazonaws.services.logs.AWSLogsClient) PatternLayout(ch.qos.logback.classic.PatternLayout) PutLogEventsResult(com.amazonaws.services.logs.model.PutLogEventsResult) PutLogEventsRequest(com.amazonaws.services.logs.model.PutLogEventsRequest) Test(org.junit.Test)

Example 10 with AWSLogsClient

use of com.amazonaws.services.logs.AWSLogsClient in project aws-codebuild-jenkins-plugin by awslabs.

the class AWSClientFactory method getCloudWatchLogsClient.

public AWSLogsClient getCloudWatchLogsClient() throws InvalidInputException {
    AWSLogsClient client = new AWSLogsClient(awsCredentialsProvider, getClientConfiguration());
    client.setEndpoint("https://logs." + region + getAwsClientSuffix(region));
    return client;
}
Also used : AWSLogsClient(com.amazonaws.services.logs.AWSLogsClient)

Aggregations

AWSLogsClient (com.amazonaws.services.logs.AWSLogsClient)16 PatternLayout (ch.qos.logback.classic.PatternLayout)13 LoggingEvent (ch.qos.logback.classic.spi.LoggingEvent)13 PutLogEventsRequest (com.amazonaws.services.logs.model.PutLogEventsRequest)13 PutLogEventsResult (com.amazonaws.services.logs.model.PutLogEventsResult)13 Test (org.junit.Test)13 BasicSessionCredentials (com.amazonaws.auth.BasicSessionCredentials)2 Regions (com.amazonaws.regions.Regions)2 AWSLogs (com.amazonaws.services.logs.AWSLogs)2 AWSSecurityTokenService (com.amazonaws.services.securitytoken.AWSSecurityTokenService)2 AssumeRoleRequest (com.amazonaws.services.securitytoken.model.AssumeRoleRequest)2 AssumeRoleResult (com.amazonaws.services.securitytoken.model.AssumeRoleResult)2