Skip to content

Commit 5d2324b

Browse files
authored
Remove Logging (#3)
1 parent e288bcc commit 5d2324b

File tree

11 files changed

+117
-46
lines changed

11 files changed

+117
-46
lines changed

Package.resolved

Lines changed: 6 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Package.swift

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,18 +41,16 @@ let package = Package(
4141
.library(name: "SublimationBonjour", targets: ["SublimationBonjour"])
4242
],
4343
dependencies: [
44-
.package(url: "https://github.com/brightdigit/Sublimation", from: "2.0.0-alpha.5"),
45-
.package(url: "https://github.com/apple/swift-protobuf.git", from: "1.26.0"),
46-
.package(url: "https://github.com/apple/swift-log.git", from: "1.0.0")
44+
.package(url: "https://github.com/brightdigit/Sublimation.git", from: "2.0.1"),
45+
.package(url: "https://github.com/apple/swift-protobuf.git", from: "1.26.0")
4746
],
4847
targets: [
4948
.target(
5049
name: "SublimationBonjour",
5150
dependencies: [
5251
.product(name: "Sublimation", package: "Sublimation"),
5352
.product(name: "SublimationCore", package: "Sublimation"),
54-
.product(name: "SwiftProtobuf", package: "swift-protobuf"),
55-
.product(name: "Logging", package: "swift-log")
53+
.product(name: "SwiftProtobuf", package: "swift-protobuf")
5654
],
5755
swiftSettings: swiftSettings
5856
),

Sources/SublimationBonjour/Client/BonjourClient.swift

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@
2929

3030
#if canImport(Network)
3131
public import Foundation
32-
33-
import Network
32+
internal import Network
3433

3534
#if canImport(os)
3635
public import os
@@ -46,9 +45,10 @@
4645
/// let hostURL = await depositor.first()
4746
/// ```
4847
public actor BonjourClient {
48+
4949
private let browser: NWBrowser
5050
private let streams = StreamManager<UUID, URL>()
51-
private let logger: Logger?
51+
private let logger: LoggerType?
5252
private let defaultURLConfiguration: URLDefaultConfiguration
5353

5454
/// AsyncStream of `URL` from the network.
@@ -76,7 +76,10 @@
7676
/// - Parameters:
7777
/// - logger: Logger
7878
/// - defaultURLConfiguration: default ``URL`` configuration for missing properties.
79-
public init(logger: Logger? = nil, defaultURLConfiguration: URLDefaultConfiguration = .init()) {
79+
public init(
80+
logger: LoggerType? = nil,
81+
defaultURLConfiguration: URLDefaultConfiguration = .init()
82+
) {
8083
assert(logger != nil)
8184
let descriptor: NWBrowser.Descriptor
8285
descriptor = .bonjourWithTXTRecord(type: "_sublimation._tcp", domain: nil)
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
//
2+
// LoggerType.swift
3+
// SublimationBonjour
4+
//
5+
// Created by Leo Dion.
6+
// Copyright © 2024 BrightDigit.
7+
//
8+
// Permission is hereby granted, free of charge, to any person
9+
// obtaining a copy of this software and associated documentation
10+
// files (the “Software”), to deal in the Software without
11+
// restriction, including without limitation the rights to use,
12+
// copy, modify, merge, publish, distribute, sublicense, and/or
13+
// sell copies of the Software, and to permit persons to whom the
14+
// Software is furnished to do so, subject to the following
15+
// conditions:
16+
//
17+
// The above copyright notice and this permission notice shall be
18+
// included in all copies or substantial portions of the Software.
19+
//
20+
// THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND,
21+
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
22+
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23+
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
24+
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
25+
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
26+
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
27+
// OTHER DEALINGS IN THE SOFTWARE.
28+
//
29+
30+
#if canImport(os)
31+
public import os
32+
#elseif canImport(Logging)
33+
public import Logging
34+
#endif
35+
36+
#if canImport(os) || canImport(Logging)
37+
public typealias LoggerType = Logger
38+
#else
39+
public typealias LoggerType = any NilLoggerType
40+
public protocol NilLoggerType { func debug(_ message: String) }
41+
#endif

Sources/SublimationBonjour/Client/StreamManager.swift

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,6 @@
2929

3030
internal import Foundation
3131

32-
#if canImport(os)
33-
internal import os
34-
#elseif canImport(Logging)
35-
internal import Logging
36-
#endif
37-
3832
internal actor StreamManager<Key: Hashable & Sendable, Value: Sendable> {
3933
private var streamContinuations: [Key: AsyncStream<Value>.Continuation] = [:]
4034

@@ -44,7 +38,7 @@ internal actor StreamManager<Key: Hashable & Sendable, Value: Sendable> {
4438

4539
internal init(newID: @escaping @Sendable () -> Key) { self.newID = newID }
4640

47-
internal func yield(_ urls: [Value], logger: Logger?) {
41+
internal func yield(_ urls: [Value], logger: LoggerType?) {
4842
if streamContinuations.isEmpty { logger?.debug("Missing Continuations.") }
4943
for streamContinuation in streamContinuations {
5044
for url in urls { streamContinuation.value.yield(url) }

Sources/SublimationBonjour/Extensions/Dictionary.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
// OTHER DEALINGS IN THE SOFTWARE.
2828
//
2929

30-
import Foundation
30+
internal import Foundation
3131

3232
extension Dictionary where Key == String, Value == String {
3333
internal init(
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
//
2+
// NWConnection.swift
3+
// SublimationBonjour
4+
//
5+
// Created by Leo Dion.
6+
// Copyright © 2024 BrightDigit.
7+
//
8+
// Permission is hereby granted, free of charge, to any person
9+
// obtaining a copy of this software and associated documentation
10+
// files (the “Software”), to deal in the Software without
11+
// restriction, including without limitation the rights to use,
12+
// copy, modify, merge, publish, distribute, sublicense, and/or
13+
// sell copies of the Software, and to permit persons to whom the
14+
// Software is furnished to do so, subject to the following
15+
// conditions:
16+
//
17+
// The above copyright notice and this permission notice shall be
18+
// included in all copies or substantial portions of the Software.
19+
//
20+
// THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND,
21+
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
22+
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23+
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
24+
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
25+
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
26+
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
27+
// OTHER DEALINGS IN THE SOFTWARE.
28+
//
29+
30+
#if canImport(Network)
31+
import Foundation
32+
public import Network
33+
34+
extension NWConnection.State: @retroactive CustomDebugStringConvertible {
35+
@_documentation(visibility: internal) public var debugDescription: String {
36+
switch self { case .setup: return "setup" case .waiting(let error):
37+
return "waiting: \(error.debugDescription)"
38+
case .preparing: return "preparing"
39+
case .ready: return "ready"
40+
case .failed(let error): return "failed: \(error.debugDescription)"
41+
case .cancelled: return "cancelled"
42+
@unknown default: return "unknown state"
43+
}
44+
}
45+
}
46+
#endif

Sources/SublimationBonjour/Extensions/String.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
// OTHER DEALINGS IN THE SOFTWARE.
2828
//
2929

30-
import Foundation
30+
internal import Foundation
3131

3232
extension String {
3333
internal func isLocalhost() -> Bool {

Sources/SublimationBonjour/Extensions/URL.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
// OTHER DEALINGS IN THE SOFTWARE.
2828
//
2929

30-
import Foundation
30+
internal import Foundation
3131

3232
extension URL {
3333
internal init?(scheme: String, host: String, port: Int) {

Sources/SublimationBonjour/Server/BonjourSublimatory.swift

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,13 @@
2727
// OTHER DEALINGS IN THE SOFTWARE.
2828
//
2929

30-
#if canImport(Network)
30+
#if canImport(Network) && canImport(Logging)
3131

3232
internal import Foundation
3333

3434
public import Network
3535

3636
public import SublimationCore
37-
3837
public import Logging
3938

4039
/// Sublimatory for using Bonjour auto-discovery.
@@ -165,26 +164,25 @@
165164
let txtRecord = NWTXTRecord(dictionary)
166165
assert(listener.service == nil)
167166
listener.service = .init(name: name, type: type, txtRecord: txtRecord)
168-
167+
let logger = self.logger
169168
listener.newConnectionHandler = { connection in
170169
connection.stateUpdateHandler = { state in
171170
switch state { case .waiting(let error):
172171

173-
self.logger.warning("Connection Waiting error: \(error)")
172+
logger.debug("Connection Waiting error: \(error.localizedDescription)")
174173

175174
case .ready:
176-
self.logger.debug("Connection Ready")
177-
self.logger.debug("Sending data \(data.count) bytes")
175+
logger.debug("Connection Ready")
176+
logger.debug("Sending data \(data.count) bytes")
178177
connection.send(
179178
content: data,
180179
completion: .contentProcessed { error in
181-
if let error { self.logger.warning("Connection Send error: \(error)") }
180+
if let error { self.logger.error("Connection Send error: \(error)") }
182181
connection.cancel()
183182
}
184183
)
185-
case .failed(let error): self.logger.error("Connection Failure: \(error)")
186-
187-
default: self.logger.debug("Connection state updated: \(state)")
184+
case .failed(let error): logger.debug("Connection Failure: \(error)")
185+
default: logger.debug("Connection state updated: \(state.debugDescription)")
188186
}
189187
}
190188
connection.start(queue: connectionQueue)
@@ -202,7 +200,7 @@
202200
self.logger.error("Listener Failure: \(error)")
203201
continuation.resume(throwing: error)
204202
case .cancelled: continuation.resume()
205-
default: self.logger.debug("Listener state updated: \(state)")
203+
default: self.logger.debug("Listener state updated: \(state.debugDescription)")
206204
}
207205
}
208206
}

0 commit comments

Comments
 (0)