feat: Moves logging setup and generate-json for the create command to cli-client module.
This commit is contained in:
28
Sources/CliClient/LoggingExtensions.swift
Normal file
28
Sources/CliClient/LoggingExtensions.swift
Normal file
@@ -0,0 +1,28 @@
|
||||
import Dependencies
|
||||
import Logging
|
||||
import ShellClient
|
||||
|
||||
public extension CliClient {
|
||||
|
||||
@discardableResult
|
||||
func withLogger<T>(
|
||||
_ options: LoggingOptions,
|
||||
operation: @Sendable @escaping () async throws -> T
|
||||
) async rethrows -> T {
|
||||
try await Self.withLogger(options, operation: operation)
|
||||
}
|
||||
|
||||
@discardableResult
|
||||
static func withLogger<T>(
|
||||
_ options: LoggingOptions,
|
||||
operation: @Sendable @escaping () async throws -> T
|
||||
) async rethrows -> T {
|
||||
try await withDependencies {
|
||||
$0.logger = .init(label: "\(Constants.executableName)")
|
||||
$0.logger.logLevel = options.logLevel
|
||||
$0.logger[metadataKey: "command"] = "\(options.commandName.blue)"
|
||||
} operation: {
|
||||
try await operation()
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user