feat: Beginning to refactor cli-client
This commit is contained in:
27
Sources/LoggingExtensions/LoggingExtensions.swift
Normal file
27
Sources/LoggingExtensions/LoggingExtensions.swift
Normal file
@@ -0,0 +1,27 @@
|
||||
import Constants
|
||||
import Dependencies
|
||||
import Foundation
|
||||
import ShellClient
|
||||
|
||||
public struct LoggingOptions: Equatable, Sendable {
|
||||
public let commandName: String
|
||||
public let logLevel: Logger.Level
|
||||
|
||||
public init(commandName: String, logLevel: Logger.Level) {
|
||||
self.commandName = commandName
|
||||
self.logLevel = logLevel
|
||||
}
|
||||
|
||||
@discardableResult
|
||||
public func withLogger<T>(
|
||||
operation: @Sendable @escaping () async throws -> T
|
||||
) async rethrows -> T {
|
||||
try await withDependencies {
|
||||
$0.logger = .init(label: "\(Constants.executableName)")
|
||||
$0.logger.logLevel = logLevel
|
||||
$0.logger[metadataKey: "command"] = "\(commandName.blue)"
|
||||
} operation: {
|
||||
try await operation()
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user