Skip to content

Add additional base infrastructure for the logging client #2174

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Dec 10, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions GoogleDataLogger/GoogleDataLogger/Classes/GDLLogStorage.h
Original file line number Diff line number Diff line change
@@ -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 <Foundation/Foundation.h>

/** Manages the storage and prioritizing of logs. */
@interface GDLLogStorage : NSObject

@end
21 changes: 21 additions & 0 deletions GoogleDataLogger/GoogleDataLogger/Classes/GDLLogStorage.m
Original file line number Diff line number Diff line change
@@ -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
22 changes: 22 additions & 0 deletions GoogleDataLogger/GoogleDataLogger/Classes/GDLLogWriter.h
Original file line number Diff line number Diff line change
@@ -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 <Foundation/Foundation.h>

/** Manages the writing and log-time transforming of logs. */
@interface GDLLogWriter : NSObject

@end
21 changes: 21 additions & 0 deletions GoogleDataLogger/GoogleDataLogger/Classes/GDLLogWriter.m
Original file line number Diff line number Diff line change
@@ -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
32 changes: 25 additions & 7 deletions GoogleDataLogger/GoogleDataLogger/Classes/GDLLogger.m
Original file line number Diff line number Diff line change
Expand Up @@ -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<id<GDLLogTransformer>> *logTransformers;
Expand All @@ -31,18 +33,34 @@ @interface GDLLogger ()

@implementation GDLLogger

- (instancetype)initWithLogSource:(NSInteger)logSource
logTransformers:(nullable NSArray<id<GDLLogTransformer>> *)logTransformers
logTarget:(NSInteger)logTarget {
- (instancetype)initWithLogMapID:(NSString *)logMapID
logTransformers:(nullable NSArray<id<GDLLogTransformer>> *)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
32 changes: 27 additions & 5 deletions GoogleDataLogger/GoogleDataLogger/Classes/Public/GDLLogger.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<id<GDLLogTransformer>> *)logTransformers
logTarget:(NSInteger)logTarget;
- (instancetype)initWithLogMapID:(NSString *)logMapID
logTransformers:(nullable NSArray<id<GDLLogTransformer>> *)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

Expand Down
32 changes: 32 additions & 0 deletions GoogleDataLogger/Tests/GDLLogStorageTest.m
Original file line number Diff line number Diff line change
@@ -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 <XCTest/XCTest.h>

#import "GDLLogStorage.h"

@interface GDLLogStorageTest : XCTestCase

@end

@implementation GDLLogStorageTest

/** Tests the default initializer. */
- (void)testInit {
XCTAssertNotNil([[GDLLogStorage alloc] init]);
}

@end
32 changes: 32 additions & 0 deletions GoogleDataLogger/Tests/GDLLogWriterTest.m
Original file line number Diff line number Diff line change
@@ -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 <XCTest/XCTest.h>

#import "GDLLogWriter.h"

@interface GDLLogWriterTest : XCTestCase

@end

@implementation GDLLogWriterTest

/** Tests the default initializer. */
- (void)testInit {
XCTAssertNotNil([[GDLLogWriter alloc] init]);
}

@end
17 changes: 16 additions & 1 deletion GoogleDataLogger/Tests/GDLLoggerTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -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