Add some additional log messages to track down a tvdb issue.

This commit is contained in:
Damiano Galassi committed 2017-05-31 09:38:46 +02:00
1 parent 7721818507
commit 3d285f692f
5 files changed
+51 -14

No files matched your search

@@ -7,6 +7,7 @@
//
#import <Foundation/Foundation.h>
#import <MP42Foundation/MP42Logging.h>
NS_ASSUME_NONNULL_BEGIN
@@ -22,6 +23,8 @@ typedef NS_ENUM(NSUInteger, SBCachePolicy) {
+ (nullable NSDictionary<NSString *, NSString *> *)parseFilename:(NSString *)filename;
+ (NSString *)urlEncoded:(NSString *)string;
@property (class) id<MP42Logging> logger;
+ (nullable NSData *)downloadDataFromURL:(NSURL *)url cachePolicy:(SBCachePolicy)policy;
+ (nullable NSData *)downloadDataFromURL:(NSURL *)url HTTPMethod:(NSString *)method HTTPBody:(nullable NSData *)body headerOptions:(nullable NSDictionary *)header cachePolicy:(SBCachePolicy)policy;
+ (NSURLSessionTask *)sessionTaskFromUrl:(NSURL *)url HTTPMethod:(NSString *)method HTTPBody:(nullable NSData *)body headerOptions:(nullable NSDictionary *)header cachePolicy:(NSURLRequestCachePolicy)cachePolicy completionHandler:(void(^)(NSData * _Nullable data))completionHandler;
@@ -9,8 +9,20 @@
#import "SBMetadataHelper.h"
#import <CommonCrypto/CommonDigest.h>
static id<MP42Logging> _logger;
@implementation SBMetadataHelper
+ (void)setLogger:(id<MP42Logging>)logger
{
_logger = logger;
}
+ (id<MP42Logging>)logger
{
return _logger;
}
+ (nullable NSDictionary<NSString *, NSString *> *)parseFilename:(NSString *)filename
{
NSParameterAssert(filename);
@@ -195,8 +207,11 @@
request.HTTPBody = body;
}
[_logger writeToLog:[NSString stringWithFormat:@"Requesting URL %@", url.absoluteString]];
NSURLSession *defaultSession = [NSURLSession sharedSession];
NSURLSessionTask *task = [defaultSession dataTaskWithRequest:request completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
if (data) {
NSUInteger statusCode = 0;
if ([response isKindOfClass:[NSHTTPURLResponse class]]) {
@@ -207,9 +222,17 @@
completionHandler(data);
}
else {
NSString *errorData = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
if (errorData) {
[_logger writeToLog:errorData];
}
completionHandler(nil);
}
}
if (error) {
[_logger writeErrorToLog:error];
}
}];
return task;
+3 -2
View File
@@ -12,6 +12,7 @@
#import "SBQueueController.h"
#import "SBPrefsController.h"
#import "SBLogWindowController.h"
#import "SBMetadataHelper.h"
#import "SBLogger.h"
#import <MP42Foundation/MP42File.h>
@@ -49,8 +50,8 @@
[logger clearLog];
debugLogController = [[SBLogWindowController alloc] initWithLogger:logger];
[MP42File setGlobalLogger:logger];
MP42File.globalLogger = logger;
SBMetadataHelper.logger = logger;
if ([[NSUserDefaults standardUserDefaults] boolForKey:@"SBShowQueueWindow"]) {
[[SBQueueController sharedManager] showWindow:self];
+1 -1
View File
@@ -41,7 +41,7 @@
- (void)writeToLog:(NSString *)string {
dispatch_async(dispatch_get_main_queue(), ^{
NSAttributedString *attributedString = [[NSAttributedString alloc] initWithString:string];
[(self.logView).textStorage appendAttributedString:attributedString];
[self.logView.textStorage appendAttributedString:attributedString];
});
}
+21 -11
View File
@@ -12,6 +12,7 @@
@interface SBLogger ()
@property (nonatomic, readonly) NSURL *fileURL;
@property (nonatomic, readonly) dispatch_queue_t queue;
@end
@@ -22,6 +23,7 @@
if (self) {
_fileURL = [fileURL copy];
_queue = dispatch_queue_create("org.subler.LogQueue", DISPATCH_QUEUE_SERIAL);
}
return self;
@@ -38,22 +40,30 @@
}
- (void)writeToLog:(NSString *)string {
if (self.fileURL) {
FILE *f = fopen(self.fileURL.fileSystemRepresentation, "a");
if (f) {
fprintf(f, "%s %s", [self currentTime].UTF8String, string.UTF8String);
fclose(f);
dispatch_sync(self.queue, ^{
if (self.fileURL) {
FILE *f = fopen(self.fileURL.fileSystemRepresentation, "a");
if (f) {
fprintf(f, "%s %s", [self currentTime].UTF8String, string.UTF8String);
fprintf(f, "\n");
fclose(f);
}
}
}
if (self.delegate) {
[self.delegate writeToLog:[NSString stringWithFormat:@"%@ %@", [self currentTime], string]];
}
if (self.delegate) {
[self.delegate writeToLog:[NSString stringWithFormat:@"%@ %@", [self currentTime], string]];
[self.delegate writeToLog:@"\n"];
}
});
}
- (void)writeErrorToLog:(NSError *)error {
[self writeToLog:[NSString stringWithFormat:@"%@\n", error.localizedDescription]];
[self writeToLog:[NSString stringWithFormat:@"%@\n", error.localizedRecoverySuggestion]];
if (error.localizedDescription) {
[self writeToLog:error.localizedDescription];
}
if (error.localizedRecoverySuggestion) {
[self writeToLog:error.localizedRecoverySuggestion];
}
}
- (void)clearLog {