Skip to content

Commit

Permalink
Pass a Logger to Parameters (#116)
Browse files Browse the repository at this point in the history
* Add swift-log to the dependencies

* Add a logger to parameters. Create a second initializer

* Change logger from private to public
  • Loading branch information
BennyDeBock authored May 18, 2022
1 parent e229a7a commit 9e181d6
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
8 changes: 6 additions & 2 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,13 @@ let package = Package(
products: [
.library(name: "RoutingKit", targets: ["RoutingKit"]),
],
dependencies: [ ],
dependencies: [
.package(url: "https://github.com/apple/swift-log.git", from: "1.4.2")
],
targets: [
.target(name: "RoutingKit"),
.target(name: "RoutingKit", dependencies: [
.product(name: "Logging", package: "swift-log"),
]),
.testTarget(name: "RoutingKitTests", dependencies: ["RoutingKit"]),
]
)
13 changes: 13 additions & 0 deletions Sources/RoutingKit/Parameters.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Foundation
import Logging

/// Holds dynamic path components that were discovered while routing.
///
Expand All @@ -11,13 +12,25 @@ public struct Parameters {
/// Internal storage.
private var values: [String: String]
private var catchall: Catchall
public let logger: Logger

/// Creates a new `Parameters`.
///
/// Pass this into the `Router.route(path:parameters:)` method to fill with values.
public init() {
self.values = [:]
self.catchall = Catchall()
self.logger = Logger(label: "routing-kit-parameters-logger")
}

/// Creates a new `Parameters`.
/// Pass this into the `Router.route(path:parameters:)` method to fill with values.
/// - Parameters:
/// - logger: The logger to be used. If none is provided, a default one will be created.
public init(_ logger: Logger?) {
self.values = [:]
self.catchall = Catchall()
self.logger = logger ?? Logger(label: "routing-kit-parameters-logger")
}

/// Grabs the named parameter from the parameter bag.
Expand Down

0 comments on commit 9e181d6

Please sign in to comment.