Skip to content

Commit

Permalink
Add log level and ignore missing frame log
Browse files Browse the repository at this point in the history
  • Loading branch information
onevcat committed May 29, 2022
1 parent 189e8e6 commit ea39519
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Source/APNGKit/APNGImageView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ open class APNGImageView: PlatformView {
guard let renderer = renderer, let _ = renderer.output /* the frame image is rendered */ else {
// but unfortunately the decoding missed the target.
// we can just wait for the next `step`.
printLog("Missed frame for image \(image): target index: \(nextFrameIndex), while displaying the current frame index: \(displayingFrameIndex).")
printLog("Missed frame for image \(image): target index: \(nextFrameIndex), while displaying the current frame index: \(displayingFrameIndex).", logLevel: .verbose)
onFrameMissed(nextFrameIndex)
frameMissed = true
return
Expand Down
9 changes: 7 additions & 2 deletions Source/APNGKit/Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ extension UnsignedInteger {
}
}

func printLog(_ item: Any) {
print("[APNGKit] \(item)")
func printLog(_ item: Any, logLevel: LogLevel = .default) {
if logLevel == .off || LogLevel.current == .off {
return
}
if logLevel <= LogLevel.current {
print("[APNGKit] \(item)")
}
}
27 changes: 27 additions & 0 deletions Source/APNGKit/LogLevel.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//
// LogLevel.swift
//
//
// Created by: onevcat (Wei Wang) on 2022/05/29
//

import Foundation

/// Log level when APNGKit to determine if the log should be printed into console.
public enum LogLevel: Int32, Comparable {
public static func < (lhs: LogLevel, rhs: LogLevel) -> Bool {
lhs.rawValue < rhs.rawValue
}

/// The log should be turned off.
case off = 0
/// The default log level. Only critical issues or errors will be printed
case `default` = 0x00000001
/// Also log some ignorable logs for diagnose purpose.
case info = 0x00001000
/// Verbose log can be used to show all information. Not in use now.
case verbose = 0x10000000

/// The global setting of the log printed by APNGKit.
public static var current: LogLevel = .default
}

0 comments on commit ea39519

Please sign in to comment.