diff --git a/SDWebImage/Core/SDImageCache.m b/SDWebImage/Core/SDImageCache.m index 84b27c30..39d27d94 100644 --- a/SDWebImage/Core/SDImageCache.m +++ b/SDWebImage/Core/SDImageCache.m @@ -7,6 +7,7 @@ */ #import "SDImageCache.h" +#import "SDInternalMacros.h" #import "NSImage+Compatibility.h" #import "SDImageCodersManager.h" #import "SDImageCoderHelper.h" @@ -316,7 +317,7 @@ static NSString * _defaultDiskCacheDirectory; NSError *error; extendedData = [NSKeyedArchiver archivedDataWithRootObject:extendedObject requiringSecureCoding:NO error:&error]; if (error) { - NSLog(@"NSKeyedArchiver archive failed with error: %@", error); + SD_LOG("NSKeyedArchiver archive failed with error: %@", error); } } else { @try { @@ -325,7 +326,7 @@ static NSString * _defaultDiskCacheDirectory; extendedData = [NSKeyedArchiver archivedDataWithRootObject:extendedObject]; #pragma clang diagnostic pop } @catch (NSException *exception) { - NSLog(@"NSKeyedArchiver archive failed with exception: %@", exception); + SD_LOG("NSKeyedArchiver archive failed with exception: %@", exception); } } if (extendedData) { @@ -574,7 +575,7 @@ static NSString * _defaultDiskCacheDirectory; unarchiver.requiresSecureCoding = NO; extendedObject = [unarchiver decodeTopLevelObjectForKey:NSKeyedArchiveRootObjectKey error:&error]; if (error) { - NSLog(@"NSKeyedUnarchiver unarchive failed with error: %@", error); + SD_LOG("NSKeyedUnarchiver unarchive failed with error: %@", error); } } else { @try { @@ -583,7 +584,7 @@ static NSString * _defaultDiskCacheDirectory; extendedObject = [NSKeyedUnarchiver unarchiveObjectWithData:extendedData]; #pragma clang diagnostic pop } @catch (NSException *exception) { - NSLog(@"NSKeyedUnarchiver unarchive failed with exception: %@", exception); + SD_LOG("NSKeyedUnarchiver unarchive failed with exception: %@", exception); } } image.sd_extendedObject = extendedObject; diff --git a/SDWebImage/Core/SDImageIOAnimatedCoder.m b/SDWebImage/Core/SDImageIOAnimatedCoder.m index 77ccb0d4..d28f0060 100644 --- a/SDWebImage/Core/SDImageIOAnimatedCoder.m +++ b/SDWebImage/Core/SDImageIOAnimatedCoder.m @@ -238,7 +238,7 @@ static BOOL SDImageIOPNGPluginBuggyNeedWorkaround(void) { // Correct value isBuggy = NO; } else { - NSLog(@"Detected the current OS's ImageIO PNG Decoder is buggy on indexed color PNG. Perform workaround solution..."); + SD_LOG("Detected the current OS's ImageIO PNG Decoder is buggy on indexed color PNG. Perform workaround solution..."); isBuggy = YES; } } diff --git a/SDWebImage/Core/UIImage+Transform.m b/SDWebImage/Core/UIImage+Transform.m index cbfd14e5..65c7d638 100644 --- a/SDWebImage/Core/UIImage+Transform.m +++ b/SDWebImage/Core/UIImage+Transform.m @@ -11,6 +11,7 @@ #import "SDImageGraphics.h" #import "SDGraphicsImageRenderer.h" #import "NSBezierPath+SDRoundedCorners.h" +#import "SDInternalMacros.h" #import #if SD_UIKIT || SD_MAC #import @@ -648,7 +649,7 @@ static inline CGImageRef _Nullable SDCreateCGImageFromCIImage(CIImage * _Nonnull // Convert to color return SDGetColorFromRGBA(pixel, bitmapInfo, colorSpace); } else { - NSLog(@"Unsupported components: %zu", components); + SD_LOG("Unsupported components: %zu", components); CFRelease(data); CGImageRelease(imageRef); return nil; @@ -732,7 +733,7 @@ static inline CGImageRef _Nullable SDCreateCGImageFromCIImage(CIImage * _Nonnull Pixel_8888 pixel = {pixels[index], pixels[index+1], pixels[index+2], pixels[index+3]}; color = SDGetColorFromRGBA(pixel, bitmapInfo, colorSpace); } else { - NSLog(@"Unsupported components: %zu", components); + SD_LOG("Unsupported components: %zu", components); } } if (color) { @@ -796,12 +797,12 @@ static inline CGImageRef _Nullable SDCreateCGImageFromCIImage(CIImage * _Nonnull vImage_Error err; err = vImageBuffer_InitWithCGImage(&effect, &format, NULL, imageRef, kvImageNoFlags); // vImage will convert to format we requests, no need `vImageConvert` if (err != kvImageNoError) { - NSLog(@"UIImage+Transform error: vImageBuffer_InitWithCGImage returned error code %zi for inputImage: %@", err, self); + SD_LOG("UIImage+Transform error: vImageBuffer_InitWithCGImage returned error code %zi for inputImage: %@", err, self); return nil; } err = vImageBuffer_Init(&scratch, effect.height, effect.width, format.bitsPerPixel, kvImageNoFlags); if (err != kvImageNoError) { - NSLog(@"UIImage+Transform error: vImageBuffer_Init returned error code %zi for inputImage: %@", err, self); + SD_LOG("UIImage+Transform error: vImageBuffer_Init returned error code %zi for inputImage: %@", err, self); return nil; } diff --git a/SDWebImage/Private/SDInternalMacros.h b/SDWebImage/Private/SDInternalMacros.h index 0b84c68a..2a9cdc23 100644 --- a/SDWebImage/Private/SDInternalMacros.h +++ b/SDWebImage/Private/SDInternalMacros.h @@ -9,6 +9,7 @@ #import #import #import +#import #import "SDmetamacros.h" #define SD_USE_OS_UNFAIR_LOCK TARGET_OS_MACCATALYST ||\ @@ -78,6 +79,13 @@ else OSSpinLockUnlock(&lock##_deprecated); #define SD_SEL_SPI(name) NSSelectorFromString([NSString stringWithFormat:@"_%@", SD_NSSTRING(name)]) #endif +extern os_log_t sd_getDefaultLog(void); + +#ifndef SD_LOG +#define SD_LOG(_log, ...) if (@available(iOS 10.0, tvOS 10.0, macOS 10.12, watchOS 3.0, *)) os_log(sd_getDefaultLog(), _log, ##__VA_ARGS__); \ +else NSLog(@(_log), ##__VA_ARGS__); +#endif + #ifndef weakify #define weakify(...) \ sd_keywordify \ diff --git a/SDWebImage/Private/SDInternalMacros.m b/SDWebImage/Private/SDInternalMacros.m index e4981af2..939ba705 100644 --- a/SDWebImage/Private/SDInternalMacros.m +++ b/SDWebImage/Private/SDInternalMacros.m @@ -8,6 +8,15 @@ #import "SDInternalMacros.h" +os_log_t sd_getDefaultLog(void) { + static dispatch_once_t onceToken; + static os_log_t log; + dispatch_once(&onceToken, ^{ + log = os_log_create("com.hackemist.SDWebImage", "Default"); + }); + return log; +} + void sd_executeCleanupBlock (__strong sd_cleanupBlock_t *block) { (*block)(); }