Skip to content

Commit 25bebf8

Browse files
OdNairygithub-actions[bot]
authored andcommitted
Add logging category manipulation API (#4940)
Add new APIs to get/set global logging level and level per category. cc @mapbox/maps-ios GitOrigin-RevId: 895ef7afb736fcfa160d7644dfb108250b4bfa3a
1 parent cbc8e2e commit 25bebf8

File tree

2 files changed

+38
-4
lines changed

2 files changed

+38
-4
lines changed

Sources/MapboxMaps/Foundation/Logger.swift

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,33 @@ import Foundation
3232
@_spi(Logging) public static func error(_ message: String, category: Category? = nil) {
3333
Logger.error(forMessage: message, category: logCategory(category?.rawValue))
3434
}
35+
36+
// MARK: - Logging levels
37+
/// Get the current logging level for a specific category or globally.
38+
/// - Parameter category: The logging category to check. If `nil`, returns the global logging level.
39+
/// - Returns: The current logging level. Returns `.debug` if no level is configured.
40+
@_spi(Logging) public static func loggingLevel(category: Category? = nil) -> LoggingLevel {
41+
let level: NSNumber?
42+
if let category {
43+
level = LogConfiguration.getLoggingLevel(forCategory: logCategory(category.rawValue))
44+
} else {
45+
level = LogConfiguration.getLoggingLevel()
46+
}
47+
return (level?.intValue).flatMap(LoggingLevel.init) ?? .debug
48+
}
49+
50+
/// Set the logging level for a specific category or globally.
51+
/// - Parameters:
52+
/// - level: The logging level to set.
53+
/// - category: The logging category to configure. If `nil`, sets the global logging level.
54+
@_spi(Logging) public static func setLogging(level: LoggingLevel, category: Category? = nil) {
55+
let nsLevel = NSNumber(value: level.rawValue)
56+
if let category {
57+
LogConfiguration.setLoggingLevelForCategory(category.fullCategoryName, upTo: nsLevel)
58+
} else {
59+
LogConfiguration.setLoggingLevelForUpTo(nsLevel)
60+
}
61+
}
3562
}
3663

3764
extension Log {
@@ -59,6 +86,17 @@ extension Log {
5986
}
6087

6188
static let `default` = Category("")
89+
90+
internal var fullCategoryName: String {
91+
Log.logCategory(rawValue)
92+
}
6293
}
94+
}
95+
96+
@_spi(Logging) extension Log.Category {
97+
/// Category for application lifecycle events.
98+
public static let applicationLifecycle = Log.Category("ApplicationLifecycle")
6399

100+
/// Category for size tracking layer events and operations.
101+
public static let sizeTrackingLayer = Log.Category("SizeTrackingLayer")
64102
}

Sources/MapboxMaps/Foundation/SizeTrackingLayer.swift

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,3 @@ extension CAAnimation {
9393
}
9494
}
9595
}
96-
97-
extension Log.Category {
98-
static let sizeTrackingLayer = Log.Category("SizeTrackingLayer")
99-
}

0 commit comments

Comments
 (0)