Welcome to the documentation for the DataDogLogs SDK. Here you will find detailed information on how to integrate the DataDogLogs SDK into your iOS or macOS application. This documentation covers everything from installation to usage, providing you with the essential information to get started with DataDogLogs.
Table of Contents
Installation
To install the DataDogLogs SDK in your project, follow these steps:
- Open your Xcode project
- Navigate to the “File” menu and select “Swift Packages” > “Add Package Dependency”
- In the dialog that appears, enter the following repository URL:
https://github.com/datadog/datadog-logs-ios.git
- Choose the desired version of the SDK
- Click “Next” and select the target where you want to integrate the SDK
- Click “Finish”
Getting Started
To start using the DataDogLogs SDK, follow these steps:
- Import the DataDogLogs module into your source file
- Set up the logger with your DataDog API key
- Start logging events
Configuration
Prior to logging events, you need to configure the DataDogLogs SDK with your preferences:
- Set the API key using the
DDLogs.apiKey
property - Specify the log level using the
DDLogs.logLevel
property - Set additional configuration options as per your requirements
Logging
To log events using the DataDogLogs SDK, use the DDLogs.log()
method:
For example, to log a simple informational message:
DDLogs.log(.info, "This is an informational message.")
Customization
The DataDogLogs SDK provides various customization options to help you tailor the logging experience:
- Configure log formats
- Enable or disable console logging
- Add tags to your logs
- And more…
Examples
Here are a few examples to illustrate how to use the DataDogLogs SDK in various scenarios:
// Example 1: Logging an error event
DDLogs.log(.error, "An error occurred in myFunction().", tag: "error")
// Example 2: Logging a warning event with additional metadata
let metadata = ["user": "john.doe", "env": "production"]
DDLogs.log(.warning, "The system is running low on memory.", metadata: metadata)