Skip to content

Instantly share code, notes, and snippets.

@valeriomazzeo
Last active May 7, 2021 14:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save valeriomazzeo/bf7fe4b07059aa4c014b80bfd20bc017 to your computer and use it in GitHub Desktop.
Save valeriomazzeo/bf7fe4b07059aa4c014b80bfd20bc017 to your computer and use it in GitHub Desktop.
SwiftyBeaver+ThreadSafe.swift related to https://github.com/SwiftyBeaver/SwiftyBeaver/issues/340
/**
Relates to https://github.com/SwiftyBeaver/SwiftyBeaver/issues/340
*/
extension SwiftyBeaver {
@usableFromInline
static let queue = DispatchQueue(label: "com.asensei.asensei.SwiftyBeaver")
@discardableResult
class func ts_addDestination(_ destination: BaseDestination) -> Bool {
return self.queue.sync { SwiftyBeaver.addDestination(destination) }
}
@discardableResult
class func ts_removeDestination(_ destination: BaseDestination) -> Bool {
return self.queue.sync { SwiftyBeaver.removeDestination(destination) }
}
class func ts_removeAllDestinations() {
self.queue.sync { SwiftyBeaver.removeAllDestinations() }
}
class func ts_countDestinations() -> Int {
return self.queue.sync { SwiftyBeaver.countDestinations() }
}
}
extension SwiftyBeaver: Logger {
public static func custom(level: LoggerLevel, message: @autoclosure () -> Any, file: String, function: String, line: Int, context: Any?) {
self.queue.sync {
SwiftyBeaver.custom(
level: .init(level),
message: message(),
file: file,
function: function,
line: line,
context: context
)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment