Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Send logs to Datadog with Swift

License

NotificationsYou must be signed in to change notification settings

jagreenwood/swift-log-datadog

Repository files navigation

This package implements a handler forswift-log which will send log messages to theDatadog's Log Management service.

Usage

Add Package 📦

Integrate theDataDogLog package as a dependency with Swift Package Manager. Add the following toPackage.swift:

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

AddDataDogLog to your target dependencies:

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

Configure ⚙️

Configure the logger by bootstrapping aDataDogLogHandler instance.

import DataDogLog// add handler to logging systemLoggingSystem.bootstrap{    // initialize handler instancevarhandler=DataDogLogHandler(label: $0, key:"xxx", hostname:"hostname")    // global metadata (optional)    handler.metadata=["foo":"bar"]return handler}

Logging 🌲

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

import DataDogLogletlogger=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 defaultUS region, you need to set theregion option when initializingDataDogLogHandler:

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

About

Send logs to Datadog with Swift

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors4

  •  
  •  
  •  
  •  

Languages


[8]ページ先頭

©2009-2025 Movatter.jp