Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add nullability to Logger+ASL. #396

Merged
merged 1 commit into from
Mar 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions Foundation/GTMLogger+ASL.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
#import <asl.h>
#import "GTMLogger.h"

NS_ASSUME_NONNULL_BEGIN

// GTMLogger (GTMLoggerASLAdditions)
//
// Adds a convenience creation method that allows you to get a standard
Expand Down Expand Up @@ -62,15 +64,15 @@
// Returns an autoreleased GTMLogASLWriter instance that uses an instance of
// GTMLoggerASLClient and the supplied facility. See asl_open(3) for a
// discusssion of ASL facility strings.
+ (instancetype)aslWriterWithFacility:(NSString *)facility;
+ (instancetype)aslWriterWithFacility:(nullable NSString *)facility;

// Designated initializer. Uses instances of the specified |clientClass| to talk
// to the ASL system. All logs from this method will use |facility| as the ASL
// log facility. This method is typically only useful for testing. Users
// should generally NOT use this method to get an instance. Instead, simply use
// the +aslWriter or +aslWriterWithFacility: methods to obtain an instance.
- (instancetype)initWithClientClass:(Class)clientClass
facility:(NSString *)facility;
facility:(nullable NSString *)facility;

@end // GTMLogASLWriter

Expand All @@ -96,10 +98,13 @@
aslmsg msgOptions_;
}

// Designated initializer, |facility| is supplied to asl_open().
- (instancetype)initWithFacility:(NSString *)facility;
// Designated initializer, |facility| is supplied to asl_open(). Can fail
// if asl_open fails.
- (nullable instancetype)initWithFacility:(nullable NSString *)facility;

// Sends the given string to ASL at the specified ASL log |level|.
- (void)log:(NSString *)msg level:(int)level;

@end

NS_ASSUME_NONNULL_END
9 changes: 6 additions & 3 deletions Foundation/GTMLogger+ASL.m
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,18 @@ + (instancetype)standardLoggerWithASL {
@implementation GTMLogASLWriter

+ (instancetype)aslWriter {
return [[[self alloc] initWithClientClass:nil facility:nil] autorelease];
return [[[self alloc] initWithClientClass:[GTMLoggerASLClient class]
facility:nil] autorelease];
}

+ (instancetype)aslWriterWithFacility:(NSString *)facility {
return [[[self alloc] initWithClientClass:nil facility:facility] autorelease];
return [[[self alloc] initWithClientClass:[GTMLoggerASLClient class]
facility:facility] autorelease];
}

- (instancetype)init {
return [self initWithClientClass:nil facility:nil];
return [self initWithClientClass:[GTMLoggerASLClient class]
facility:nil];
}

- (instancetype)initWithClientClass:(Class)clientClass
Expand Down