Skip to content

Commit

Permalink
Fix module build issues (#13797)
Browse files Browse the repository at this point in the history
  • Loading branch information
paulb777 authored Oct 4, 2024
1 parent 3c754ed commit 67834c3
Show file tree
Hide file tree
Showing 6 changed files with 138 additions and 34 deletions.
13 changes: 4 additions & 9 deletions FirebaseAppDistribution/Sources/FIRFADLogger.m
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

#import "FirebaseAppDistribution/Sources/FIRFADLogger.h"
#import "FirebaseCore/Extension/FIRLogger.h"
#import "FirebaseCore/Sources/Public/FirebaseCore/FIRLoggerLevel.h"

FIRLoggerService kFIRLoggerAppDistribution = @"[FirebaseAppDistribution]";

Expand All @@ -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);
}
45 changes: 45 additions & 0 deletions FirebaseCore/Extension/FIRLogger.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,23 @@ 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).
* (required) whether or not this function is called from the Analytics component.
*/
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.
Expand Down Expand Up @@ -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
Expand Down
48 changes: 48 additions & 0 deletions FirebaseCore/Sources/FIRLogger.m
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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,
Expand All @@ -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.
*
Expand Down
2 changes: 1 addition & 1 deletion Firestore/Source/API/FSTFirestoreComponent.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
62 changes: 39 additions & 23 deletions Firestore/core/src/util/log_apple.mm
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
#include <string>

#import "FirebaseCore/Extension/FIRLogger.h"
#import "FirebaseCore/Sources/Public/FirebaseCore/FIRLoggerLevel.h"

#include "Firestore/core/src/util/string_apple.h"

Expand All @@ -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<FIRLoggerLevel>(-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
Expand All @@ -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) {
Expand Down

0 comments on commit 67834c3

Please sign in to comment.