CocoaLumberjack是一个功能丰富的第三方日志系统。其生成的log文件,默认是自动命名的,如果需要自定义文件名,重载两个函数即可。
// 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