/
Logger.swift
85 lines (77 loc) · 2.29 KB
/
Logger.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
76
77
78
79
80
81
82
83
84
85
import Foundation
import os.log
/// Namespace for logging helpers
enum Logger {}
/// BlueprintView signposts
extension Logger {
static func logLayoutStart(view: BlueprintView) {
os_signpost(
.begin,
log: .active,
name: "Layout",
signpostID: OSSignpostID(log: .active, object: view),
"%{public}s",
view.name ?? "BlueprintView"
)
}
static func logLayoutEnd(view: BlueprintView) {
os_signpost(
.end,
log: .active,
name: "Layout",
signpostID: OSSignpostID(log: .active, object: view)
)
}
static func logViewUpdateStart(view: BlueprintView) {
os_signpost(
.begin,
log: .active,
name: "View Update",
signpostID: OSSignpostID(log: .active, object: view),
"%{public}s",
view.name ?? "BlueprintView"
)
}
static func logViewUpdateEnd(view: BlueprintView) {
os_signpost(
.end,
log: .active,
name: "View Update",
signpostID: OSSignpostID(log: .active, object: view)
)
}
static func logElementAssigned(view: BlueprintView) {
os_signpost(
.event,
log: .active,
name: "Element assigned",
signpostID: OSSignpostID(log: .active, object: view),
"Element assigned to %{public}s",
view.name ?? "BlueprintView"
)
}
}
/// Measuring signposts
extension Logger {
static func logMeasureStart(object: AnyObject, description: String, constraint: SizeConstraint) {
os_signpost(
.begin,
log: .active,
name: "Measuring",
signpostID: OSSignpostID(log: .active, object: object),
// nb: os_signpost seems to ignore precision specifiers
"%{public}s in %.1f×%.1f",
description,
constraint.width.constrainedValue ?? .infinity,
constraint.height.constrainedValue ?? .infinity
)
}
static func logMeasureEnd(object: AnyObject) {
os_signpost(
.end,
log: .active,
name: "Measuring",
signpostID: OSSignpostID(log: .active, object: object)
)
}
}