Skip to content

Commit 546bf67

Browse files
authored
Add additional base infrastructure for the logging client (#2174)
* Generalize the concept of a logSource Rename and change the type of the 'log source' to be more appropriately generalized as a log mapping identifier string. * Expand the API of the logger. * Add infrastructure for log storage. * Add infrastructure for the log writer. * Remove an unnecessary comment. * Style fixes applied * Change a missed assert message to make more sense.
1 parent c22e2b7 commit 546bf67

File tree

9 files changed

+218
-13
lines changed

9 files changed

+218
-13
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
* Copyright 2018 Google
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#import <Foundation/Foundation.h>
18+
19+
/** Manages the storage and prioritizing of logs. */
20+
@interface GDLLogStorage : NSObject
21+
22+
@end
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*
2+
* Copyright 2018 Google
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#import "GDLLogStorage.h"
18+
19+
@implementation GDLLogStorage
20+
21+
@end
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
* Copyright 2018 Google
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#import <Foundation/Foundation.h>
18+
19+
/** Manages the writing and log-time transforming of logs. */
20+
@interface GDLLogWriter : NSObject
21+
22+
@end
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*
2+
* Copyright 2018 Google
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#import "GDLLogWriter.h"
18+
19+
@implementation GDLLogWriter : NSObject
20+
21+
@end

GoogleDataLogger/GoogleDataLogger/Classes/GDLLogger.m

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,12 @@
1616

1717
#import "GDLLogger.h"
1818

19+
#import "GDLLogEvent.h"
20+
1921
@interface GDLLogger ()
2022

21-
/** The log source this logger logs to. */
22-
@property(nonatomic) NSInteger logSource;
23+
/** The log mapping identifier that a GDLLogBackend will use to map the extension to proto. */
24+
@property(nonatomic) NSString *logMapID;
2325

2426
/** The log transformers that will operate on logs logged by this logger. */
2527
@property(nonatomic) NSArray<id<GDLLogTransformer>> *logTransformers;
@@ -31,18 +33,34 @@ @interface GDLLogger ()
3133

3234
@implementation GDLLogger
3335

34-
- (instancetype)initWithLogSource:(NSInteger)logSource
35-
logTransformers:(nullable NSArray<id<GDLLogTransformer>> *)logTransformers
36-
logTarget:(NSInteger)logTarget {
36+
- (instancetype)initWithLogMapID:(NSString *)logMapID
37+
logTransformers:(nullable NSArray<id<GDLLogTransformer>> *)logTransformers
38+
logTarget:(NSInteger)logTarget {
3739
self = [super init];
3840
if (self) {
39-
NSAssert(logSource > 0, @"A log source cannot be negative or 0");
41+
NSAssert(logMapID.length > 0, @"A log mapping ID cannot be nil or empty");
4042
NSAssert(logTarget > 0, @"A log target cannot be negative or 0");
41-
_logSource = logSource;
43+
_logMapID = logMapID;
4244
_logTransformers = logTransformers;
4345
_logTarget = logTarget;
4446
}
4547
return self;
4648
}
4749

50+
- (void)logTelemetryEvent:(GDLLogEvent *)logEvent {
51+
NSAssert(logEvent, @"You can't log a nil event");
52+
53+
// TODO(mikehaney24): Implement.
54+
}
55+
56+
- (void)logDataEvent:(GDLLogEvent *)logEvent {
57+
NSAssert(logEvent, @"You can't log a nil event");
58+
59+
// TODO(mikehaney24): Implement.
60+
}
61+
62+
- (GDLLogEvent *)newEvent {
63+
return [[GDLLogEvent alloc] init];
64+
}
65+
4866
@end

GoogleDataLogger/GoogleDataLogger/Classes/Public/GDLLogger.h

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,23 +18,45 @@
1818

1919
#import "GDLLogTransformer.h"
2020

21+
@class GDLLogEvent;
22+
2123
NS_ASSUME_NONNULL_BEGIN
2224

2325
@interface GDLLogger : NSObject
2426

25-
/** Please use the designated initializer. */
27+
// Please use the designated initializer.
2628
- (instancetype)init NS_UNAVAILABLE;
2729

2830
/** Initializes a new logger that will log events to the given target backend.
2931
*
30-
* @param logSource The log source/type that this logger logs to.
32+
* @param logMapID The mapping identifier used by the backend to map the extension to a proto.
3133
* @param logTransformers A list of transformers to be applied to log events that are logged.
3234
* @param logTarget The target backend of this logger.
3335
* @return A logger that will log events.
3436
*/
35-
- (instancetype)initWithLogSource:(NSInteger)logSource
36-
logTransformers:(nullable NSArray<id<GDLLogTransformer>> *)logTransformers
37-
logTarget:(NSInteger)logTarget;
37+
- (instancetype)initWithLogMapID:(NSString *)logMapID
38+
logTransformers:(nullable NSArray<id<GDLLogTransformer>> *)logTransformers
39+
logTarget:(NSInteger)logTarget NS_DESIGNATED_INITIALIZER;
40+
41+
/** Logs an internal telemetry event. Logs sent using this API are lower in priority, and sometimes
42+
* won't be sent on their own.
43+
*
44+
* @param logEvent The log event to log.
45+
*/
46+
- (void)logTelemetryEvent:(GDLLogEvent *)logEvent;
47+
48+
/** Logs an SDK service data event. Logs send using this API are higher in priority, and will cause
49+
* a network request at some point in the relative near future.
50+
*
51+
* @param logEvent The log event to log.
52+
*/
53+
- (void)logDataEvent:(GDLLogEvent *)logEvent;
54+
55+
/** Creates a log event for use by this logger.
56+
*
57+
* @return A log event that is suited for use by this logger.
58+
*/
59+
- (GDLLogEvent *)newEvent;
3860

3961
@end
4062

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* Copyright 2018 Google
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#import <XCTest/XCTest.h>
18+
19+
#import "GDLLogStorage.h"
20+
21+
@interface GDLLogStorageTest : XCTestCase
22+
23+
@end
24+
25+
@implementation GDLLogStorageTest
26+
27+
/** Tests the default initializer. */
28+
- (void)testInit {
29+
XCTAssertNotNil([[GDLLogStorage alloc] init]);
30+
}
31+
32+
@end
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* Copyright 2018 Google
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#import <XCTest/XCTest.h>
18+
19+
#import "GDLLogWriter.h"
20+
21+
@interface GDLLogWriterTest : XCTestCase
22+
23+
@end
24+
25+
@implementation GDLLogWriterTest
26+
27+
/** Tests the default initializer. */
28+
- (void)testInit {
29+
XCTAssertNotNil([[GDLLogWriter alloc] init]);
30+
}
31+
32+
@end

GoogleDataLogger/Tests/GDLLoggerTest.m

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,22 @@ @implementation GDLLoggerTest
2626

2727
/** Tests the default initializer. */
2828
- (void)testInit {
29-
XCTAssertNotNil([[GDLLogger alloc] initWithLogSource:1 logTransformers:nil logTarget:1]);
29+
XCTAssertNotNil([[GDLLogger alloc] initWithLogMapID:@"1" logTransformers:nil logTarget:1]);
30+
XCTAssertThrows([[GDLLogger alloc] initWithLogMapID:@"" logTransformers:nil logTarget:1]);
31+
}
32+
33+
/** Tests logging a telemetry event. */
34+
- (void)testLogTelemetryEvent {
35+
GDLLogger *logger = [[GDLLogger alloc] initWithLogMapID:@"1" logTransformers:nil logTarget:1];
36+
GDLLogEvent *event = [logger newEvent];
37+
XCTAssertNoThrow([logger logTelemetryEvent:event]);
38+
}
39+
40+
/** Tests logging a data event. */
41+
- (void)testLogDataEvent {
42+
GDLLogger *logger = [[GDLLogger alloc] initWithLogMapID:@"1" logTransformers:nil logTarget:1];
43+
GDLLogEvent *event = [logger newEvent];
44+
XCTAssertNoThrow([logger logDataEvent:event]);
3045
}
3146

3247
@end

0 commit comments

Comments
 (0)