From bd53e680b385a3f16b14db359209f8ae337af240 Mon Sep 17 00:00:00 2001 From: Darren Ford Date: Wed, 7 Feb 2024 11:30:04 +1100 Subject: [PATCH] Added basic logging --- Sources/CIFilterFactory/CIFilterFactory.swift | 32 +++++---------- .../CIFilterFactory/private/CIFF+Logger.swift | 40 +++++++++++++++++++ 2 files changed, 49 insertions(+), 23 deletions(-) create mode 100644 Sources/CIFilterFactory/private/CIFF+Logger.swift diff --git a/Sources/CIFilterFactory/CIFilterFactory.swift b/Sources/CIFilterFactory/CIFilterFactory.swift index 685a1539..dc5f17df 100644 --- a/Sources/CIFilterFactory/CIFilterFactory.swift +++ b/Sources/CIFilterFactory/CIFilterFactory.swift @@ -23,7 +23,10 @@ import CoreImage import Foundation + +#if canImport(OSLog) import OSLog +#endif /// The namespace object for the filter factory @objc public class CIFF: NSObject { @@ -105,13 +108,8 @@ import OSLog internal init?(name: String) { guard let filter = CIFilter(name: name) else { - if #available(macOS 10.12, iOS 10, tvOS 10, *) { - os_log( - "CIFilterFactory: Filter '%@' does is not supported on this platform.", - log: OSLog.default, - type: .error, - name - ) + if #available(macOS 11, iOS 14, tvOS 14, *) { + _logger.error("CIFilterFactory: Filter '\(name, privacy: .public)' is not supported on this platform.") } return nil } @@ -129,14 +127,8 @@ internal extension CIFF.Core { // Convenience method for getting a value of a specific type @inline(__always) func keyedValue(_ key: String) -> TYPE? { guard self.filter.attributes[key] != nil else { - if #available(macOS 10.12, iOS 10, tvOS 10, *) { - os_log( - "CIFilterFactory: '%@' does not support parameter '%@' on this platform.", - log: OSLog.default, - type: .error, - self.filter.name, - key - ) + if #available(macOS 11, iOS 14, tvOS 14, *) { + _logger.error("CIFilterFactory: '\(self.filter.name, privacy: .public)' does not support parameter '\(key, privacy: .public)' on this platform.") } return nil } @@ -148,14 +140,8 @@ internal extension CIFF.Core { // Apple seems to have added some new filter parameters ("inputExtrapolate") to some filters which // are not available on older OS versions. guard self.filter.attributes[key] != nil else { - if #available(macOS 10.12, iOS 10, tvOS 10, *) { - os_log( - "CIFilterFactory: '%@' does not support parameter '%@' on this platform. Ignoring…", - log: OSLog.default, - type: .error, - self.filter.name, - key - ) + if #available(macOS 11, iOS 14, tvOS 14, *) { + _logger.error("CIFilterFactory: '\(self.filter.name, privacy: .public)' does not support parameter '\(key, privacy: .public)' on this platform. Ignoring…") } return } diff --git a/Sources/CIFilterFactory/private/CIFF+Logger.swift b/Sources/CIFilterFactory/private/CIFF+Logger.swift new file mode 100644 index 00000000..2fa0aaa4 --- /dev/null +++ b/Sources/CIFilterFactory/private/CIFF+Logger.swift @@ -0,0 +1,40 @@ +// +// CIFF+Logger.swift +// +// Copyright © 2024 Darren Ford. All rights reserved. +// +// MIT license +// +// 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. +// + +// Error logging extensions for CIFilterFactory + +#if canImport(OSLog) + +import Foundation +import OSLog + +@available(macOS 11.0, iOS 14, tvOS 14, *) +internal var _logger: Logger = Logger() + +@available(macOS 11.0, iOS 14, tvOS 14, *) +extension CIFF { + /// Set the logger instance to be used when presenting error messages + public static func SetLogger(_ logger: Logger) { + _logger = logger + } +} + +#endif