Skip to content

Commit e82a4cd

Browse files
committed
Add the ability to modify the default format block
1 parent 3197a89 commit e82a4cd

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

SuperLogger/SLLoggerController.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ NS_ASSUME_NONNULL_BEGIN
3737
/**
3838
* The default format block that will be used if a logger's format block is nil
3939
*/
40-
@property (copy, nonatomic, readonly) SLLogFormatBlock defaultFormatBlock;
40+
@property (copy, nonatomic) SLLogFormatBlock defaultFormatBlock;
4141

4242
/**
4343
* Whether or not non-error logs will be dispatched asynchronously.

SuperLogger/SLLoggerController.m

+18-5
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ @interface SLLoggerController ()
2525

2626
@implementation SLLoggerController
2727

28+
@synthesize defaultFormatBlock = _defaultFormatBlock;
29+
2830
#pragma mark - Lifecycle
2931

3032
+ (SLLoggerController *)sharedController {
@@ -50,6 +52,7 @@ - (instancetype)init {
5052
_async = YES;
5153
_errorAsync = NO;
5254
_globalLogLevel = SLLogLevelDebug;
55+
_defaultFormatBlock = nil;
5356

5457
return self;
5558
}
@@ -127,11 +130,21 @@ + (SLLogLevel)logLevelForFile:(NSString *)file {
127130
#pragma mark - Getters / Setters
128131

129132
- (SLLogFormatBlock)defaultFormatBlock {
130-
return ^NSString * (SLLog *log) {
131-
NSString *callerClass = log.fileName;
132-
NSString *callerFunction = log.functionName;
133-
return [NSString stringWithFormat:@"(%@:%@)[%@ %@] %@", log.queueLabel, log.timestamp, callerClass, callerFunction, log.message];
134-
};
133+
if (_defaultFormatBlock != nil) {
134+
return _defaultFormatBlock;
135+
} else {
136+
return [^NSString * (SLLog *log) {
137+
NSString *callerClass = log.fileName;
138+
NSString *callerFunction = log.functionName;
139+
return [NSString stringWithFormat:@"(%@:%@)[%@ %@] %@", log.queueLabel, log.timestamp, callerClass, callerFunction, log.message];
140+
} copy];
141+
}
142+
}
143+
144+
- (void)setDefaultFormatBlock:(SLLogFormatBlock)defaultFormatBlock {
145+
dispatch_async([self.class globalLogQueue], ^{
146+
_defaultFormatBlock = defaultFormatBlock;
147+
});
135148
}
136149

137150

0 commit comments

Comments
 (0)