-
Notifications
You must be signed in to change notification settings - Fork 135
/
Copy pathInternalLoggers.swift
75 lines (69 loc) · 2.93 KB
/
InternalLoggers.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/*
* Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.
* This product includes software developed at Datadog (https://www.datadoghq.com/).
* Copyright 2019-2020 Datadog, Inc.
*/
import Foundation
/// Necessary configuration to instantiate `developerLogger` and `userLogger`.
internal struct InternalLoggerConfiguration {
let sdkVersion: String
let applicationVersion: String
let environment: String
let userInfoProvider: UserInfoProvider
let networkConnectionInfoProvider: NetworkConnectionInfoProviderType
let carrierInfoProvider: CarrierInfoProviderType
}
/// Global SDK `Logger` using console output.
/// This logger is meant for debugging purposes when using SDK, hence **it should print useful information to SDK user**.
/// It is only used when `Datadog.verbosityLevel` value is set.
/// Every information posted to user should be properly classified (most commonly `.debug()` or `.error()`) according to
/// its context: does the message pop up due to user error or user's app environment error? or is it SDK error?
///
/// This no-op `Logger` gets replaced with working instance as soon as the SDK is initialized.
internal var userLogger = createNoOpSDKUserLogger()
internal func createNoOpSDKUserLogger() -> Logger {
return Logger(
logBuilder: nil,
logOutput: nil,
dateProvider: SystemDateProvider(),
identifier: "no-op",
rumContextIntegration: nil,
activeSpanIntegration: nil
)
}
internal func createSDKUserLogger(
configuration: InternalLoggerConfiguration,
consolePrintFunction: @escaping (String) -> Void = { consolePrint($0) },
dateProvider: DateProvider = SystemDateProvider(),
timeZone: TimeZone = .current
) -> Logger {
let logBuilder = LogEventBuilder(
sdkVersion: configuration.sdkVersion,
applicationVersion: configuration.applicationVersion,
environment: configuration.environment,
serviceName: "sdk-user",
loggerName: "sdk-user",
userInfoProvider: configuration.userInfoProvider,
networkConnectionInfoProvider: configuration.networkConnectionInfoProvider,
carrierInfoProvider: configuration.carrierInfoProvider,
dateCorrector: nil,
logEventMapper: nil
)
let consoleOutput = LogConsoleOutput(
format: .shortWith(prefix: "[DATADOG SDK] 🐶 → "),
timeZone: timeZone,
printingFunction: consolePrintFunction
)
return Logger(
logBuilder: logBuilder,
logOutput: ConditionalLogOutput(conditionedOutput: consoleOutput) { log in
let logSeverity = LogLevel(from: log.status)?.rawValue ?? .max
let threshold = Datadog.verbosityLevel?.rawValue ?? .max
return logSeverity >= threshold
},
dateProvider: dateProvider,
identifier: "sdk-user",
rumContextIntegration: nil,
activeSpanIntegration: nil
)
}