Search in sources :

Example 1 with AWSLogsClient

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

the class Ec2InstanceNameConverterTest method testInstanceNameUnknown.

@Test(timeout = 10000)
public void testInstanceNameUnknown() throws InterruptedException {
    Ec2InstanceNameConverter.setInstanceName(null);
    AWSLogsClient awsLogClient = createMock(AWSLogsClient.class);
    appender.setAwsLogsClient(awsLogClient);
    String prefix = "logstream-";
    appender.setLogStream(prefix + "%instanceName");
    final String expectedLogStream = prefix + "unknown";
    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 2 with AWSLogsClient

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

the class HostNameConverterTest method testStuff.

@Test(timeout = 5000)
public void testStuff() throws InterruptedException, UnknownHostException {
    String hostAddr = InetAddress.getLocalHost().getHostName();
    AWSLogsClient awsLogClient = createMock(AWSLogsClient.class);
    appender.setAwsLogsClient(awsLogClient);
    String prefix = "logstream-";
    appender.setLogStream(prefix + "%hostName");
    final String expectedLogStream = prefix + hostAddr;
    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 3 with AWSLogsClient

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

the class SystemEnvironConverterTest method testUnknownEnvNameSpecified.

@Test(timeout = 5000)
public void testUnknownEnvNameSpecified() throws InterruptedException {
    AWSLogsClient awsLogClient = createMock(AWSLogsClient.class);
    appender.setAwsLogsClient(awsLogClient);
    String prefix = "logstream-";
    appender.setLogStream(prefix + "%systemEnviron{NOTKNOWNVARIABLE}");
    final String expectedLogStream = prefix + null;
    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 4 with AWSLogsClient

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

the class HostAddressConverterTest method testStuff.

@Test(timeout = 5000)
public void testStuff() throws InterruptedException, UnknownHostException {
    String hostAddr = InetAddress.getLocalHost().getHostAddress();
    AWSLogsClient awsLogClient = createMock(AWSLogsClient.class);
    appender.setAwsLogsClient(awsLogClient);
    String prefix = "logstream-";
    appender.setLogStream(prefix + "%hostAddress");
    final String expectedLogStream = prefix + hostAddr;
    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 5 with AWSLogsClient

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

the class SystemPropertyConverterTest method testUnknownEnvNameSpecified.

@Test(timeout = 5000)
public void testUnknownEnvNameSpecified() throws InterruptedException {
    AWSLogsClient awsLogClient = createMock(AWSLogsClient.class);
    appender.setAwsLogsClient(awsLogClient);
    String prefix = "logstream-";
    appender.setLogStream(prefix + "%systemProperty{NOTKNOWNPROPERTY}");
    final String expectedLogStream = prefix + null;
    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)

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