use of com.amazonaws.services.logs.AWSLogs in project aws-doc-sdk-examples by awsdocs.
the class PutSubscriptionFilter method main.
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);
}
use of com.amazonaws.services.logs.AWSLogs in project ranger by apache.
the class AmazonCloudWatchAuditDestination method log.
@Override
public synchronized boolean log(Collection<AuditEventBase> collection) {
boolean ret = false;
AWSLogs client = getClient();
PutLogEventsRequest req = new PutLogEventsRequest().withLogEvents(toInputLogEvent(collection)).withLogGroupName(logGroupName).withLogStreamName(logStreamName);
if (StringUtils.isNotBlank(sequenceToken)) {
req.setSequenceToken(sequenceToken);
}
try {
sequenceToken = pushLogEvents(req, false, client);
addSuccessCount(collection.size());
ret = true;
} catch (Throwable e) {
addFailedCount(collection.size());
LOG.error("Failed to send audit events", e);
}
return ret;
}
use of com.amazonaws.services.logs.AWSLogs in project ranger by apache.
the class AmazonCloudWatchAuditDestination method createLogStream.
private void createLogStream() {
AWSLogs client = getClient();
CreateLogStreamRequest req = new CreateLogStreamRequest().withLogGroupName(logGroupName).withLogStreamName(logStreamName);
LOG.info(String.format("Creating Log Stream `%s` in Log Group `%s`", logStreamName, logGroupName));
client.createLogStream(req);
}
use of com.amazonaws.services.logs.AWSLogs in project minijax by minijax.
the class CloudWatchAppenderTest method testAlreadyExists.
@Test
public void testAlreadyExists() {
final Context mockContext = mock(Context.class);
final PutLogEventsResult mockResult = mock(PutLogEventsResult.class);
when(mockResult.getNextSequenceToken()).thenReturn("2");
final AWSLogs mockAwsLogs = mock(AWSLogs.class);
when(mockAwsLogs.createLogGroup(any())).thenThrow(ResourceAlreadyExistsException.class);
when(mockAwsLogs.createLogStream(any())).thenThrow(ResourceAlreadyExistsException.class);
when(mockAwsLogs.putLogEvents(any())).thenReturn(mockResult);
final CloudWatchAppender appender = new CloudWatchAppender();
appender.setContext(mockContext);
appender.setAwsLogs(mockAwsLogs);
appender.start();
appender.doAppend(new LoggingEvent());
appender.stop();
}
use of com.amazonaws.services.logs.AWSLogs in project cloudwatch-logback-appender by j256.
the class CloudWatchAppenderTest method testBigMessageDrop.
@Test(timeout = 10000)
public void testBigMessageDrop() throws InterruptedException {
CloudWatchAppender appender = new CloudWatchAppender();
AWSLogs awsLogClient = createMock(AWSLogsClient.class);
appender.setAwsLogsClient(awsLogClient);
appender.setMaxBatchSize(1);
appender.setRegion("region");
final String logGroup = "pfqoejpfqe";
appender.setLogGroup(logGroup);
final String logStream = "pffqjfqjpoqoejpfqe";
appender.setLogStream(logStream);
appender.setContext(LOGGER_CONTEXT);
PatternLayout layout = new PatternLayout();
layout.setContext(LOGGER_CONTEXT);
layout.setPattern("[%thread] %level %logger{20} - %msg%n%xThrowable");
layout.start();
appender.setLayout(layout);
EmergencyAppender emergency = new EmergencyAppender();
appender.addAppender(emergency);
final String loggerName = "name";
final Level level = Level.DEBUG;
String message = "ytjkuyliuyiuk";
LoggingEvent event = createEvent(loggerName, level, message, System.currentTimeMillis());
int maxSize = 10;
appender.setMaxEventMessageSize(maxSize);
appender.setTruncateEventMessages(false);
final PutLogEventsResult result = new PutLogEventsResult();
String sequence = "ewopjfewfj";
result.setNextSequenceToken(sequence);
awsLogClient.shutdown();
// =====================================
replay(awsLogClient);
appender.start();
// for coverage
appender.start();
appender.append(event);
while (emergency.event == null) {
Thread.sleep(100);
}
appender.stop();
verify(awsLogClient);
assertSame(event, emergency.event);
assertEquals(0, appender.getEventsWrittenCount());
}
Aggregations