Skip to content

Commit

Permalink
Set default log level in load instead of getter (google#23)
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewheard authored Sep 6, 2023
1 parent abe7026 commit d6b709f
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 7 deletions.
12 changes: 5 additions & 7 deletions AppCheckCore/Sources/Core/GACAppCheckLogger.m
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,12 @@ @implementation GACAppCheckLogger
// Note: Declared as volatile to make getting and setting atomic.
static volatile GACAppCheckLogLevel _logLevel;

+ (void)load {
// Set the default log level (warning).
_logLevel = GACAppCheckLogLevelWarning;
}

+ (GACAppCheckLogLevel)logLevel {
static dispatch_once_t once;
dispatch_once(&once, ^{
if (!_logLevel) {
// Set the default log level (warning) if not yet set.
_logLevel = GACAppCheckLogLevelWarning;
}
});
return _logLevel;
}

Expand Down
40 changes: 40 additions & 0 deletions AppCheckCore/Tests/Unit/Core/GACAppCheckLoggerTests.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Copyright 2023 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

@import XCTest;

#import "AppCheckCore/Sources/Public/AppCheckCore/GACAppCheckLogger.h"

@interface GACAppCheckLoggerTests : XCTestCase
@end

@implementation GACAppCheckLoggerTests

- (void)testDefaultLogLevel {
GACAppCheckLogLevel defaultLogLevel = GACAppCheckLogger.logLevel;

XCTAssertEqual(defaultLogLevel, GACAppCheckLogLevelWarning);
}

- (void)testSetLogLevel {
GACAppCheckLogLevel expectedLogLevel = GACAppCheckLogLevelDebug;

GACAppCheckLogger.logLevel = expectedLogLevel;

XCTAssertEqual(GACAppCheckLogger.logLevel, expectedLogLevel);
}

@end

0 comments on commit d6b709f

Please sign in to comment.