Skip to content

Commit

Permalink
Minor style files
Browse files Browse the repository at this point in the history
  • Loading branch information
Alkenso committed May 29, 2024
1 parent d106f28 commit 74d7393
Show file tree
Hide file tree
Showing 4 changed files with 118 additions and 27 deletions.
4 changes: 2 additions & 2 deletions Sources/SpellbookFoundation/Common/Extensions - Codable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ extension Encodable {
do {
return try encoder.encode(self)
} catch {
(log ?? codableLogger).error("Encoding \(Self.self) to \(encoder.formatName) failed. Error: \(error)", file, function, line: line)
(log ?? codableLogger).error("Encoding \(Self.self) to \(encoder.formatName) failed. Error: \(error)", file: file, function: function, line: line)
return nil
}
}
Expand Down Expand Up @@ -92,7 +92,7 @@ extension Decodable {
do {
self = try decoder.decode(Self.self, data)
} catch {
(log ?? codableLogger).error("Decoding \(Self.self) from \(decoder.formatName) failed. Error: \(error)", file, function, line: line)
(log ?? codableLogger).error("Decoding \(Self.self) from \(decoder.formatName) failed. Error: \(error)", file: file, function: function, line: line)
return nil
}
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/SpellbookFoundation/Common/SBUnit.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ extension SBUnit {
/// - Parameters:
/// - value: Unit magnitude.
/// - from: `value` measurement units. `nil` means base units.
/// - to: `resulting` measurement units. `nil` means base units.
/// - to: `resulting` measurement units. `nil` means base units.
public static func convert(_ value: Double, _ from: Self? = nil, to: Self? = nil) -> Double {
value * (from?.rawValue ?? 1) / (to?.rawValue ?? 1)
}
Expand Down
137 changes: 114 additions & 23 deletions Sources/SpellbookFoundation/Common/SpellbookLog.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,39 +23,89 @@
import Foundation

public protocol SpellbookLog {
func custom(level: SpellbookLogLevel, message: @autoclosure () -> Any, assert: Bool, file: StaticString, function: StaticString, line: Int)
func _custom(
level: SpellbookLogLevel,
message: @autoclosure () -> Any,
assert: Bool,
file: StaticString,
function: StaticString,
line: Int
)
}

extension SpellbookLog {
public func verbose(_ message: @autoclosure () -> Any, _ file: StaticString = #file, _ function: StaticString = #function, line: Int = #line) {
custom(level: .verbose, message: message(), assert: false, file, function, line)
public func verbose(
_ message: @autoclosure () -> Any,
file: StaticString = #file,
function: StaticString = #function,
line: Int = #line
) {
custom(level: .verbose, message: message(), assert: false, file: file, function: function, line: line)
}

public func debug(_ message: @autoclosure () -> Any, _ file: StaticString = #file, _ function: StaticString = #function, line: Int = #line) {
custom(level: .debug, message: message(), assert: false, file, function, line)
public func debug(
_ message: @autoclosure () -> Any,
file: StaticString = #file,
function: StaticString = #function,
line: Int = #line
) {
custom(level: .debug, message: message(), assert: false, file: file, function: function, line: line)
}

public func info(_ message: @autoclosure () -> Any, _ file: StaticString = #file, _ function: StaticString = #function, line: Int = #line) {
custom(level: .info, message: message(), assert: false, file, function, line)
public func info(
_ message: @autoclosure () -> Any,
file: StaticString = #file,
function: StaticString = #function,
line: Int = #line
) {
custom(level: .info, message: message(), assert: false, file: file, function: function, line: line)
}

public func warning(_ message: @autoclosure () -> Any, _ file: StaticString = #file, _ function: StaticString = #function, line: Int = #line) {
custom(level: .warning, message: message(), assert: false, file, function, line)
public func warning(
_ message: @autoclosure () -> Any,
file: StaticString = #file,
function: StaticString = #function,
line: Int = #line
) {
custom(level: .warning, message: message(), assert: false, file: file, function: function, line: line)
}

public func error(_ message: @autoclosure () -> Any, assert: Bool = false, _ file: StaticString = #file, _ function: StaticString = #function, line: Int = #line) {
custom(level: .error, message: message(), assert: assert, file, function, line)
public func error(
_ message: @autoclosure () -> Any,
assert: Bool = false,
file: StaticString = #file,
function: StaticString = #function,
line: Int = #line
) {
custom(level: .error, message: message(), assert: assert, file: file, function: function, line: line)
}

public func fatal(_ message: @autoclosure () -> Any, assert: Bool = false, _ file: StaticString = #file, _ function: StaticString = #function, line: Int = #line) {
custom(level: .fatal, message: message(), assert: assert, file, function, line)
public func fatal(
_ message: @autoclosure () -> Any,
assert: Bool = false,
file: StaticString = #file,
function: StaticString = #function,
line: Int = #line
) {
custom(level: .fatal, message: message(), assert: assert, file: file, function: function, line: line)
}

public func custom(
level: SpellbookLogLevel, message: @autoclosure () -> Any, assert: Bool,
_ file: StaticString = #file, _ function: StaticString = #function, _ line: Int = #line
level: SpellbookLogLevel,
message: @autoclosure () -> Any,
assert: Bool,
file: StaticString = #file,
function: StaticString = #function,
line: Int = #line
) {
custom(level: level, message: message(), assert: assert, file: file, function: function, line: line)
_custom(
level: level,
message: message(),
assert: assert,
file: file,
function: function,
line: line
)
}
}

Expand All @@ -82,7 +132,14 @@ public struct SpellbookLogRecord {
public var function: StaticString
public var line: Int

public init(source: SpellbookLogSource, level: SpellbookLogLevel, message: Any, file: StaticString, function: StaticString, line: Int) {
public init(
source: SpellbookLogSource,
level: SpellbookLogLevel,
message: Any,
file: StaticString,
function: StaticString,
line: Int
) {
self.source = source
self.level = level
self.message = message
Expand Down Expand Up @@ -172,13 +229,33 @@ extension SpellbookLogger {
}

extension SpellbookLogger: SpellbookLog {
public func custom(level: SpellbookLogLevel, message: @autoclosure () -> Any, assert: Bool, file: StaticString, function: StaticString, line: Int) {
custom(source: source, level: level, message: message(), assert: assert, file: file, function: function, line: line)
public func _custom(
level: SpellbookLogLevel,
message: @autoclosure () -> Any,
assert: Bool,
file: StaticString,
function: StaticString,
line: Int
) {
custom(
source: source,
level: level,
message: message(),
assert: assert,
file: file,
function: function,
line: line
)
}

private func custom(
source: SpellbookLogSource, level: SpellbookLogLevel, message: @autoclosure () -> Any, assert: Bool,
file: StaticString, function: StaticString, line: Int
source: SpellbookLogSource,
level: SpellbookLogLevel,
message: @autoclosure () -> Any,
assert: Bool,
file: StaticString,
function: StaticString,
line: Int
) {
if assert && isAssertsEnabled {
assertionFailure("\(message())", file: file, line: UInt(line))
Expand All @@ -198,9 +275,23 @@ extension SpellbookLogger: SpellbookLog {
}

private struct SubsystemLogger: SpellbookLog {
let logImpl: (_ level: SpellbookLogLevel, _ message: @autoclosure () -> Any, _ assert: Bool, _ file: StaticString, _ function: StaticString, _ line: Int) -> Void
let logImpl: (
_ level: SpellbookLogLevel,
_ message: @autoclosure () -> Any,
_ assert: Bool,
_ file: StaticString,
_ function: StaticString,
_ line: Int
) -> Void

func custom(level: SpellbookLogLevel, message: @autoclosure () -> Any, assert: Bool, file: StaticString, function: StaticString, line: Int) {
func _custom(
level: SpellbookLogLevel,
message: @autoclosure () -> Any,
assert: Bool,
file: StaticString,
function: StaticString,
line: Int
) {
logImpl(level, message(), assert, file, function, line)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ extension Synchronized {
write { $0 = value }
}

public func write<S>(_ subValue: S, at keyPath: WritableKeyPath<Value, S>) {
public func write<S>(at keyPath: WritableKeyPath<Value, S>, _ subValue: S) {
write { $0[keyPath: keyPath] = subValue }
}

Expand Down

0 comments on commit 74d7393

Please sign in to comment.