Files
dotfiles/dots/Sources/LoggingDependency/Live.swift
2023-03-05 14:37:02 -05:00

33 lines
674 B
Swift

import Dependencies
import Foundation
@_exported import Logging
import LoggingFormatAndPipe
extension Logger: DependencyKey {
fileprivate static func factory(label: String) -> Self {
Logger(label: "dots") { _ in
LoggingFormatAndPipe.Handler(
formatter: BasicFormatter([.message]),
pipe: LoggerTextOutputStreamPipe.standardOutput
)
}
}
public static var liveValue: Logger {
factory(label: "dots")
}
public static var testValue: Logger {
factory(label: "dots-test")
}
}
extension DependencyValues {
public var logger: Logger {
get { self[Logger.self] }
set { self[Logger.self] = newValue }
}
}