Skip to content

Commit

Permalink
Added basic logging
Browse files Browse the repository at this point in the history
  • Loading branch information
dagronf committed Feb 7, 2024
1 parent 33ca043 commit bd53e68
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 23 deletions.
32 changes: 9 additions & 23 deletions Sources/CIFilterFactory/CIFilterFactory.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}
Expand All @@ -129,14 +127,8 @@ internal extension CIFF.Core {
// Convenience method for getting a value of a specific type
@inline(__always) func keyedValue<TYPE>(_ 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
}
Expand All @@ -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
}
Expand Down
40 changes: 40 additions & 0 deletions Sources/CIFilterFactory/private/CIFF+Logger.swift
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit bd53e68

Please sign in to comment.