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

Remove deprecated logger APIs and update Changelog #202

Merged
merged 1 commit into from
Jul 11, 2024
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
- `- [GULKeychainStorage getObjectForKey:objectClass:accessGroup:]`
- `- [GULKeychainStorage setObject:forKey:accessGroup:]`
- `- [GULKeychainStorage removeObjectForKey:accessGroup:]`
- Update underlying GULLogger implementation from `asl` to `os_log`.
- Remove `GULLoggerEnableSTDERR` API.

# 7.13.3
- Rename parameter placeholder in `GULSecureCoding` unarchiving API to avoid
Expand Down
40 changes: 0 additions & 40 deletions GoogleUtilities/Logger/GULLogger.m
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,6 @@ void GULLoggerInitialize(void) {
});
}

void GULLoggerInitializeASL(void) {
GULLoggerInitialize();
}

void GULLoggerEnableSTDERR(void) {
// No-op
}

void GULLoggerForceDebug(void) {
// We should enable debug mode if we're not running from App Store.
if (![GULAppEnvironmentUtil isFromAppStore]) {
Expand Down Expand Up @@ -180,38 +172,6 @@ void GULOSLogBasic(GULLoggerLevel level,
});
}

void GULLogBasic(GULLoggerLevel level,
GULLoggerService service,
BOOL forceLog,
NSString *messageCode,
NSString *message,
va_list args_ptr) {
GULOSLogBasic(level, kGULLogSubsystem, service, forceLog, messageCode, message, args_ptr);
}

/**
* Generates the logging functions using macros.
*
* Calling GULLogError({service}, @"I-XYZ000001", @"Configure %@ failed.", @"blah") shows:
* yyyy-mm-dd hh:mm:ss.SSS sender[PID] <Error> [{service}][I-XYZ000001] Configure blah failed.
* Calling GULLogDebug({service}, @"I-XYZ000001", @"Configure succeed.") shows:
* yyyy-mm-dd hh:mm:ss.SSS sender[PID] <Debug> [{service}][I-XYZ000001] Configure succeed.
*/
#define GUL_LOGGING_FUNCTION(level) \
void GULLog##level(GULLoggerService service, BOOL force, NSString *messageCode, \
NSString *message, ...) { \
va_list args_ptr; \
va_start(args_ptr, message); \
GULLogBasic(GULLoggerLevel##level, service, force, messageCode, message, args_ptr); \
va_end(args_ptr); \
}

GUL_LOGGING_FUNCTION(Error)
GUL_LOGGING_FUNCTION(Warning)
GUL_LOGGING_FUNCTION(Notice)
GUL_LOGGING_FUNCTION(Info)
GUL_LOGGING_FUNCTION(Debug)

#undef GUL_LOGGING_FUNCTION

/**
Expand Down
94 changes: 1 addition & 93 deletions GoogleUtilities/Logger/Public/GoogleUtilities/GULLogger.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,27 +31,15 @@ typedef NSString *const GULLoggerService;
extern "C" {
#endif // __cplusplus

/// DEPRECATED; provide a relevant subsystem name rather than using default.
/// Used for other GoogleUtilities logging.
extern NSString *const kGULLogSubsystem;

/// Initialize GULLogger.
extern void GULLoggerInitialize(void);

/// Initialize GULLogger.
///
/// The Apple System Log (ASL) in Google Utilities Logger has been replaced by OSLog.
///
/// DEPRECATED; simply calls its replacement `GULLoggerInitialize`.
extern void GULLoggerInitializeASL(void);

/// Override log level to Debug.
void GULLoggerForceDebug(void);

/// Turn on logging to STDERR.
///
/// DEPRECATED; this function is a no-op.
extern void GULLoggerEnableSTDERR(void);

/// Gets the current `GULLoggerLevel`.
extern GULLoggerLevel GULGetLoggerLevel(void);

Expand Down Expand Up @@ -102,66 +90,6 @@ extern void GULOSLogBasic(GULLoggerLevel level,
#endif
);

/**
* Logs a message to the Xcode console and the device log. If running from AppStore, will
* not log any messages with a level higher than GULLoggerLevelNotice to avoid log spamming.
* (required) log level (one of the GULLoggerLevel enum values).
* (required) service name of type GULLoggerService.
* (required) message code starting with "I-" which means iOS, followed by a capitalized
* three-character service identifier and a six digit integer message ID that is unique
* within the service.
* An example of the message code is @"I-COR000001".
* (required) message string which can be a format string.
* (optional) variable arguments list obtained from calling va_start, used when message is a format
* string.
*
* DEPRECATED; replaced by `GULOSLogBasic`.
*/
extern void GULLogBasic(GULLoggerLevel level,
GULLoggerService service,
BOOL forceLog,
NSString *messageCode,
NSString *message,
// On 64-bit simulators, va_list is not a pointer, so cannot be marked nullable
// See: http://stackoverflow.com/q/29095469
#if __LP64__ && TARGET_OS_SIMULATOR || TARGET_OS_OSX
va_list args_ptr
#else
va_list _Nullable args_ptr
#endif
);

/**
* The following functions accept the following parameters in order:
* (required) service name of type GULLoggerService.
* (required) message code starting from "I-" which means iOS, followed by a capitalized
* three-character service identifier and a six digit integer message ID that is unique
* within the service.
* An example of the message code is @"I-COR000001".
* See go/firebase-log-proposal for details.
* (required) message string which can be a format string.
* (optional) the list of arguments to substitute into the format string.
* Example usage:
* GULLogError(kGULLoggerCore, @"I-COR000001", @"Configuration of %@ failed.", app.name);
*
* DEPRECATED; replaced by `GULOSLogError`, `GULOSLogWarning`, etc.
*/
extern void GULLogError(
GULLoggerService service, BOOL force, NSString *messageCode, NSString *message, ...)
NS_FORMAT_FUNCTION(4, 5) DEPRECATED_MSG_ATTRIBUTE("Replaced by `GULOSLogError`.");
extern void GULLogWarning(
GULLoggerService service, BOOL force, NSString *messageCode, NSString *message, ...)
NS_FORMAT_FUNCTION(4, 5) DEPRECATED_MSG_ATTRIBUTE("Replaced by `GULOSLogWarning`.");
extern void GULLogNotice(
GULLoggerService service, BOOL force, NSString *messageCode, NSString *message, ...)
NS_FORMAT_FUNCTION(4, 5) DEPRECATED_MSG_ATTRIBUTE("Replaced by `GULOSLogInfo`.");
extern void GULLogInfo(
GULLoggerService service, BOOL force, NSString *messageCode, NSString *message, ...)
NS_FORMAT_FUNCTION(4, 5) DEPRECATED_MSG_ATTRIBUTE("Replaced by `GULOSLogInfo`.");
extern void GULLogDebug(
GULLoggerService service, BOOL force, NSString *messageCode, NSString *message, ...)
NS_FORMAT_FUNCTION(4, 5) DEPRECATED_MSG_ATTRIBUTE("Replaced by `GULOSLogDebug`.");
Comment on lines -151 to -163
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just as a reminder, when you move these functions to a new file internally, these were the ones I forget to remove the DEPRECATED_MSG_ATTRIBUTE from.


/**
* The following functions accept the following parameters in order:
* (required) service name of type GULLoggerService.
Expand Down Expand Up @@ -232,26 +160,6 @@ extern void GULOSLogDebug(NSString *subsystem,
message:(NSString *)message
arguments:(va_list)args;

/**
* Objective-C wrapper for GULLogBasic to allow weak linking to GULLogger
* (required) log level (one of the GULLoggerLevel enum values).
* (required) service name of type GULLoggerService.
* (required) message code starting with "I-" which means iOS, followed by a capitalized
* three-character service identifier and a six digit integer message ID that is unique
* within the service.
* An example of the message code is @"I-COR000001".
* (required) message string which can be a format string.
* (optional) variable arguments list obtained from calling va_start, used when message is a format
* string.
*
* DEPRECATED; replaced by `logWithLevel:subsystem:category:messageCode:message:arguments:`.
*/
+ (void)logWithLevel:(GULLoggerLevel)level
withService:(GULLoggerService)service
withCode:(NSString *)messageCode
withMessage:(NSString *)message
withArgs:(va_list)args;

@end

NS_ASSUME_NONNULL_END
59 changes: 0 additions & 59 deletions GoogleUtilities/Tests/Unit/Logger/GULLoggerTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -140,64 +140,5 @@ - (void)testGULResetLogger_ResetsLoggerLevel {
XCTAssertEqual(loggerLevel, GULLoggerLevelNotice);
}

#pragma mark - Deprecated Functions

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"

- (void)testDeprecatedInitializeASL {
XCTAssertNoThrow(GULLoggerInitializeASL());
}

- (void)testDeprecatedEnableSTDERR {
XCTAssertNoThrow(GULLoggerEnableSTDERR());
}

- (void)testDeprecatedMessageCodeFormat {
// Valid case.
XCTAssertNoThrow(GULLogError(@"my service", NO, @"I-APP000001", @"Message."));

// An extra dash or missing dash should fail.
XCTAssertThrows(GULLogError(@"my service", NO, @"I-APP-000001", @"Message."));
XCTAssertThrows(GULLogError(@"my service", NO, @"IAPP000001", @"Message."));

// Wrong number of digits should fail.
XCTAssertThrows(GULLogError(@"my service", NO, @"I-APP00001", @"Message."));
XCTAssertThrows(GULLogError(@"my service", NO, @"I-APP0000001", @"Message."));

// Lowercase should fail.
XCTAssertThrows(GULLogError(@"my service", NO, @"I-app000001", @"Message."));

// nil or empty message code should fail.
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wnonnull"
XCTAssertThrows(GULLogError(@"my service", NO, nil, @"Message."));
#pragma clang diagnostic pop

XCTAssertThrows(GULLogError(@"my service", NO, @"", @"Message."));

// Android message code should fail.
XCTAssertThrows(GULLogError(@"my service", NO, @"A-APP000001", @"Message."));
}

- (void)testDeprecatedLoggerInterface {
XCTAssertNoThrow(GULLogError(@"my service", NO, kMessageCode, @"Message."));
XCTAssertNoThrow(GULLogError(@"my service", NO, kMessageCode, @"Configure %@.", @"blah"));

XCTAssertNoThrow(GULLogWarning(@"my service", NO, kMessageCode, @"Message."));
XCTAssertNoThrow(GULLogWarning(@"my service", NO, kMessageCode, @"Configure %@.", @"blah"));

XCTAssertNoThrow(GULLogNotice(@"my service", NO, kMessageCode, @"Message."));
XCTAssertNoThrow(GULLogNotice(@"my service", NO, kMessageCode, @"Configure %@.", @"blah"));

XCTAssertNoThrow(GULLogInfo(@"my service", NO, kMessageCode, @"Message."));
XCTAssertNoThrow(GULLogInfo(@"my service", NO, kMessageCode, @"Configure %@.", @"blah"));

XCTAssertNoThrow(GULLogDebug(@"my service", NO, kMessageCode, @"Message."));
XCTAssertNoThrow(GULLogDebug(@"my service", NO, kMessageCode, @"Configure %@.", @"blah"));
}

#pragma clang diagnostic pop

@end
#endif
Loading