I am trying to change the logfile name. What i've found so far is this.
My subclass of DDLogFileManagerDefault looks like this:
LogFileManager.h
@import CocoaLumberjack;
// this import would work as well
// #import <CocoaLumberjack/CocoaLumberjack.h>
// but none of these
//#import "DDLog.h"
//#import "DDTTYLogger.h"
//#import "DDASLLogger.h"
//#import "DDFileLogger.h"
@interface LogFileManager : DDLogFileManagerDefault
@end
LogFileManager.m
#import "LogFileManager.h"
@implementation LogFileManager
- (NSString *)newLogFileName {
NSBundle *bundle = [NSBundle mainBundle];
NSDictionary *info = [bundle infoDictionary];
NSString *appName = [info objectForKey:@"CFBundleExecutable"];
NSString *timeStamp = [self getTimestamp];
return [NSString stringWithFormat:@"%@%@.log", appName, timeStamp];
}
- (BOOL)isLogFile:(NSString *)fileName {
return NO;
}
- (NSString *)getTimestamp {
static dispatch_once_t onceToken;
static NSDateFormatter *dateFormatter;
dispatch_once(&onceToken, ^{
dateFormatter = [NSDateFormatter new];
[dateFormatter setDateFormat:@"YYYY.MM.dd-HH.mm.ss"];
});
return [dateFormatter stringFromDate:NSDate.date];
}
@end
This is how I use it:
DDLogFileManagerDefault *documentsFileManager = [[LogFileManager alloc] init];
DDFileLogger *fileLogger = [[DDFileLogger alloc] initWithLogFileManager:documentsFileManager];
When I replace LogFileManager
with DDLogFileManagerDefault
it works fine. Otherwise I get:
Undefined symbols for architecture x86_64:
"_OBJC_CLASS_$_LogFileManager", referenced from: objc-class-ref in Logger.o ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation)
What exactly am I missing here?
CocoaLumberjack is added via Carthage 3.2.0 for Xcode 8.
I've added the CocoaLumberjack.framework
to the Build Phases like all the other frameworks in the project with /usr/local/bin/carthage copy-frameworks
Okay, I solved it. That error was very confusing but has nothing to do with anything. Sorry for that.
It is a big project with lots of build targets and lots of compile flags that make different things throw a warning and warnings become an error. In this case I added flags to disable the global ones to the mentioned Logger.m class. But I only added those anti-flags to one target and forgot to add them to another. That's why it didn't build.
Still strange, that the compiler didn't simply say: cannot build target A or compile error in file B. Instead I got a missing architecture message that was misleading me totally... So sorry for the trouble. Fixed it.