Swiftpack.co -  jagreenwood/swift-log-datadog as Swift Package
Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
jagreenwood/swift-log-datadog
Send logs to Datadog with Swift
.package(url: "https://github.com/jagreenwood/swift-log-datadog.git", from: "0.2.0")

DataDogLog 🐶

Swift Release Unit Test

This package implements a handler for swift-log which will send log messages to the Datadog's Log Management service.

Usage

Add Package 📦

Integrate the DataDogLog package as a dependency with Swift Package Manager. Add the following to Package.swift:

.package(url: "git@github.com:jagreenwood/swift-log-datadog.git", from: "0.0.1")

Add DataDogLog to your target dependencies:

.product(name: "DataDogLog", package: "swift-log-datadog")

Configure ⚙️

Configure the logger by bootstrapping a DataDogLogHandler instance.

import DataDogLog

// add handler to logging system
LoggingSystem.bootstrap {
    // initialize handler instance
    var handler = DataDogLogHandler(label: $0, key: "xxx", hostname: "hostname")
    // global metadata (optional)
    handler.metadata = ["foo":"bar"]

    return handler
}

Logging 🌲

To send logs to Datadog, initialize a Logger instance and send a message with optional additional metadata:

import DataDogLog

let logger = Logger(label: "com.swift-log.awesome-app")
logger.error("unfortunate error", metadata: ["request-id": "abc-123"], source: "module-name")

This call will send the following payload to Datadog:

{
    "message": "2020-05-27T06:37:17-0400 ERROR: unfortunate error",
    "hostname": "hostname",
    "ddsource": "module-name",
    "ddtags": "callsite:testLog():39,foo:bar,request-id:abc-123",
    "status": "error"
    "service": "com.swift-log.awesome-app"
}

Select Region 🌎

The Datadog API uses a different URL in the EU region compared to the US. If your account was created using Datadog EU, you need to set the region option when initializing DataDogLogHandler:

DataDogLogHandler(label: $0, key: "xxx", hostname: "hostname", region: .EU)

GitHub

link
Stars: 8
Last commit: 13 weeks ago

Ad: Job Offers

iOS Software Engineer @ Perry Street Software
Perry Street Software is Jack’d and SCRUFF. We are two of the world’s largest gay, bi, trans and queer social dating apps on iOS and Android. Our brands reach more than 20 million members worldwide so members can connect, meet and express themselves on a platform that prioritizes privacy and security. We invest heavily into SwiftUI and using Swift Packages to modularize the codebase.

Dependencies

Release Notes

0.2.0
13 weeks ago

Adds service to log instance and now properly handles passing in source when a log is sent.

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API