diff --git a/GoogleDataLogger/GoogleDataLogger/Classes/GDLLogStorage.h b/GoogleDataLogger/GoogleDataLogger/Classes/GDLLogStorage.h new file mode 100644 index 00000000000..0a334ca7563 --- /dev/null +++ b/GoogleDataLogger/GoogleDataLogger/Classes/GDLLogStorage.h @@ -0,0 +1,22 @@ +/* + * Copyright 2018 Google + * + * 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 + +/** Manages the storage and prioritizing of logs. */ +@interface GDLLogStorage : NSObject + +@end diff --git a/GoogleDataLogger/GoogleDataLogger/Classes/GDLLogStorage.m b/GoogleDataLogger/GoogleDataLogger/Classes/GDLLogStorage.m new file mode 100644 index 00000000000..50d977fa030 --- /dev/null +++ b/GoogleDataLogger/GoogleDataLogger/Classes/GDLLogStorage.m @@ -0,0 +1,21 @@ +/* + * Copyright 2018 Google + * + * 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 "GDLLogStorage.h" + +@implementation GDLLogStorage + +@end diff --git a/GoogleDataLogger/GoogleDataLogger/Classes/GDLLogWriter.h b/GoogleDataLogger/GoogleDataLogger/Classes/GDLLogWriter.h new file mode 100644 index 00000000000..c11dffe9f32 --- /dev/null +++ b/GoogleDataLogger/GoogleDataLogger/Classes/GDLLogWriter.h @@ -0,0 +1,22 @@ +/* + * Copyright 2018 Google + * + * 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 + +/** Manages the writing and log-time transforming of logs. */ +@interface GDLLogWriter : NSObject + +@end diff --git a/GoogleDataLogger/GoogleDataLogger/Classes/GDLLogWriter.m b/GoogleDataLogger/GoogleDataLogger/Classes/GDLLogWriter.m new file mode 100644 index 00000000000..1f7453dbfce --- /dev/null +++ b/GoogleDataLogger/GoogleDataLogger/Classes/GDLLogWriter.m @@ -0,0 +1,21 @@ +/* + * Copyright 2018 Google + * + * 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 "GDLLogWriter.h" + +@implementation GDLLogWriter : NSObject + +@end diff --git a/GoogleDataLogger/GoogleDataLogger/Classes/GDLLogger.m b/GoogleDataLogger/GoogleDataLogger/Classes/GDLLogger.m index 9bb179c6a48..70f4e921d69 100644 --- a/GoogleDataLogger/GoogleDataLogger/Classes/GDLLogger.m +++ b/GoogleDataLogger/GoogleDataLogger/Classes/GDLLogger.m @@ -16,10 +16,12 @@ #import "GDLLogger.h" +#import "GDLLogEvent.h" + @interface GDLLogger () -/** The log source this logger logs to. */ -@property(nonatomic) NSInteger logSource; +/** The log mapping identifier that a GDLLogBackend will use to map the extension to proto. */ +@property(nonatomic) NSString *logMapID; /** The log transformers that will operate on logs logged by this logger. */ @property(nonatomic) NSArray> *logTransformers; @@ -31,18 +33,34 @@ @interface GDLLogger () @implementation GDLLogger -- (instancetype)initWithLogSource:(NSInteger)logSource - logTransformers:(nullable NSArray> *)logTransformers - logTarget:(NSInteger)logTarget { +- (instancetype)initWithLogMapID:(NSString *)logMapID + logTransformers:(nullable NSArray> *)logTransformers + logTarget:(NSInteger)logTarget { self = [super init]; if (self) { - NSAssert(logSource > 0, @"A log source cannot be negative or 0"); + NSAssert(logMapID.length > 0, @"A log mapping ID cannot be nil or empty"); NSAssert(logTarget > 0, @"A log target cannot be negative or 0"); - _logSource = logSource; + _logMapID = logMapID; _logTransformers = logTransformers; _logTarget = logTarget; } return self; } +- (void)logTelemetryEvent:(GDLLogEvent *)logEvent { + NSAssert(logEvent, @"You can't log a nil event"); + + // TODO(mikehaney24): Implement. +} + +- (void)logDataEvent:(GDLLogEvent *)logEvent { + NSAssert(logEvent, @"You can't log a nil event"); + + // TODO(mikehaney24): Implement. +} + +- (GDLLogEvent *)newEvent { + return [[GDLLogEvent alloc] init]; +} + @end diff --git a/GoogleDataLogger/GoogleDataLogger/Classes/Public/GDLLogger.h b/GoogleDataLogger/GoogleDataLogger/Classes/Public/GDLLogger.h index ae0917fba6b..1938c36f16d 100644 --- a/GoogleDataLogger/GoogleDataLogger/Classes/Public/GDLLogger.h +++ b/GoogleDataLogger/GoogleDataLogger/Classes/Public/GDLLogger.h @@ -18,23 +18,45 @@ #import "GDLLogTransformer.h" +@class GDLLogEvent; + NS_ASSUME_NONNULL_BEGIN @interface GDLLogger : NSObject -/** Please use the designated initializer. */ +// Please use the designated initializer. - (instancetype)init NS_UNAVAILABLE; /** Initializes a new logger that will log events to the given target backend. * - * @param logSource The log source/type that this logger logs to. + * @param logMapID The mapping identifier used by the backend to map the extension to a proto. * @param logTransformers A list of transformers to be applied to log events that are logged. * @param logTarget The target backend of this logger. * @return A logger that will log events. */ -- (instancetype)initWithLogSource:(NSInteger)logSource - logTransformers:(nullable NSArray> *)logTransformers - logTarget:(NSInteger)logTarget; +- (instancetype)initWithLogMapID:(NSString *)logMapID + logTransformers:(nullable NSArray> *)logTransformers + logTarget:(NSInteger)logTarget NS_DESIGNATED_INITIALIZER; + +/** Logs an internal telemetry event. Logs sent using this API are lower in priority, and sometimes + * won't be sent on their own. + * + * @param logEvent The log event to log. + */ +- (void)logTelemetryEvent:(GDLLogEvent *)logEvent; + +/** Logs an SDK service data event. Logs send using this API are higher in priority, and will cause + * a network request at some point in the relative near future. + * + * @param logEvent The log event to log. + */ +- (void)logDataEvent:(GDLLogEvent *)logEvent; + +/** Creates a log event for use by this logger. + * + * @return A log event that is suited for use by this logger. + */ +- (GDLLogEvent *)newEvent; @end diff --git a/GoogleDataLogger/Tests/GDLLogStorageTest.m b/GoogleDataLogger/Tests/GDLLogStorageTest.m new file mode 100644 index 00000000000..b511fcee111 --- /dev/null +++ b/GoogleDataLogger/Tests/GDLLogStorageTest.m @@ -0,0 +1,32 @@ +/* + * Copyright 2018 Google + * + * 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 + +#import "GDLLogStorage.h" + +@interface GDLLogStorageTest : XCTestCase + +@end + +@implementation GDLLogStorageTest + +/** Tests the default initializer. */ +- (void)testInit { + XCTAssertNotNil([[GDLLogStorage alloc] init]); +} + +@end diff --git a/GoogleDataLogger/Tests/GDLLogWriterTest.m b/GoogleDataLogger/Tests/GDLLogWriterTest.m new file mode 100644 index 00000000000..914b7e62ec4 --- /dev/null +++ b/GoogleDataLogger/Tests/GDLLogWriterTest.m @@ -0,0 +1,32 @@ +/* + * Copyright 2018 Google + * + * 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 + +#import "GDLLogWriter.h" + +@interface GDLLogWriterTest : XCTestCase + +@end + +@implementation GDLLogWriterTest + +/** Tests the default initializer. */ +- (void)testInit { + XCTAssertNotNil([[GDLLogWriter alloc] init]); +} + +@end diff --git a/GoogleDataLogger/Tests/GDLLoggerTest.m b/GoogleDataLogger/Tests/GDLLoggerTest.m index 5f854cf8ae3..2c7f5d4cebb 100644 --- a/GoogleDataLogger/Tests/GDLLoggerTest.m +++ b/GoogleDataLogger/Tests/GDLLoggerTest.m @@ -26,7 +26,22 @@ @implementation GDLLoggerTest /** Tests the default initializer. */ - (void)testInit { - XCTAssertNotNil([[GDLLogger alloc] initWithLogSource:1 logTransformers:nil logTarget:1]); + XCTAssertNotNil([[GDLLogger alloc] initWithLogMapID:@"1" logTransformers:nil logTarget:1]); + XCTAssertThrows([[GDLLogger alloc] initWithLogMapID:@"" logTransformers:nil logTarget:1]); +} + +/** Tests logging a telemetry event. */ +- (void)testLogTelemetryEvent { + GDLLogger *logger = [[GDLLogger alloc] initWithLogMapID:@"1" logTransformers:nil logTarget:1]; + GDLLogEvent *event = [logger newEvent]; + XCTAssertNoThrow([logger logTelemetryEvent:event]); +} + +/** Tests logging a data event. */ +- (void)testLogDataEvent { + GDLLogger *logger = [[GDLLogger alloc] initWithLogMapID:@"1" logTransformers:nil logTarget:1]; + GDLLogEvent *event = [logger newEvent]; + XCTAssertNoThrow([logger logDataEvent:event]); } @end