CocoaLumberjack是一個功能豐富的第三方日誌系統。其生成的log文件,默認是自動命名的,若是須要自定義文件名,重載兩個函數便可。ide
// Log.h
#import "CocoaLumberjack.h" @interface CustomLogFileManager : DDLogFileManagerDefault - (instancetype)initWithLogsDirectory:(NSString *)logsDirectory fileName:(NSString *)name; @end
// Log.m
#import <Foundation/Foundation.h> #import "Log.h" @interface CustomLogFileManager () @property (nonatomic, copy) NSString *fileName; @end @implementation CustomLogFileManager #pragma mark - Lifecycle method - (instancetype)initWithLogsDirectory:(NSString *)logsDirectory fileName:(NSString *)name { self = [super initWithLogsDirectory:logsDirectory]; if (self) { self.fileName = name; } return self; } #pragma mark - Override methods - (NSString *)newLogFileName { return [NSString stringWithFormat:@"%@", self.fileName]; } - (BOOL)isLogFile:(NSString *)fileName { return [fileName isEqualToString:self.fileName]; } @end