Skip to content

Commit 1efe19e

Browse files
committed
Refactor Logging
1 parent 2625eeb commit 1efe19e

File tree

2 files changed

+19
-20
lines changed

2 files changed

+19
-20
lines changed

Sources/GateEngine/ECS/Base/Entity.swift

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,7 @@ extension Entity {
8787
public subscript<T: Component>(_ type: T.Type) -> T {
8888
get {
8989
let componentID = type.componentID.value
90-
#if DEBUG
9190
Log.assert(hasComponent(at: componentID), "Component \"\(type)\" is not a member of this entity.")
92-
#endif
9391
return self.getComponent(at: componentID) as! T
9492
}
9593
set {
@@ -101,9 +99,7 @@ extension Entity {
10199
public subscript<T: ResourceConstrainedComponent>(_ type: T.Type) -> T {
102100
get {
103101
let componentID = type.componentID.value
104-
#if DEBUG
105102
Log.assert(hasComponent(at: componentID), "Component \"\(type)\" is not a member of this entity.")
106-
#endif
107103
return self.getComponent(at: componentID) as! T
108104
}
109105
set {

Sources/GateEngine/GateEngine.swift

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -139,12 +139,19 @@ extension GateEngineError: ExpressibleByStringLiteral {
139139
}
140140

141141
extension CommandLine {
142-
#if os(macOS) || ((os(iOS) || os(tvOS) || os(watchOS) || os(visionOS)) && targetEnvironment(simulator))
143142
@usableFromInline
144-
static let isDebuggingWithXcode: Bool = ProcessInfo.processInfo.environment.keys.first(where: {
145-
$0.lowercased().contains("xcode")
146-
}) != nil
147-
#endif
143+
static let isDebuggingWithXcode: Bool = {
144+
#if canImport(Darwin) || os(macOS) || os(iOS) || os(tvOS) || os(watchOS) || os(visionOS)
145+
let environment = ProcessInfo.processInfo.environment
146+
if environment.keys.contains(where: {$0.lowercased().contains("xcode.app")}) {
147+
return true
148+
}
149+
if environment.values.contains(where: {$0.lowercased().contains("xcode.app")}) {
150+
return true
151+
}
152+
#endif
153+
return false
154+
}()
148155
}
149156

150157
@usableFromInline
@@ -171,12 +178,10 @@ internal enum Log {
171178
}
172179

173180
@inlinable
174-
static var supportsColor: Bool {
175-
#if os(macOS) || ((os(iOS) || os(tvOS)) && targetEnvironment(simulator))
181+
static var supportsANSIColor: Bool {
176182
if CommandLine.isDebuggingWithXcode {
177183
return false
178184
}
179-
#endif
180185
#if os(WASI) || os(Windows)
181186
return false
182187
#else
@@ -243,7 +248,7 @@ internal enum Log {
243248
@usableFromInline
244249
static func warn(_ items: Any..., separator: String = " ", terminator: String = "\n") {
245250
let resolvedMessage: String
246-
if supportsColor {
251+
if supportsANSIColor {
247252
resolvedMessage = _message(
248253
prefix: "[GateEngine] \(ANSIColors.magenta)warning\(ANSIColors.default):",
249254
items,
@@ -276,7 +281,7 @@ internal enum Log {
276281
@usableFromInline
277282
static func error(_ items: Any..., separator: String = " ", terminator: String = "\n") {
278283
let resolvedMessage: String
279-
if supportsColor {
284+
if supportsANSIColor {
280285
resolvedMessage = self._message(
281286
prefix: "[GateEngine] \(ANSIColors.red)error\(ANSIColors.default):",
282287
items,
@@ -310,7 +315,7 @@ internal enum Log {
310315
}
311316
}
312317

313-
@_transparent // Must be transparent to inline and function similar to a Swift.assert
318+
@_transparent // Must be transparent to function similar to a Swift.assert
314319
@usableFromInline
315320
static func assert(
316321
_ condition: @autoclosure () -> Bool,
@@ -323,7 +328,7 @@ internal enum Log {
323328
guard condition == false else { return }
324329

325330
let resolvedMessage: String
326-
if supportsColor {
331+
if supportsANSIColor {
327332
resolvedMessage = self._message(
328333
prefix: "[GateEngine] \(ANSIColors.red)error\(ANSIColors.default):",
329334
message(),
@@ -350,11 +355,9 @@ internal enum Log {
350355
}
351356

352357
@usableFromInline
353-
static func fatalError(_ message: String, file: StaticString = #file, line: UInt = #line)
354-
-> Never
355-
{
358+
static func fatalError(_ message: String, file: StaticString = #file, line: UInt = #line) -> Never {
356359
let resolvedMessage: String
357-
if supportsColor {
360+
if supportsANSIColor {
358361
resolvedMessage = self._message(
359362
prefix: "[GateEngine] \(ANSIColors.red)error\(ANSIColors.default):",
360363
message,

0 commit comments

Comments
 (0)