aws_cloudwatch 0.0.3
aws_cloudwatch: ^0.0.3 copied to clipboard

Flutter Android iOS Linux macOS Windows

An AWS CloudWatch wrapper package for easy Flutter cloud logging. Currently only logging is supported.

aws_cloudwatch #

A package that sends logs to AWS CloudWatch.

Currently only logging is supported

This package is still under development

The repository can be found here

If you have feedback or have a use case that isn't covered feel free to contact me.

Getting Started #

To get start add aws_cloudwatch: ^[CURRENT_VERION], to your pubspec.yaml

Then import import 'package:aws_request/aws_cloudwatch.dart';

Create a CloudWatch instance by calling

CloudWatch cloudWatch = new CloudWatch(AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, Region, ServiceInstance);

Finally, send a log by calling cloudWatch.log('STRING TO LOG');

Examples #

Example 1 #

Here's an example of using aws_cloudwatch to send a CloudWatch PutLogEvent request:

import 'package:aws_cloudwatch/aws_cloudwatch.dart';

// AWS Variables
const String AWS_ACCESS_KEY_ID = 'ExampleKey';
const String AWS_SECRET_ACCESS_KEY = 'ExampleSecret';
const String Region = 'us-west-2';
const String ServiceInstance = 'Logs_XXXXXXXX';

// Logging Variables
const String LogGroup = 'LogGroupExample';
String logStreamName = 'LogStreamExample';
CloudWatch cloudWatch = new CloudWatch(AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, Region, ServiceInstance);

void log(String logString){
  cloudWatch.log(logString);
}

Example 2 #

Here is an example of how to capture all errors in flutter and send them to CloudWatch. First create this file and name it errorLog.dart

import 'package:aws_request/aws_cloudwatch.dart';

// AWS Variables
const String AWS_ACCESS_KEY_ID = 'ExampleKey';
const String AWS_SECRET_ACCESS_KEY = 'ExampleSecret';
const String Region = 'us-west-2';
const String ServiceInstance = 'Logs_XXXXXXXX';

// Logging Variables
const String LogGroup = 'LogGroupExample';
String logStreamName = 'LogStreamExample';
CloudWatch cloudWatch = new CloudWatch(AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, Region, ServiceInstance);

void logFlutterSystemError(dynamic logString, dynamic stackTrace) async {
  cloudWatch.log('Auto Captured Error: ${logString.toString()}\n\n'
      'Auto Captured Stack Trace:\n${stackTrace.toString()}');
}

Then modify your main.dart to look like the following

import 'dart:async';
import 'app.dart';

import 'errorLog.dart';

void main() {

  runZonedGuarded<Future<void>>(() async {
    Function originalOnError = FlutterError.onError;
    FlutterError.onError = (FlutterErrorDetails errorDetails) async {
      Zone.current
          .handleUncaughtError(errorDetails.exception, errorDetails.stack);
      originalOnError(errorDetails);
    };
    runApp(MyApp());
  }, (error, stackTrace) async {
    logFlutterSystemError(error, stackTrace);
    print(error.toString());
    throw error;
  });
}
4
likes
100
pub points
29%
popularity

An AWS CloudWatch wrapper package for easy Flutter cloud logging. Currently only logging is supported.

Repository (GitHub)
View/report issues

Documentation

API reference

Uploader

zsmerritt@gmail.com

License

Apache 2.0 (LICENSE)

Dependencies

aws_request, flutter

More

Packages that depend on aws_cloudwatch