@@ -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
3764extension 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}
0 commit comments