Skip to content

Commit

Permalink
Removed shared library variant.
Browse files Browse the repository at this point in the history
Guard against multiple copies of Logger being linked.
  • Loading branch information
samdeane committed Aug 14, 2019
1 parent d51ba24 commit 5524dce
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
8 changes: 0 additions & 8 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,9 @@ let package = Package(
.macOS(.v10_13), .iOS(.v12),
],
products: [
.library(
name: "LoggerShared",
type: .dynamic,
targets: ["Logger"]),
.library(
name: "Logger",
targets: ["Logger"]),
.library(
name: "LoggerKitShared",
type: .dynamic,
targets: ["LoggerKit"]),
.library(
name: "LoggerKit",
targets: ["LoggerKit"]),
Expand Down
21 changes: 20 additions & 1 deletion Sources/Logger/Channel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,26 @@ public class Channel {
though, which is why it's not a true singleton.
*/

public static let defaultManager = Manager()
public static let defaultManager = initDefaultManager()

/// Initialise the default log manager.
static func initDefaultManager() -> Manager {
#if ensureUniqueManager
/// We really do want there to only be a single instance of this, even if the logger library has mistakenly been
/// linked multiple times, so we store it in the thread dictionary for the main thread, and retrieve it from there if necessary
let dictionary = Thread.main.threadDictionary
if let manager = dictionary["Logger.Manager"] {
return unsafeBitCast(manager as AnyObject, to: Manager.self) // a normal cast might fail here if the code has been linked multiple times, since the class could be different (but identical)
}

let manager = Manager()
dictionary["Logger.Manager"] = manager
return manager

#else
return Manager()
#endif
}

/**
Default subsystem if nothing else is specified.
Expand Down

0 comments on commit 5524dce

Please sign in to comment.