Easy access macro to disable logging

This commit is contained in:
relikd
2019-09-25 21:19:21 +02:00
parent aa87d1be6a
commit 23b5bba794
8 changed files with 14 additions and 8 deletions

View File

@@ -22,6 +22,8 @@
@import Cocoa; @import Cocoa;
#define ENV_LOG_YOUTUBE 1
// TODO: Make plugins extensible? community extensions. // TODO: Make plugins extensible? community extensions.
@interface YouTubePlugin : NSObject @interface YouTubePlugin : NSObject
+ (NSString*)feedURL:(NSURL*)url; + (NSString*)feedURL:(NSURL*)url;

View File

@@ -39,7 +39,7 @@
// https://www.youtube.com/channel/[channel-id] // https://www.youtube.com/channel/[channel-id]
// https://www.youtube.com/user/[user-name] // https://www.youtube.com/user/[user-name]
// https://www.youtube.com/playlist?list=[playlist-id] // https://www.youtube.com/playlist?list=[playlist-id]
#ifdef DEBUG #if DEBUG && ENV_LOG_YOUTUBE
printf("resolving YouTube url:\n"); printf("resolving YouTube url:\n");
printf(" ↳ %s\n", url.absoluteString.UTF8String); printf(" ↳ %s\n", url.absoluteString.UTF8String);
#endif #endif
@@ -64,7 +64,7 @@
} }
} }
} }
#ifdef DEBUG #if DEBUG && ENV_LOG_YOUTUBE
printf(" ↳ %s\n", found ? found.UTF8String : "could not resolve!"); printf(" ↳ %s\n", found ? found.UTF8String : "could not resolve!");
#endif #endif
return found; // may be nil return found; // may be nil

View File

@@ -168,7 +168,7 @@
NSURL *path = self.fileURL; NSURL *path = self.fileURL;
NSImage *img = [[NSImage alloc] initByReferencingURL:path]; NSImage *img = [[NSImage alloc] initByReferencingURL:path];
if (!img.valid) { path = nil; img = nil; } if (!img.valid) { path = nil; img = nil; }
#ifdef DEBUG #if DEBUG && ENV_LOG_DOWNLOAD
printf("ICON %1.0fx%1.0f %s\n", img.size.width, img.size.height, self.remoteURL.absoluteString.UTF8String); printf("ICON %1.0fx%1.0f %s\n", img.size.width, img.size.height, self.remoteURL.absoluteString.UTF8String);
printf(" ↳ %s\n", path.absoluteString.UTF8String); printf(" ↳ %s\n", path.absoluteString.UTF8String);
#endif #endif

View File

@@ -70,7 +70,7 @@
</dict> </dict>
</array> </array>
<key>CFBundleVersion</key> <key>CFBundleVersion</key>
<string>13702</string> <string>13723</string>
<key>LSApplicationCategoryType</key> <key>LSApplicationCategoryType</key>
<string>public.app-category.news</string> <string>public.app-category.news</string>
<key>LSMinimumSystemVersion</key> <key>LSMinimumSystemVersion</key>

View File

@@ -22,6 +22,8 @@
@import Cocoa; @import Cocoa;
#define ENV_LOG_FILES 0
@interface NSURL (Ext) @interface NSURL (Ext)
// Generators // Generators
+ (NSURL*)applicationSupportURL; + (NSURL*)applicationSupportURL;

View File

@@ -89,11 +89,11 @@
/// Delete file or folder at URL. If item does not exist, this method does nothing. /// Delete file or folder at URL. If item does not exist, this method does nothing.
- (void)remove { - (void)remove {
#ifdef DEBUG #if DEBUG && ENV_LOG_FILES
BOOL success = BOOL success =
#endif #endif
[[NSFileManager defaultManager] removeItemAtURL:self error:nil]; [[NSFileManager defaultManager] removeItemAtURL:self error:nil];
#ifdef DEBUG #if DEBUG && ENV_LOG_FILES
if (success) printf("DEL %s\n", self.absoluteString.UTF8String); if (success) printf("DEL %s\n", self.absoluteString.UTF8String);
#endif #endif
} }
@@ -102,7 +102,7 @@
- (void)moveTo:(NSURL*)destination { - (void)moveTo:(NSURL*)destination {
[[NSFileManager defaultManager] removeItemAtURL:destination error:nil]; [[NSFileManager defaultManager] removeItemAtURL:destination error:nil];
[[NSFileManager defaultManager] moveItemAtURL:self toURL:destination error:nil]; [[NSFileManager defaultManager] moveItemAtURL:self toURL:destination error:nil];
#ifdef DEBUG #if DEBUG && ENV_LOG_FILES
printf("MOVE %s\n", self.absoluteString.UTF8String); printf("MOVE %s\n", self.absoluteString.UTF8String);
printf(" ↳ %s\n", destination.absoluteString.UTF8String); printf(" ↳ %s\n", destination.absoluteString.UTF8String);
#endif #endif

View File

@@ -22,6 +22,8 @@
@import Cocoa; @import Cocoa;
#define ENV_LOG_DOWNLOAD 1
@interface NSURLRequest (Ext) @interface NSURLRequest (Ext)
+ (instancetype)withURL:(NSString*)urlStr; + (instancetype)withURL:(NSString*)urlStr;
- (NSURLSessionDataTask*)dataTask:(nonnull void(^)(NSData * _Nullable data, NSError * _Nullable error, NSHTTPURLResponse *response))block; - (NSURLSessionDataTask*)dataTask:(nonnull void(^)(NSData * _Nullable data, NSError * _Nullable error, NSHTTPURLResponse *response))block;

View File

@@ -58,7 +58,7 @@ static NSURLSession* NonCachingURLSession(void) {
NSURLSessionDataTask *task = [NonCachingURLSession() dataTaskWithRequest:self completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) { NSURLSessionDataTask *task = [NonCachingURLSession() dataTaskWithRequest:self completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
NSHTTPURLResponse* httpResponse = (NSHTTPURLResponse*)response; NSHTTPURLResponse* httpResponse = (NSHTTPURLResponse*)response;
NSInteger status = [httpResponse statusCode]; NSInteger status = [httpResponse statusCode];
#ifdef DEBUG #if DEBUG && ENV_LOG_DOWNLOAD
/*if (status != 304)*/ printf("GET %ld %s\n", status, self.URL.absoluteString.UTF8String); /*if (status != 304)*/ printf("GET %ld %s\n", status, self.URL.absoluteString.UTF8String);
#endif #endif
if (error || status == 304) { if (error || status == 304) {