Files
swift-composable-architectu…/Sources/ComposableArchitecture/Internal/Logger.swift
Brandon Williams 931a71b78e Revamp integration tests (#2503)
* More integration tests.

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* comment out all but one test

* wip

* try ios 17

* see if this works in ios 16

* wip

* wip

* wip

* bring back tests

* wip

* wip

* wip

* fixes

* fixes

* re-enable tests

* wip

* Update Sources/ComposableArchitecture/Internal/Logger.swift

* wip

---------

Co-authored-by: Stephen Celis <stephen@stephencelis.com>
2023-10-09 15:06:04 -04:00

37 lines
1.0 KiB
Swift

import OSLog
@_spi(Logging)
public final class Logger {
public static let shared = Logger()
public var isEnabled = false
@Published public var logs: [String] = []
#if DEBUG
@available(iOS 14, macOS 11, tvOS 14, watchOS 7, *)
var logger: os.Logger {
os.Logger(subsystem: "composable-architecture", category: "store-events")
}
public func log(level: OSLogType = .default, _ string: @autoclosure () -> String) {
guard self.isEnabled else { return }
let string = string()
if ProcessInfo.processInfo.environment["XCODE_RUNNING_FOR_PREVIEWS"] == "1" {
print("\(string)")
} else {
if #available(iOS 14, macOS 11, tvOS 14, watchOS 7, *) {
self.logger.log(level: level, "\(string)")
}
}
self.logs.append(string)
}
public func clear() {
self.logs = []
}
#else
@inlinable @inline(__always)
public func log(level: OSLogType = .default, _ string: @autoclosure () -> String) {
}
@inlinable @inline(__always)
public func clear() {
}
#endif
}