From 71306b695b57796203d7127848d31661c097102a Mon Sep 17 00:00:00 2001 From: Nikita Semenov Date: Thu, 29 Dec 2022 17:30:30 +0300 Subject: [PATCH 1/3] fix: passing of arguments to a logging message --- LeadKit.podspec | 2 +- TIAppleMapUtils/TIAppleMapUtils.podspec | 2 +- TIAuth/TIAuth.podspec | 2 +- TIEcommerce/TIEcommerce.podspec | 2 +- TIFoundationUtils/TIFoundationUtils.podspec | 2 +- TIGoogleMapUtils/TIGoogleMapUtils.podspec | 2 +- TIKeychainUtils/TIKeychainUtils.podspec | 2 +- .../LogHandler/DefaultLoggerHandler.swift | 45 ++++++++++++++++ .../Logger/LogHandler/LogHandler.swift | 33 ++++++++++++ TILogging/Sources/Logger/Logger.swift | 51 +++++++++++++++---- .../Sources/Logger/Output/DefaultOutput.swift | 44 ++++++++++++++++ .../LogOutputRepresenter.swift} | 4 +- .../Output/Logger+OutputRepresenter.swift | 30 +++++++++++ TILogging/TILogging.podspec | 2 +- TIMapUtils/TIMapUtils.podspec | 2 +- TIMoyaNetworking/TIMoyaNetworking.podspec | 2 +- TINetworking/TINetworking.podspec | 2 +- TINetworkingCache/TINetworkingCache.podspec | 2 +- TIPagination/TIPagination.podspec | 2 +- TISwiftUICore/TISwiftUICore.podspec | 2 +- TISwiftUtils/TISwiftUtils.podspec | 2 +- TITableKitUtils/TITableKitUtils.podspec | 2 +- TITransitions/TITransitions.podspec | 2 +- TIUIElements/TIUIElements.podspec | 2 +- TIUIKitCore/TIUIKitCore.podspec | 2 +- TIYandexMapUtils/TIYandexMapUtils.podspec | 2 +- 26 files changed, 215 insertions(+), 32 deletions(-) create mode 100644 TILogging/Sources/Logger/LogHandler/DefaultLoggerHandler.swift create mode 100644 TILogging/Sources/Logger/LogHandler/LogHandler.swift create mode 100644 TILogging/Sources/Logger/Output/DefaultOutput.swift rename TILogging/Sources/Logger/{LoggerRepresentable.swift => Output/LogOutputRepresenter.swift} (89%) create mode 100644 TILogging/Sources/Logger/Output/Logger+OutputRepresenter.swift diff --git a/LeadKit.podspec b/LeadKit.podspec index 77369e54..a65c9586 100644 --- a/LeadKit.podspec +++ b/LeadKit.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = "LeadKit" - s.version = "1.30.0" + s.version = "1.30.1" s.summary = "iOS framework with a bunch of tools for rapid development" s.homepage = "https://github.com/TouchInstinct/LeadKit" s.license = "Apache License, Version 2.0" diff --git a/TIAppleMapUtils/TIAppleMapUtils.podspec b/TIAppleMapUtils/TIAppleMapUtils.podspec index 80a3f947..47b7d36a 100644 --- a/TIAppleMapUtils/TIAppleMapUtils.podspec +++ b/TIAppleMapUtils/TIAppleMapUtils.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = 'TIAppleMapUtils' - s.version = '1.30.0' + s.version = '1.30.1' s.summary = 'Set of helpers for map objects clustering and interacting using Apple MapKit.' s.homepage = 'https://github.com/TouchInstinct/LeadKit/tree/' + s.version.to_s + '/' + s.name s.license = { :type => 'MIT', :file => 'LICENSE' } diff --git a/TIAuth/TIAuth.podspec b/TIAuth/TIAuth.podspec index 75915749..6e3bff42 100644 --- a/TIAuth/TIAuth.podspec +++ b/TIAuth/TIAuth.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = 'TIAuth' - s.version = '1.30.0' + s.version = '1.30.1' s.summary = 'Login, registration, confirmation and other related actions' s.homepage = 'https://github.com/TouchInstinct/LeadKit/tree/' + s.version.to_s + '/' + s.name s.license = { :type => 'MIT', :file => 'LICENSE' } diff --git a/TIEcommerce/TIEcommerce.podspec b/TIEcommerce/TIEcommerce.podspec index e65a3a19..d2b4334a 100644 --- a/TIEcommerce/TIEcommerce.podspec +++ b/TIEcommerce/TIEcommerce.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = 'TIEcommerce' - s.version = '1.30.0' + s.version = '1.30.1' s.summary = 'Cart, products, promocodes, bonuses and other related actions' s.homepage = 'https://github.com/TouchInstinct/LeadKit/tree/' + s.version.to_s + '/' + s.name s.license = { :type => 'MIT', :file => 'LICENSE' } diff --git a/TIFoundationUtils/TIFoundationUtils.podspec b/TIFoundationUtils/TIFoundationUtils.podspec index 63f45a58..54679ea0 100644 --- a/TIFoundationUtils/TIFoundationUtils.podspec +++ b/TIFoundationUtils/TIFoundationUtils.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = 'TIFoundationUtils' - s.version = '1.30.0' + s.version = '1.30.1' s.summary = 'Set of helpers for Foundation framework classes.' s.homepage = 'https://github.com/TouchInstinct/LeadKit/tree/' + s.version.to_s + '/' + s.name s.license = { :type => 'MIT', :file => 'LICENSE' } diff --git a/TIGoogleMapUtils/TIGoogleMapUtils.podspec b/TIGoogleMapUtils/TIGoogleMapUtils.podspec index 99e30625..8ff5cbec 100644 --- a/TIGoogleMapUtils/TIGoogleMapUtils.podspec +++ b/TIGoogleMapUtils/TIGoogleMapUtils.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = 'TIGoogleMapUtils' - s.version = '1.30.0' + s.version = '1.30.1' s.summary = 'Set of helpers for map objects clustering and interacting using Google Maps SDK.' s.homepage = 'https://github.com/TouchInstinct/LeadKit/tree/' + s.version.to_s + '/' + s.name s.license = { :type => 'MIT', :file => 'LICENSE' } diff --git a/TIKeychainUtils/TIKeychainUtils.podspec b/TIKeychainUtils/TIKeychainUtils.podspec index b0a6525e..981d1d9b 100644 --- a/TIKeychainUtils/TIKeychainUtils.podspec +++ b/TIKeychainUtils/TIKeychainUtils.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = 'TIKeychainUtils' - s.version = '1.30.0' + s.version = '1.30.1' s.summary = 'Set of helpers for Keychain classes.' s.homepage = 'https://github.com/TouchInstinct/LeadKit/tree/' + s.version.to_s + '/' + s.name s.license = { :type => 'MIT', :file => 'LICENSE' } diff --git a/TILogging/Sources/Logger/LogHandler/DefaultLoggerHandler.swift b/TILogging/Sources/Logger/LogHandler/DefaultLoggerHandler.swift new file mode 100644 index 00000000..6ec4ecdc --- /dev/null +++ b/TILogging/Sources/Logger/LogHandler/DefaultLoggerHandler.swift @@ -0,0 +1,45 @@ +// +// Copyright (c) 2022 Touch Instinct +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the Software), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. +// + +import os + +public struct DefaultLoggerHandler: LogHandler { + + public var logInfo: OSLog + public var logger: LogOutputRepresentater? + + public init(logInfo: OSLog) { + self.logInfo = logInfo + + if #available(iOS 14, *) { + self.logger = Logger(logInfo) + } else { + self.logger = DefaultOutput() + } + } + + // MARK: - LogHandler + + public func log(type: OSLogType, log: OSLog?, _ message: String) { + logger?.log(type: type, log: log, message) + } +} diff --git a/TILogging/Sources/Logger/LogHandler/LogHandler.swift b/TILogging/Sources/Logger/LogHandler/LogHandler.swift new file mode 100644 index 00000000..5db88c1e --- /dev/null +++ b/TILogging/Sources/Logger/LogHandler/LogHandler.swift @@ -0,0 +1,33 @@ +// +// Copyright (c) 2022 Touch Instinct +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the Software), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. +// + +import os + +public protocol LogHandler { + func log(type: OSLogType, log: OSLog?, _ message: String) +} + +public extension LogHandler { + func log(type: OSLogType, log: OSLog?, _ message: String) { + // empty implementation + } +} diff --git a/TILogging/Sources/Logger/Logger.swift b/TILogging/Sources/Logger/Logger.swift index 07507989..08caa171 100644 --- a/TILogging/Sources/Logger/Logger.swift +++ b/TILogging/Sources/Logger/Logger.swift @@ -23,7 +23,7 @@ import Foundation import os -public struct TILogger: LoggerRepresentable { +public struct TILogger { // MARK: - Properties @@ -31,44 +31,75 @@ public struct TILogger: LoggerRepresentable { public static let defaultLogger = TILogger(subsystem: .defaultSubsystem ?? "", category: .pointsOfInterest) public let logInfo: OSLog + public var loggerHandler: LogHandler? // MARK: - Init public init(subsystem: String, category: String) { self.logInfo = .init(subsystem: subsystem, category: category) + self.loggerHandler = DefaultLoggerHandler(logInfo: logInfo) } @available(iOS 12, *) public init(subsystem: String, category: OSLog.Category) { self.logInfo = .init(subsystem: subsystem, category: category) + self.loggerHandler = DefaultLoggerHandler(logInfo: logInfo) } - // MARK: - LoggerRepresentable + // MARK: - Public methods - public func log(_ message: StaticString, log: OSLog?, type: OSLogType, _ arguments: CVarArg...) { - os_log(message, log: log ?? logInfo, type: type, arguments) + public func log(_ message: StaticString, log: OSLog? = nil, type: OSLogType, _ arguments: CVarArg...) { + let stringMessage = String(format: "\(message)", arguments: arguments) + self.log(type: type, log: log, stringMessage) } - // MARK: - Public methods + public func log(type: OSLogType, log: OSLog? = nil, _ message: String) { + loggerHandler?.log(type: type, log: log ?? logInfo, message) + } public func verbose(_ message: StaticString, _ arguments: CVarArg...) { - self.log(message, log: logInfo, type: .default, arguments) + let stringMessage = String(format: "\(message)", arguments: arguments) + self.log(type: .default, stringMessage) + } + + public func verbose(_ message: String) { + self.log(type: .default, message) } public func info(_ message: StaticString, _ arguments: CVarArg...) { - self.log(message, log: logInfo, type: .info, arguments) + let stringMessage = String(format: "\(message)", arguments: arguments) + self.log(type: .info, stringMessage) + } + + public func info(_ message: String) { + self.log(type: .info, message) } public func debug(_ message: StaticString, _ arguments: CVarArg...) { - self.log(message, log: logInfo, type: .debug, arguments) + let stringMessage = String(format: "\(message)", arguments: arguments) + self.log(type: .debug, stringMessage) + } + + public func debug(_ message: String) { + self.log(type: .debug, message) } public func error(_ message: StaticString, _ arguments: CVarArg...) { - self.log(message, log: logInfo, type: .error, arguments) + let stringMessage = String(format: "\(message)", arguments: arguments) + self.log(type: .error, stringMessage) + } + + public func error(_ message: String) { + self.log(type: .error, message) } public func fault(_ message: StaticString, _ arguments: CVarArg...) { - self.log(message, log: logInfo, type: .fault, arguments) + let stringMessage = String(format: "\(message)", arguments: arguments) + self.log(type: .fault, stringMessage) + } + + public func fault(_ message: String) { + self.log(type: .fault, message) } } diff --git a/TILogging/Sources/Logger/Output/DefaultOutput.swift b/TILogging/Sources/Logger/Output/DefaultOutput.swift new file mode 100644 index 00000000..893584f5 --- /dev/null +++ b/TILogging/Sources/Logger/Output/DefaultOutput.swift @@ -0,0 +1,44 @@ +// +// Copyright (c) 2022 Touch Instinct +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the Software), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. +// + +import os +import _SwiftOSOverlayShims + +public struct DefaultOutput: LogOutputRepresentater { + + public func log(type: OSLogType, log: OSLog?, _ message: String) { + guard let logInfo = log, logInfo.isEnabled(type: type) else { + return + } + + let ra = _swift_os_log_return_address() + var mutableMessage = message + + mutableMessage.withUTF8 { (buf: UnsafeBufferPointer) in + buf.baseAddress!.withMemoryRebound(to: CChar.self, capacity: buf.count) { str in + withVaList([]) { valist in + _swift_os_log(#dsohandle, ra, logInfo, type, str, valist) + } + } + } + } +} diff --git a/TILogging/Sources/Logger/LoggerRepresentable.swift b/TILogging/Sources/Logger/Output/LogOutputRepresenter.swift similarity index 89% rename from TILogging/Sources/Logger/LoggerRepresentable.swift rename to TILogging/Sources/Logger/Output/LogOutputRepresenter.swift index 5337fcfe..9a6fa0db 100644 --- a/TILogging/Sources/Logger/LoggerRepresentable.swift +++ b/TILogging/Sources/Logger/Output/LogOutputRepresenter.swift @@ -22,6 +22,6 @@ import os -public protocol LoggerRepresentable { - func log(_ message: StaticString, log: OSLog?, type: OSLogType, _ arguments: CVarArg...) +public protocol LogOutputRepresentater { + func log(type: OSLogType, log: OSLog?, _ message: String) } diff --git a/TILogging/Sources/Logger/Output/Logger+OutputRepresenter.swift b/TILogging/Sources/Logger/Output/Logger+OutputRepresenter.swift new file mode 100644 index 00000000..1a94bffa --- /dev/null +++ b/TILogging/Sources/Logger/Output/Logger+OutputRepresenter.swift @@ -0,0 +1,30 @@ +// +// Copyright (c) 2022 Touch Instinct +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the Software), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. +// + +import os + +@available(iOS 14.0, *) +extension Logger: LogOutputRepresentater { + public func log(type: OSLogType, log: OSLog?, _ message: String) { + self.log(level: type, "\(message)") + } +} diff --git a/TILogging/TILogging.podspec b/TILogging/TILogging.podspec index 20b9d4b6..fdd4ae7a 100644 --- a/TILogging/TILogging.podspec +++ b/TILogging/TILogging.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = 'TILogging' - s.version = '1.30.0' + s.version = '1.30.1' s.summary = 'Logging API' s.homepage = 'https://github.com/TouchInstinct/LeadKit/tree/' + s.version.to_s + '/' + s.name s.license = { :type => 'MIT', :file => 'LICENSE' } diff --git a/TIMapUtils/TIMapUtils.podspec b/TIMapUtils/TIMapUtils.podspec index 578a4eb3..28b7a456 100644 --- a/TIMapUtils/TIMapUtils.podspec +++ b/TIMapUtils/TIMapUtils.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = 'TIMapUtils' - s.version = '1.30.0' + s.version = '1.30.1' s.summary = 'Set of helpers for map objects clustering and interacting.' s.homepage = 'https://github.com/TouchInstinct/LeadKit/tree/' + s.version.to_s + '/' + s.name s.license = { :type => 'MIT', :file => 'LICENSE' } diff --git a/TIMoyaNetworking/TIMoyaNetworking.podspec b/TIMoyaNetworking/TIMoyaNetworking.podspec index 867865d6..d57f158f 100644 --- a/TIMoyaNetworking/TIMoyaNetworking.podspec +++ b/TIMoyaNetworking/TIMoyaNetworking.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = 'TIMoyaNetworking' - s.version = '1.30.0' + s.version = '1.30.1' s.summary = 'Moya + Swagger network service.' s.homepage = 'https://github.com/TouchInstinct/LeadKit/tree/' + s.version.to_s + '/' + s.name s.license = { :type => 'MIT', :file => 'LICENSE' } diff --git a/TINetworking/TINetworking.podspec b/TINetworking/TINetworking.podspec index 8f92f73a..e1ce09af 100644 --- a/TINetworking/TINetworking.podspec +++ b/TINetworking/TINetworking.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = 'TINetworking' - s.version = '1.30.0' + s.version = '1.30.1' s.summary = 'Swagger-frendly networking layer helpers.' s.homepage = 'https://github.com/TouchInstinct/LeadKit/tree/' + s.version.to_s + '/' + s.name s.license = { :type => 'MIT', :file => 'LICENSE' } diff --git a/TINetworkingCache/TINetworkingCache.podspec b/TINetworkingCache/TINetworkingCache.podspec index 3131de4f..87d0a425 100644 --- a/TINetworkingCache/TINetworkingCache.podspec +++ b/TINetworkingCache/TINetworkingCache.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = 'TINetworkingCache' - s.version = '1.30.0' + s.version = '1.30.1' s.summary = 'Caching results of EndpointRequests.' s.homepage = 'https://github.com/TouchInstinct/LeadKit/tree/' + s.version.to_s + '/' + s.name s.license = { :type => 'MIT', :file => 'LICENSE' } diff --git a/TIPagination/TIPagination.podspec b/TIPagination/TIPagination.podspec index 1df31c1f..e04d888f 100644 --- a/TIPagination/TIPagination.podspec +++ b/TIPagination/TIPagination.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = 'TIPagination' - s.version = '1.30.0' + s.version = '1.30.1' s.summary = 'Generic pagination component.' s.homepage = 'https://github.com/TouchInstinct/LeadKit/tree/' + s.version.to_s + '/' + s.name s.license = { :type => 'MIT', :file => 'LICENSE' } diff --git a/TISwiftUICore/TISwiftUICore.podspec b/TISwiftUICore/TISwiftUICore.podspec index f9a4a99a..867e8fe0 100644 --- a/TISwiftUICore/TISwiftUICore.podspec +++ b/TISwiftUICore/TISwiftUICore.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = 'TISwiftUICore' - s.version = '1.30.0' + s.version = '1.30.1' s.summary = 'Core UI elements: protocols, views and helpers.' s.homepage = 'https://github.com/TouchInstinct/LeadKit/tree/' + s.version.to_s + '/' + s.name s.license = { :type => 'MIT', :file => 'LICENSE' } diff --git a/TISwiftUtils/TISwiftUtils.podspec b/TISwiftUtils/TISwiftUtils.podspec index fc9189e6..f0867fc9 100644 --- a/TISwiftUtils/TISwiftUtils.podspec +++ b/TISwiftUtils/TISwiftUtils.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = 'TISwiftUtils' - s.version = '1.30.0' + s.version = '1.30.1' s.summary = 'Bunch of useful helpers for Swift development.' s.homepage = 'https://github.com/TouchInstinct/LeadKit/tree/' + s.version.to_s + '/' + s.name s.license = { :type => 'MIT', :file => 'LICENSE' } diff --git a/TITableKitUtils/TITableKitUtils.podspec b/TITableKitUtils/TITableKitUtils.podspec index fe06f081..c498650b 100644 --- a/TITableKitUtils/TITableKitUtils.podspec +++ b/TITableKitUtils/TITableKitUtils.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = 'TITableKitUtils' - s.version = '1.30.0' + s.version = '1.30.1' s.summary = 'Set of helpers for TableKit classes.' s.homepage = 'https://github.com/TouchInstinct/LeadKit/tree/' + s.version.to_s + '/' + s.name s.license = { :type => 'MIT', :file => 'LICENSE' } diff --git a/TITransitions/TITransitions.podspec b/TITransitions/TITransitions.podspec index e27da747..338f19e5 100644 --- a/TITransitions/TITransitions.podspec +++ b/TITransitions/TITransitions.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = 'TITransitions' - s.version = '1.30.0' + s.version = '1.30.1' s.summary = 'Set of custom transitions to present controller. ' s.homepage = 'https://github.com/TouchInstinct/LeadKit/tree/' + s.version.to_s + '/' + s.name s.license = { :type => 'MIT', :file => 'LICENSE' } diff --git a/TIUIElements/TIUIElements.podspec b/TIUIElements/TIUIElements.podspec index bb4eadba..152981dd 100644 --- a/TIUIElements/TIUIElements.podspec +++ b/TIUIElements/TIUIElements.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = 'TIUIElements' - s.version = '1.30.0' + s.version = '1.30.1' s.summary = 'Bunch of useful protocols and views.' s.homepage = 'https://github.com/TouchInstinct/LeadKit/tree/' + s.version.to_s + '/' + s.name s.license = { :type => 'MIT', :file => 'LICENSE' } diff --git a/TIUIKitCore/TIUIKitCore.podspec b/TIUIKitCore/TIUIKitCore.podspec index 533371cd..87d94dce 100644 --- a/TIUIKitCore/TIUIKitCore.podspec +++ b/TIUIKitCore/TIUIKitCore.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = 'TIUIKitCore' - s.version = '1.30.0' + s.version = '1.30.1' s.summary = 'Core UI elements: protocols, views and helpers.' s.homepage = 'https://github.com/TouchInstinct/LeadKit/tree/' + s.version.to_s + '/' + s.name s.license = { :type => 'MIT', :file => 'LICENSE' } diff --git a/TIYandexMapUtils/TIYandexMapUtils.podspec b/TIYandexMapUtils/TIYandexMapUtils.podspec index ff7ea34a..a1a170d5 100644 --- a/TIYandexMapUtils/TIYandexMapUtils.podspec +++ b/TIYandexMapUtils/TIYandexMapUtils.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = 'TIYandexMapUtils' - s.version = '1.30.0' + s.version = '1.30.1' s.summary = 'Set of helpers for map objects clustering and interacting using Yandex Maps SDK.' s.homepage = 'https://github.com/TouchInstinct/LeadKit/tree/' + s.version.to_s + '/' + s.name s.license = { :type => 'MIT', :file => 'LICENSE' } From 57d40f18ef344c0c31eac614648d7caf0acbd092 Mon Sep 17 00:00:00 2001 From: Nikita Semenov Date: Thu, 29 Dec 2022 17:33:08 +0300 Subject: [PATCH 2/3] docs: added documentation to TILogging --- CHANGELOG.md | 5 +++++ TILogging/README.md | 24 ++++++++++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 TILogging/README.md diff --git a/CHANGELOG.md b/CHANGELOG.md index 6e303738..f797e135 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # Changelog +### 1.30.1 + +- **Fix**: `TILogging` bug with passing arguments to a logging message with wrapped `os_log` function; +- **Added**: Documentation for `TILogging`. + ### 1.30.0 - **Added**: Base classes for encryption and decryption user token with pin code or biometry diff --git a/TILogging/README.md b/TILogging/README.md new file mode 100644 index 00000000..38750db9 --- /dev/null +++ b/TILogging/README.md @@ -0,0 +1,24 @@ +# TILogging + +## Logger usage + +```swift +let logger = TILogger.defaultLogger + +// string interpolation +logger.log(type: .default, "🐈 Hello from \(someName), I'm machine number \(someNumer)") + +// passing CVarArgs +logger.log("🐈 Hello from %@, I'm machine number %i", type: .default, someName, someNumber) +``` + +To pass arguments to a logging string it is essantial to pass valid formatting specifiers + +| Specifier | Type | Usage | +| --------- | ---- | ----- | +| `%i`, `%d` | `Int` | `logger.verbose("🎉 int %i", 1)` | +| `%f` | `Float` | `logger.verbose("🎉 float %f", Float(1.23))` | +| `%f` | `Double` | `logger.verbose("🎉 double %f", Double(1.23))` | +| `%@` | `String` | `logger.verbose("🎉 string %@", "String")` | + +> For more information about string format specifiers check the [documentation](https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/Strings/Articles/formatSpecifiers.html) From cce06d57af769823b42630ebb95629c39ebbe97b Mon Sep 17 00:00:00 2001 From: Nikita Semenov Date: Thu, 29 Dec 2022 21:45:18 +0300 Subject: [PATCH 3/3] fix: code review notes --- .../Sources/Logger/LogHandler/DefaultLoggerHandler.swift | 4 ++-- TILogging/Sources/Logger/LogHandler/LogHandler.swift | 6 ------ .../{DefaultOutput.swift => DefaultOutputStream.swift} | 4 ++-- .../{LogOutputRepresenter.swift => LogOutputStream.swift} | 2 +- .../Sources/Logger/Output/Logger+OutputRepresenter.swift | 2 +- 5 files changed, 6 insertions(+), 12 deletions(-) rename TILogging/Sources/Logger/Output/{DefaultOutput.swift => DefaultOutputStream.swift} (93%) rename TILogging/Sources/Logger/Output/{LogOutputRepresenter.swift => LogOutputStream.swift} (96%) diff --git a/TILogging/Sources/Logger/LogHandler/DefaultLoggerHandler.swift b/TILogging/Sources/Logger/LogHandler/DefaultLoggerHandler.swift index 6ec4ecdc..71f7f7ae 100644 --- a/TILogging/Sources/Logger/LogHandler/DefaultLoggerHandler.swift +++ b/TILogging/Sources/Logger/LogHandler/DefaultLoggerHandler.swift @@ -25,7 +25,7 @@ import os public struct DefaultLoggerHandler: LogHandler { public var logInfo: OSLog - public var logger: LogOutputRepresentater? + public var logger: LogOutputStream? public init(logInfo: OSLog) { self.logInfo = logInfo @@ -33,7 +33,7 @@ public struct DefaultLoggerHandler: LogHandler { if #available(iOS 14, *) { self.logger = Logger(logInfo) } else { - self.logger = DefaultOutput() + self.logger = DefaultOutputStream() } } diff --git a/TILogging/Sources/Logger/LogHandler/LogHandler.swift b/TILogging/Sources/Logger/LogHandler/LogHandler.swift index 5db88c1e..a5935dea 100644 --- a/TILogging/Sources/Logger/LogHandler/LogHandler.swift +++ b/TILogging/Sources/Logger/LogHandler/LogHandler.swift @@ -25,9 +25,3 @@ import os public protocol LogHandler { func log(type: OSLogType, log: OSLog?, _ message: String) } - -public extension LogHandler { - func log(type: OSLogType, log: OSLog?, _ message: String) { - // empty implementation - } -} diff --git a/TILogging/Sources/Logger/Output/DefaultOutput.swift b/TILogging/Sources/Logger/Output/DefaultOutputStream.swift similarity index 93% rename from TILogging/Sources/Logger/Output/DefaultOutput.swift rename to TILogging/Sources/Logger/Output/DefaultOutputStream.swift index 893584f5..c5249967 100644 --- a/TILogging/Sources/Logger/Output/DefaultOutput.swift +++ b/TILogging/Sources/Logger/Output/DefaultOutputStream.swift @@ -23,7 +23,7 @@ import os import _SwiftOSOverlayShims -public struct DefaultOutput: LogOutputRepresentater { +public struct DefaultOutputStream: LogOutputStream { public func log(type: OSLogType, log: OSLog?, _ message: String) { guard let logInfo = log, logInfo.isEnabled(type: type) else { @@ -34,7 +34,7 @@ public struct DefaultOutput: LogOutputRepresentater { var mutableMessage = message mutableMessage.withUTF8 { (buf: UnsafeBufferPointer) in - buf.baseAddress!.withMemoryRebound(to: CChar.self, capacity: buf.count) { str in + buf.baseAddress?.withMemoryRebound(to: CChar.self, capacity: buf.count) { str in withVaList([]) { valist in _swift_os_log(#dsohandle, ra, logInfo, type, str, valist) } diff --git a/TILogging/Sources/Logger/Output/LogOutputRepresenter.swift b/TILogging/Sources/Logger/Output/LogOutputStream.swift similarity index 96% rename from TILogging/Sources/Logger/Output/LogOutputRepresenter.swift rename to TILogging/Sources/Logger/Output/LogOutputStream.swift index 9a6fa0db..d6ff6a4e 100644 --- a/TILogging/Sources/Logger/Output/LogOutputRepresenter.swift +++ b/TILogging/Sources/Logger/Output/LogOutputStream.swift @@ -22,6 +22,6 @@ import os -public protocol LogOutputRepresentater { +public protocol LogOutputStream { func log(type: OSLogType, log: OSLog?, _ message: String) } diff --git a/TILogging/Sources/Logger/Output/Logger+OutputRepresenter.swift b/TILogging/Sources/Logger/Output/Logger+OutputRepresenter.swift index 1a94bffa..51597168 100644 --- a/TILogging/Sources/Logger/Output/Logger+OutputRepresenter.swift +++ b/TILogging/Sources/Logger/Output/Logger+OutputRepresenter.swift @@ -23,7 +23,7 @@ import os @available(iOS 14.0, *) -extension Logger: LogOutputRepresentater { +extension Logger: LogOutputStream { public func log(type: OSLogType, log: OSLog?, _ message: String) { self.log(level: type, "\(message)") }