From 4ff973f288b99a3ae8f1364d0397b2cc94f5336b Mon Sep 17 00:00:00 2001 From: Konrad `ktoso` Malawski Date: Mon, 6 Jul 2020 20:06:58 +0900 Subject: [PATCH] =doc #82 avoid showcasing internal lock in public docs --- Sources/Logging/LogHandler.swift | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/Sources/Logging/LogHandler.swift b/Sources/Logging/LogHandler.swift index 244cd430..6b52b120 100644 --- a/Sources/Logging/LogHandler.swift +++ b/Sources/Logging/LogHandler.swift @@ -56,9 +56,11 @@ /// `LogHandlerWithGlobalLogLevelOverride.overrideGlobalLogLevel = .debug`, for example. /// /// ```swift +/// import class Foundation.NSLock +/// /// public struct LogHandlerWithGlobalLogLevelOverride: LogHandler { /// // the static properties hold the globally overridden log level (if overridden) -/// private static let overrideLock = Lock() +/// private static let overrideLock = NSLock() /// private static var overrideLogLevel: Logger.Level? = nil /// /// // this holds the log level if not overridden @@ -74,9 +76,9 @@ /// public var logLevel: Logger.Level { /// // when we get asked for the log level, we check if it was globally overridden or not /// get { -/// return LogHandlerWithGlobalLogLevelOverride.overrideLock.withLock { -/// return LogHandlerWithGlobalLogLevelOverride.overrideLogLevel -/// } ?? self._logLevel +/// LogHandlerWithGlobalLogLevelOverride.overrideLock.lock() +/// defer { LogHandlerWithGlobalLogLevelOverride.overrideLock.unlock() } +/// return LogHandlerWithGlobalLogLevelOverride.overrideLogLevel ?? self._logLevel /// } /// // we set the log level whenever we're asked (note: this might not have an effect if globally /// // overridden) @@ -101,9 +103,9 @@ /// /// // this is the function to globally override the log level, it is not part of the `LogHandler` protocol /// public static func overrideGlobalLogLevel(_ logLevel: Logger.Level) { -/// LogHandlerWithGlobalLogLevelOverride.overrideLock.withLock { -/// LogHandlerWithGlobalLogLevelOverride.overrideLogLevel = logLevel -/// } +/// LogHandlerWithGlobalLogLevelOverride.overrideLock.lock() +/// defer { LogHandlerWithGlobalLogLevelOverride.overrideLock.unlock() } +/// LogHandlerWithGlobalLogLevelOverride.overrideLogLevel = logLevel /// } /// } /// ```