Swiftpack.co - jagreenwood/swift-log-datadog as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by jagreenwood.
jagreenwood/swift-log-datadog 1.0.0
Send logs to Datadog with Swift
⭐️ 19
🕓 3 weeks ago
iOS macOS watchOS tvOS
.package(url: "https://github.com/jagreenwood/swift-log-datadog.git", from: "1.0.0")

DataDogLog 🐶

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


Add Package 📦

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

.package(url: "[email protected]:jagreenwood/swift-log-datadog.git", from: "1.0.0")

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 runs on multiple regions (e.g. US, EU, US3, US5, US1FED), with different API endpoints. If your account was not created in the default US region, you need to set the region option when initializing DataDogLogHandler:

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


Stars: 19
Last commit: 4 weeks ago
Advertisement: IndiePitcher.com - Cold Email Software for Startups

Release Notes

4 weeks ago

What's Changed

Full Changelog: https://github.com/jagreenwood/swift-log-datadog/compare/0.3.0...1.0.0

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