Skip to content

Commit

Permalink
Change designated initializer on DDOSLogger after version bump
Browse files Browse the repository at this point in the history
  • Loading branch information
ffried committed May 10, 2024
1 parent dc28b52 commit c7e5817
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 26 deletions.
25 changes: 13 additions & 12 deletions Sources/CocoaLumberjack/DDOSLogger.m
Original file line number Diff line number Diff line change
Expand Up @@ -84,30 +84,31 @@ + (instancetype)sharedInstance {
}

#pragma mark - Initialization
- (instancetype)initWithSubsystem:(NSString *)subsystem category:(NSString *)category {
NSAssert((subsystem == nil) == (category == nil),
- (instancetype)initWithSubsystem:(NSString *)subsystem
category:(NSString *)category
logLevelMapper:(id<DDOSLogLevelMapper>)logLevelMapper {
NSAssert((subsystem == nil) == (category == nil),
@"Either both subsystem and category or neither should be nil.");
NSParameterAssert(logLevelMapper);
if (self = [super init]) {
_subsystem = [subsystem copy];
_category = [category copy];
_logLevelMapper = [[DDOSLogLevelMapperDefault alloc] init];
_logLevelMapper = logLevelMapper;
}
return self;
}

- (instancetype)initWithSubsystem:(NSString *)subsystem category:(NSString *)category {
return [self initWithSubsystem:subsystem
category:category
logLevelMapper:[[DDOSLogLevelMapperDefault alloc] init]];
}

- (instancetype)init {
return [self initWithSubsystem:nil category:nil];
}

- (instancetype)initWithSubsystem:(NSString *)subsystem
category:(NSString *)category
logLevelMapper:(id<DDOSLogLevelMapper>)logLevelMapper {
if (self = [self initWithSubsystem:subsystem category:category]) {
NSParameterAssert(logLevelMapper);
_logLevelMapper = logLevelMapper;
}
return self;
}


- (instancetype)initWithLogLevelMapper:(id<DDOSLogLevelMapper>)logLevelMapper {
return [self initWithSubsystem:nil category:nil logLevelMapper:logLevelMapper];
Expand Down
27 changes: 13 additions & 14 deletions Sources/CocoaLumberjack/include/CocoaLumberjack/DDOSLogger.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,18 +73,6 @@ DD_SENDABLE
/// The log level mapper, that maps ``DDLogFlag``s to ``os_log_type_t`` for this logger.
@property (nonatomic, strong, readonly) id<DDOSLogLevelMapper> logLevelMapper;

/// The designated initializer, using `DDOSLogLevelMapperDefault`.
/// @param subsystem Desired subsystem in log. E.g. "org.example"
/// @param category Desired category in log. E.g. "Point of interests."
/// @discussion This method requires either both or no parameter to be set. Much like `(String, String)?` in Swift.
/// If both parameters are nil, this method will return a logger configured with `OS_LOG_DEFAULT`.
/// If both parameters are non-nil, it will return a logger configured with `os_log_create(subsystem, category)`.
- (instancetype)initWithSubsystem:(nullable NSString *)subsystem
category:(nullable NSString *)category NS_DESIGNATED_INITIALIZER;

/// Creates an instance that uses `OS_LOG_DEFAULT` and `DDOSLogLevelMapperDefault`.
- (instancetype)init;

/// An initializer that in addition to subsystem and category also allows providing the log level mapper.
/// @param subsystem Desired subsystem in log. E.g. "org.example"
/// @param category Desired category in log. E.g. "Point of interests."
Expand All @@ -94,13 +82,24 @@ DD_SENDABLE
/// If both parameters are non-nil, it will return a logger configured with `os_log_create(subsystem, category)`
- (instancetype)initWithSubsystem:(nullable NSString *)subsystem
category:(nullable NSString *)category
logLevelMapper:(id<DDOSLogLevelMapper>)logLevelMapper;
// FIXME: This should actually be the designated initializer, but that would be a breaking change. Adjust in next version bump.
logLevelMapper:(id<DDOSLogLevelMapper>)logLevelMapper NS_DESIGNATED_INITIALIZER;

/// The designated initializer, using `DDOSLogLevelMapperDefault`.
/// @param subsystem Desired subsystem in log. E.g. "org.example"
/// @param category Desired category in log. E.g. "Point of interests."
/// @discussion This method requires either both or no parameter to be set. Much like `(String, String)?` in Swift.
/// If both parameters are nil, this method will return a logger configured with `OS_LOG_DEFAULT`.
/// If both parameters are non-nil, it will return a logger configured with `os_log_create(subsystem, category)`.
- (instancetype)initWithSubsystem:(nullable NSString *)subsystem
category:(nullable NSString *)category;

/// Creates an instance that uses `OS_LOG_DEFAULT`.
/// @param logLevelMapper The log level mapper to use.
- (instancetype)initWithLogLevelMapper:(id<DDOSLogLevelMapper>)logLevelMapper;

/// Creates an instance that uses `OS_LOG_DEFAULT` and `DDOSLogLevelMapperDefault`.
- (instancetype)init;

@end

NS_ASSUME_NONNULL_END

0 comments on commit c7e5817

Please sign in to comment.