| 12345678910111213141516171819202122232425262728293031323334353637383940 |
- import Foundation
- public struct Logger: Sendable {
- public struct Message: ExpressibleByStringLiteral, Sendable {
- public let description: String
- public init(stringLiteral value: String) { self.description = value }
- }
- public typealias Metadata = [String: String]
- public typealias MetadataProvider = () -> Metadata
-
- public init(label: String) {}
-
- public func trace(_ message: @autoclosure () -> Message) {
- print(message().description)
- }
- public func warning(
- _ message: @autoclosure () -> Message,
- metadata: @autoclosure () -> Metadata? = nil,
- file: String = #fileID,
- function: String = #function,
- line: UInt = #line
- ) {
- print("WARNING: \(message().description)")
- }
-
- private struct SourceLocation: Hashable {
- let file: String
- let line: UInt
- }
-
- public func warnOnce(
- _ message: @autoclosure () -> Message,
- metadata: @autoclosure () -> Metadata? = nil,
- file: String = #fileID,
- function: String = #function,
- line: UInt = #line
- ) {
- warning(message(), metadata: metadata(), file: file, function: function, line: line)
- }
- }
|