diff --git a/FirebaseAppDistribution/Sources/FIRFADLogger.m b/FirebaseAppDistribution/Sources/FIRFADLogger.m index 5eb8b92acd1..d0141e7550c 100644 --- a/FirebaseAppDistribution/Sources/FIRFADLogger.m +++ b/FirebaseAppDistribution/Sources/FIRFADLogger.m @@ -14,7 +14,6 @@ #import "FirebaseAppDistribution/Sources/FIRFADLogger.h" #import "FirebaseCore/Extension/FIRLogger.h" -#import "FirebaseCore/Sources/Public/FirebaseCore/FIRLoggerLevel.h" FIRLoggerService kFIRLoggerAppDistribution = @"[FirebaseAppDistribution]"; @@ -23,31 +22,27 @@ void FIRFADDebugLog(NSString *message, ...) { va_list args_ptr; va_start(args_ptr, message); - FIRLogBasic(FIRLoggerLevelDebug, kFIRLoggerAppDistribution, AppDistributionMessageCode, message, - args_ptr); + FIRLogBasicDebug(kFIRLoggerAppDistribution, AppDistributionMessageCode, message, args_ptr); va_end(args_ptr); } void FIRFADInfoLog(NSString *message, ...) { va_list args_ptr; va_start(args_ptr, message); - FIRLogBasic(FIRLoggerLevelInfo, kFIRLoggerAppDistribution, AppDistributionMessageCode, message, - args_ptr); + FIRLogBasicInfo(kFIRLoggerAppDistribution, AppDistributionMessageCode, message, args_ptr); va_end(args_ptr); } void FIRFADWarningLog(NSString *message, ...) { va_list args_ptr; va_start(args_ptr, message); - FIRLogBasic(FIRLoggerLevelWarning, kFIRLoggerAppDistribution, AppDistributionMessageCode, message, - args_ptr); + FIRLogBasicWarning(kFIRLoggerAppDistribution, AppDistributionMessageCode, message, args_ptr); va_end(args_ptr); } void FIRFADErrorLog(NSString *message, ...) { va_list args_ptr; va_start(args_ptr, message); - FIRLogBasic(FIRLoggerLevelError, kFIRLoggerAppDistribution, AppDistributionMessageCode, message, - args_ptr); + FIRLogBasicError(kFIRLoggerAppDistribution, AppDistributionMessageCode, message, args_ptr); va_end(args_ptr); } diff --git a/FirebaseCore/Extension/FIRLogger.h b/FirebaseCore/Extension/FIRLogger.h index 95adea51e73..629b5c4bbef 100644 --- a/FirebaseCore/Extension/FIRLogger.h +++ b/FirebaseCore/Extension/FIRLogger.h @@ -64,6 +64,11 @@ FIRLoggerLevel FIRGetLoggerLevel(void); */ void FIRSetLoggerLevel(FIRLoggerLevel loggerLevel); +void FIRSetLoggerLevelNotice(void); +void FIRSetLoggerLevelWarning(void); +void FIRSetLoggerLevelError(void); +void FIRSetLoggerLevelDebug(void); + /** * Checks if the specified logger level is loggable given the current settings. * (required) log level (one of the FirebaseLoggerLevel enum values). @@ -71,6 +76,11 @@ void FIRSetLoggerLevel(FIRLoggerLevel loggerLevel); */ BOOL FIRIsLoggableLevel(FIRLoggerLevel loggerLevel, BOOL analyticsComponent); +BOOL FIRIsLoggableLevelNotice(void); +BOOL FIRIsLoggableLevelWarning(void); +BOOL FIRIsLoggableLevelError(void); +BOOL FIRIsLoggableLevelDebug(void); + /** * 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 FirebaseLoggerLevelNotice to avoid log spamming. @@ -121,6 +131,41 @@ extern void FIRLogInfo(NSString *category, NSString *messageCode, NSString *mess extern void FIRLogDebug(NSString *category, NSString *messageCode, NSString *message, ...) NS_FORMAT_FUNCTION(3, 4); +/** + * This function is similar to the one above, except it takes a `va_list` instead of the listed + * variables. + * + * The following functions accept the following parameters in order: (required) service + * name of type FirebaseLoggerService. + * + * (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) A va_list + */ +extern void FIRLogBasicError(NSString *category, + NSString *messageCode, + NSString *message, + va_list args_ptr); +extern void FIRLogBasicWarning(NSString *category, + NSString *messageCode, + NSString *message, + va_list args_ptr); +extern void FIRLogBasicNotice(NSString *category, + NSString *messageCode, + NSString *message, + va_list args_ptr); +extern void FIRLogBasicInfo(NSString *category, + NSString *messageCode, + NSString *message, + va_list args_ptr); +extern void FIRLogBasicDebug(NSString *category, + NSString *messageCode, + NSString *message, + va_list args_ptr); + #ifdef __cplusplus } // extern "C" #endif // __cplusplus diff --git a/FirebaseCore/Sources/FIRLogger.m b/FirebaseCore/Sources/FIRLogger.m index 382a3a921ec..17f54a9dbd1 100644 --- a/FirebaseCore/Sources/FIRLogger.m +++ b/FirebaseCore/Sources/FIRLogger.m @@ -95,6 +95,26 @@ void FIRSetLoggerLevel(FIRLoggerLevel loggerLevel) { GULSetLoggerLevel((GULLoggerLevel)loggerLevel); } +void FIRSetLoggerLevelNotice(void) { + FIRLoggerInitialize(); + GULSetLoggerLevel(GULLoggerLevelNotice); +} + +void FIRSetLoggerLevelWarning(void) { + FIRLoggerInitialize(); + GULSetLoggerLevel(GULLoggerLevelWarning); +} + +void FIRSetLoggerLevelError(void) { + FIRLoggerInitialize(); + GULSetLoggerLevel(GULLoggerLevelError); +} + +void FIRSetLoggerLevelDebug(void) { + FIRLoggerInitialize(); + GULSetLoggerLevel(GULLoggerLevelDebug); +} + #ifdef DEBUG void FIRResetLogger(void) { extern void GULResetLogger(void); @@ -124,6 +144,22 @@ void FIRSetLoggerUserDefaults(NSUserDefaults *defaults) { return GULIsLoggableLevel((GULLoggerLevel)loggerLevel); } +BOOL FIRIsLoggableLevelNotice(void) { + return FIRIsLoggableLevel(FIRLoggerLevelNotice, NO); +} + +BOOL FIRIsLoggableLevelWarning(void) { + return FIRIsLoggableLevel(FIRLoggerLevelWarning, NO); +} + +BOOL FIRIsLoggableLevelError(void) { + return FIRIsLoggableLevel(FIRLoggerLevelError, NO); +} + +BOOL FIRIsLoggableLevelDebug(void) { + return FIRIsLoggableLevel(FIRLoggerLevelDebug, NO); +} + void FIRLogBasic(FIRLoggerLevel level, NSString *category, NSString *messageCode, @@ -135,6 +171,18 @@ void FIRLogBasic(FIRLoggerLevel level, messageCode, message, args_ptr); } +#define FIR_LOGGING_FUNCTION_BASIC(level) \ + void FIRLogBasic##level(NSString *category, NSString *messageCode, NSString *message, \ + va_list args_ptr) { \ + FIRLogBasic(FIRLoggerLevel##level, category, messageCode, message, args_ptr); \ + } + +FIR_LOGGING_FUNCTION_BASIC(Error) +FIR_LOGGING_FUNCTION_BASIC(Warning) +FIR_LOGGING_FUNCTION_BASIC(Notice) +FIR_LOGGING_FUNCTION_BASIC(Info) +FIR_LOGGING_FUNCTION_BASIC(Debug) + /** * Generates the logging functions using macros. * diff --git a/Firestore/Source/API/FSTFirestoreComponent.mm b/Firestore/Source/API/FSTFirestoreComponent.mm index ff6e89eadb0..d07ac36f899 100644 --- a/Firestore/Source/API/FSTFirestoreComponent.mm +++ b/Firestore/Source/API/FSTFirestoreComponent.mm @@ -28,7 +28,7 @@ #import "FirebaseCore/Extension/FIRComponentContainer.h" #import "FirebaseCore/Extension/FIRComponentType.h" #import "FirebaseCore/Extension/FIRLibrary.h" -#import "FirebaseCore/Sources/Public/FirebaseCore/FIROptions.h" +#import "FirebaseCore/Sources/FIROptionsInternal.h" #import "Firestore/Source/API/FIRFirestore+Internal.h" #include "Firestore/core/include/firebase/firestore/firestore_version.h" diff --git a/Firestore/core/src/remote/firebase_metadata_provider_apple.mm b/Firestore/core/src/remote/firebase_metadata_provider_apple.mm index ea2a4c982b3..a2c7e287bd6 100644 --- a/Firestore/core/src/remote/firebase_metadata_provider_apple.mm +++ b/Firestore/core/src/remote/firebase_metadata_provider_apple.mm @@ -18,7 +18,7 @@ #import "FirebaseCore/Extension/FIRAppInternal.h" #import "FirebaseCore/Extension/FIRHeartbeatLogger.h" -#import "FirebaseCore/Sources/Public/FirebaseCore/FIROptions.h" +#import "FirebaseCore/Sources/FIROptionsInternal.h" #include "Firestore/core/src/util/string_apple.h" diff --git a/Firestore/core/src/util/log_apple.mm b/Firestore/core/src/util/log_apple.mm index 6d1e7d7ab6c..b57b156b403 100644 --- a/Firestore/core/src/util/log_apple.mm +++ b/Firestore/core/src/util/log_apple.mm @@ -24,7 +24,6 @@ #include #import "FirebaseCore/Extension/FIRLogger.h" -#import "FirebaseCore/Sources/Public/FirebaseCore/FIRLoggerLevel.h" #include "Firestore/core/src/util/string_apple.h" @@ -36,39 +35,46 @@ const FIRLoggerService kFIRLoggerFirestore = @"[FirebaseFirestore]"; -// Translates a C++ LogLevel to the equivalent Objective-C FIRLoggerLevel -FIRLoggerLevel ToFIRLoggerLevel(LogLevel level) { - switch (level) { - case kLogLevelDebug: - return FIRLoggerLevelDebug; - case kLogLevelNotice: - return FIRLoggerLevelNotice; - case kLogLevelWarning: - return FIRLoggerLevelWarning; - case kLogLevelError: - return FIRLoggerLevelError; - default: - // Unsupported log level. FIRSetLoggerLevel will deal with it. - return static_cast(-1); - } -} - // Actually logs a message via FIRLogger. This must be a C varargs function // so that we can call FIRLogBasic which takes a `va_list`. void LogMessageV(LogLevel level, NSString* format, ...) { va_list list; va_start(list, format); - FIRLogBasic(ToFIRLoggerLevel(level), kFIRLoggerFirestore, @"I-FST000001", - format, list); - + switch (level) { + case kLogLevelDebug: + FIRLogBasicDebug(kFIRLoggerFirestore, @"I-FST000001", format, list); + break; + case kLogLevelNotice: + FIRLogBasicNotice(kFIRLoggerFirestore, @"I-FST000001", format, list); + break; + case kLogLevelWarning: + FIRLogBasicWarning(kFIRLoggerFirestore, @"I-FST000001", format, list); + break; + case kLogLevelError: + FIRLogBasicError(kFIRLoggerFirestore, @"I-FST000001", format, list); + break; + } va_end(list); } } // namespace void LogSetLevel(LogLevel level) { - FIRSetLoggerLevel(ToFIRLoggerLevel(level)); + switch (level) { + case kLogLevelDebug: + FIRSetLoggerLevelDebug(); + break; + case kLogLevelNotice: + FIRSetLoggerLevelNotice(); + break; + case kLogLevelWarning: + FIRSetLoggerLevelWarning(); + break; + case kLogLevelError: + FIRSetLoggerLevelError(); + break; + } } // Note that FIRLogger's default level can be changed by persisting a @@ -82,7 +88,17 @@ void LogSetLevel(LogLevel level) { // defaults write firestore_util_test /google/firebase/debug_mode NO bool LogIsLoggable(LogLevel level) { - return FIRIsLoggableLevel(ToFIRLoggerLevel(level), false); + switch (level) { + case kLogLevelDebug: + return FIRIsLoggableLevelDebug(); + case kLogLevelNotice: + return FIRIsLoggableLevelNotice(); + case kLogLevelWarning: + return FIRIsLoggableLevelWarning(); + case kLogLevelError: + return FIRIsLoggableLevelError(); + } + return false; } void LogMessage(LogLevel level, const std::string& message) {