I have a iOS App and want to log some things for example when an error happened. Is there a possibility to send those Logs to Cloudwatch?
Thank you.
You can use AWSLogs
SDK to send logs from an iOS app to CloudWatch. Add the following line to your Podfile under the app target section to consume the SDK via cocoapods:
pod 'AWSLogs', '~> 2.7'
Documentation: https://github.com/aws-amplify/aws-sdk-ios/tree/master/AWSLogs Source: https://github.com/aws-amplify/aws-sdk-ios/tree/master/AWSLogs
To instantiate the client, do the following:
let logs = AWSLogs.default()
Once you have the logs client created, you need to create a log group and log stream. You can do this via Amazon CloudWatch Logs console or through the SDK. If you want to create using the SDK, do the following:
Create a log group:
https://aws-amplify.github.io/aws-sdk-ios/docs/reference/Classes/AWSLogs.html#//api/name/createLogGroup:
Create a log stream:
https://aws-amplify.github.io/aws-sdk-ios/docs/reference/Classes/AWSLogs.html#//api/name/createLogStream:
Now, you can start sending the logs to the log stream. You need a sequence token which you can obtain by doing a DescribeLogStreams
call. See https://aws-amplify.github.io/aws-sdk-ios/docs/reference/Classes/AWSLogs.html#//api/name/DescribeLogStreams:
After this you can call putLogEvents
in order to send the logs:
https://aws-amplify.github.io/aws-sdk-ios/docs/reference/Classes/AWSLogs.html#//api/name/putLogEvents:
You can take a look at our tests for an example: https://github.com/aws-amplify/aws-sdk-ios/blob/master/AWSLogsUnitTests/AWSGeneralLogsTests.m#L1247
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With