Skip to content

Commit

Permalink
[Core] Add logging level getter to FIRConfiguration (#13815)
Browse files Browse the repository at this point in the history
  • Loading branch information
ncooke3 authored Oct 4, 2024
1 parent a366d6c commit a1e4be7
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 1 deletion.
11 changes: 10 additions & 1 deletion FirebaseCore/Sources/FIRConfiguration.m
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#import "FirebaseCore/Sources/FIRAnalyticsConfiguration.h"

extern void FIRSetLoggerLevel(FIRLoggerLevel loggerLevel);
extern FIRLoggerLevel FIRGetLoggerLevel(void);

@implementation FIRConfiguration

Expand All @@ -40,7 +41,15 @@ - (instancetype)init {
- (void)setLoggerLevel:(FIRLoggerLevel)loggerLevel {
NSAssert(loggerLevel <= FIRLoggerLevelMax && loggerLevel >= FIRLoggerLevelMin,
@"Invalid logger level, %ld", (long)loggerLevel);
FIRSetLoggerLevel(loggerLevel);
@synchronized(self) {
FIRSetLoggerLevel(loggerLevel);
}
}

- (FIRLoggerLevel)loggerLevel {
@synchronized(self) {
return FIRGetLoggerLevel();
}
}

@end
1 change: 1 addition & 0 deletions FirebaseCore/Sources/FIRLogger.m
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ void FIRLoggerInitialize(void) {
}

FIRLoggerLevel FIRGetLoggerLevel(void) {
FIRLoggerInitialize();
return (FIRLoggerLevel)GULGetLoggerLevel();
}

Expand Down
3 changes: 3 additions & 0 deletions FirebaseCore/Sources/Public/FirebaseCore/FIRConfiguration.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ NS_SWIFT_NAME(FirebaseConfiguration)
*/
- (void)setLoggerLevel:(FIRLoggerLevel)loggerLevel;

/// Returns the logging level for internal Firebase logging.
- (FIRLoggerLevel)loggerLevel;

@end

NS_ASSUME_NONNULL_END
14 changes: 14 additions & 0 deletions FirebaseCore/Tests/Unit/FIRConfigurationTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,18 @@ - (void)testSharedInstance {
XCTAssertNotNil(config.analyticsConfiguration);
}

- (void)testGetDefaultLevel {
FIRConfiguration *config = [FIRConfiguration sharedInstance];
FIRLoggerLevel defaultLevel = [config loggerLevel];
XCTAssertEqual(defaultLevel, FIRLoggerLevelNotice);
}

- (void)testSetAndGet {
FIRConfiguration *config = [FIRConfiguration sharedInstance];
for (FIRLoggerLevel level = FIRLoggerLevelMin; level <= FIRLoggerLevelMax; level++) {
[config setLoggerLevel:level];
XCTAssertEqual([config loggerLevel], level);
}
}

@end

0 comments on commit a1e4be7

Please sign in to comment.