blob: 058be6b59e54ce4a923a40ff452477c9fb878ed0 (
plain)
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
|
//
// Logger+Errors.swift
// MullvadVPN
//
// Created by pronebird on 02/08/2020.
// Copyright © 2025 Mullvad VPN AB. All rights reserved.
//
import Foundation
import Logging
import MullvadTypes
extension Logger {
public func error(
error: some Error,
message: @autoclosure () -> String? = nil,
metadata: @autoclosure () -> Logger.Metadata? = nil,
source: @autoclosure () -> String? = nil,
file: String = #file,
function: String = #function,
line: UInt = #line
) {
var lines = [String]()
var errors = [Error]()
if let prefixMessage = message() {
lines.append(prefixMessage)
errors.append(error)
} else {
lines.append(error.logFormatError())
}
errors.append(contentsOf: error.underlyingErrorChain)
for error in errors {
lines.append("Caused by: \(error.logFormatError())")
}
log(
level: .error,
Message(stringLiteral: lines.joined(separator: "\n")),
metadata: metadata(),
source: source(),
file: file,
function: function,
line: line
)
}
}
|