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;
#define ENV_LOG_YOUTUBE 1
// TODO: Make plugins extensible? community extensions.
@interface YouTubePlugin : NSObject
+ (NSString*)feedURL:(NSURL*)url;

View File

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

View File

@@ -168,7 +168,7 @@
NSURL *path = self.fileURL;
NSImage *img = [[NSImage alloc] initByReferencingURL:path];
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(" ↳ %s\n", path.absoluteString.UTF8String);
#endif

View File

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

View File

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

View File

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

View File

@@ -22,6 +22,8 @@
@import Cocoa;
#define ENV_LOG_DOWNLOAD 1
@interface NSURLRequest (Ext)
+ (instancetype)withURL:(NSString*)urlStr;
- (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) {
NSHTTPURLResponse* httpResponse = (NSHTTPURLResponse*)response;
NSInteger status = [httpResponse statusCode];
#ifdef DEBUG
#if DEBUG && ENV_LOG_DOWNLOAD
/*if (status != 304)*/ printf("GET %ld %s\n", status, self.URL.absoluteString.UTF8String);
#endif
if (error || status == 304) {