diff options
author | Riz <rsattar@gmail.com> | 2017-05-24 17:29:09 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-05-24 17:29:09 -0700 |
commit | 2c133b34b0d3cbbe27b9206d57fe69140e5db6b3 (patch) | |
tree | 7c3959cd04e4a9b1c0fced611d51253353f402fa /Firebase | |
parent | db7f85b9d43906adb99524185d7c375d2161c152 (diff) |
Clean up logging and configuration in Messaging (#28)
* Remove mostly unused code from FIRMessagingLogger
This cleans up some left-over old logging logic from before we moved to FIRLogger in Firebase Core. We no longer need this logging functionality.
* Delete FIRMessagingConfig.{h,m}
We no longer need a config class to store an unused log level filter (that filter is no longer needed).
Diffstat (limited to 'Firebase')
-rw-r--r-- | Firebase/Messaging/FIRMessaging+FIRApp.m | 1 | ||||
-rw-r--r-- | Firebase/Messaging/FIRMessaging.m | 26 | ||||
-rw-r--r-- | Firebase/Messaging/FIRMessagingConfig.h | 46 | ||||
-rw-r--r-- | Firebase/Messaging/FIRMessagingConfig.m | 38 | ||||
-rw-r--r-- | Firebase/Messaging/FIRMessagingFileLogger.h | 31 | ||||
-rw-r--r-- | Firebase/Messaging/FIRMessagingFileLogger.m | 108 | ||||
-rw-r--r-- | Firebase/Messaging/FIRMessagingLogger.h | 30 | ||||
-rw-r--r-- | Firebase/Messaging/FIRMessagingLogger.m | 214 |
8 files changed, 5 insertions, 489 deletions
diff --git a/Firebase/Messaging/FIRMessaging+FIRApp.m b/Firebase/Messaging/FIRMessaging+FIRApp.m index fc53286..b8adf14 100644 --- a/Firebase/Messaging/FIRMessaging+FIRApp.m +++ b/Firebase/Messaging/FIRMessaging+FIRApp.m @@ -19,7 +19,6 @@ #import "FIRAppInternal.h" #import "FIROptionsInternal.h" -#import "FIRMessagingConfig.h" #import "FIRMessagingConstants.h" #import "FIRMessagingLogger.h" #import "FIRMessagingPubSub.h" diff --git a/Firebase/Messaging/FIRMessaging.m b/Firebase/Messaging/FIRMessaging.m index 94347c8..f9a5f50 100644 --- a/Firebase/Messaging/FIRMessaging.m +++ b/Firebase/Messaging/FIRMessaging.m @@ -24,7 +24,6 @@ #import <UIKit/UIKit.h> #import "FIRMessagingClient.h" -#import "FIRMessagingConfig.h" #import "FIRMessagingConstants.h" #import "FIRMessagingContextManagerService.h" #import "FIRMessagingDataMessageManager.h" @@ -133,7 +132,6 @@ NSString * const FIRMessagingRegistrationTokenRefreshedNotification = // Due to our packaging requirements, we can't directly depend on FIRInstanceID currently. @property(nonatomic, readwrite, strong) FIRMessagingInstanceIDProxy *instanceIDProxy; -@property(nonatomic, readwrite, strong) FIRMessagingConfig *config; @property(nonatomic, readwrite, assign) BOOL isClientSetup; @property(nonatomic, readwrite, strong) FIRMessagingClient *client; @@ -157,18 +155,15 @@ NSString * const FIRMessagingRegistrationTokenRefreshedNotification = static FIRMessaging *messaging; static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ - // Start Messaging (Fully initialize in one place). - FIRMessagingConfig *config = [FIRMessagingConfig defaultConfig]; - messaging = [[FIRMessaging alloc] initWithConfig:config]; + messaging = [[FIRMessaging alloc] initPrivately]; [messaging start]; }); return messaging; } -- (instancetype)initWithConfig:(FIRMessagingConfig *)config { +- (instancetype)initPrivately { self = [super init]; if (self) { - _config = config; _loggedMessageIDs = [NSMutableSet set]; _instanceIDProxy = [[FIRMessagingInstanceIDProxy alloc] init]; } @@ -192,11 +187,9 @@ NSString * const FIRMessagingRegistrationTokenRefreshedNotification = #pragma mark - Config - (void)start { - _FIRMessagingDevAssert(self.config, @"Invalid nil config in FIRMessagingService"); [self saveLibraryVersion]; - [self setupLogger:self.config.logLevel]; - [self setupReceiverWithConfig:self.config]; + [self setupReceiver]; NSString *hostname = kFIRMessagingReachabilityHostname; self.reachability = [[FIRReachabilityChecker alloc] initWithReachabilityDelegate:self @@ -259,18 +252,7 @@ NSString * const FIRMessagingRegistrationTokenRefreshedNotification = currentLibraryVersion); } -- (void)setupLogger:(FIRMessagingLogLevel)loggerLevel { -#if FIRMessaging_PROBER - // do nothing -#else - FIRMessagingLogger *logger = FIRMessagingSharedLogger(); - FIRMessagingLogLevelFilter *filter = - [[FIRMessagingLogLevelFilter alloc] initWithLevel:loggerLevel]; - [logger setFilter:filter]; -#endif -} - -- (void)setupReceiverWithConfig:(FIRMessagingConfig *)config { +- (void)setupReceiver { self.receiver = [[FIRMessagingReceiver alloc] init]; self.receiver.delegate = self; } diff --git a/Firebase/Messaging/FIRMessagingConfig.h b/Firebase/Messaging/FIRMessagingConfig.h deleted file mode 100644 index 09a9ec7..0000000 --- a/Firebase/Messaging/FIRMessagingConfig.h +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright 2017 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> - -typedef NS_ENUM(int8_t, FIRMessagingLogLevel) { - kFIRMessagingLogLevelDebug, - kFIRMessagingLogLevelInfo, - kFIRMessagingLogLevelError, - kFIRMessagingLogLevelAssert, -}; - -/** - * Config used to set different options in Firebase Messaging. - */ -@interface FIRMessagingConfig : NSObject - -/** - * The log level for the FIRMessaging library. Valid values are `kFIRMessagingLogLevelDebug`, - * `kFIRMessagingLogLevelInfo`, `kFIRMessagingLogLevelError`, and `kFIRMessagingLogLevelAssert`. - */ -@property(nonatomic, readwrite, assign) FIRMessagingLogLevel logLevel; - -/** - * Get default configuration for FIRMessaging. The default config has logLevel set to - * `kFIRMessagingLogLevelError` and `receiverDelegate` is set to nil. - * - * @return FIRMessagingConfig sharedInstance. - */ -+ (instancetype)defaultConfig; - -@end - diff --git a/Firebase/Messaging/FIRMessagingConfig.m b/Firebase/Messaging/FIRMessagingConfig.m deleted file mode 100644 index e7674c3..0000000 --- a/Firebase/Messaging/FIRMessagingConfig.m +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright 2017 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 "FIRMessagingConfig.h" -#import "FIRMessagingDefines.h" - -@implementation FIRMessagingConfig - -- (instancetype)init { - FIRMessagingInvalidateInitializer(); -} - -+ (instancetype)defaultConfig { - return [[FIRMessagingConfig alloc] initWithDefaultConfig]; -} - -- (instancetype)initWithDefaultConfig { - self = [super init]; - if (self) { - self.logLevel = kFIRMessagingLogLevelError; - } - return self; -} - -@end diff --git a/Firebase/Messaging/FIRMessagingFileLogger.h b/Firebase/Messaging/FIRMessagingFileLogger.h deleted file mode 100644 index ec11369..0000000 --- a/Firebase/Messaging/FIRMessagingFileLogger.h +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright 2017 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 "FIRMessagingLogger.h" - -#if FIRMessaging_PROBER -@interface FIRMessagingFileLogFilter : NSObject <FIRMessagingLogFilter> - -@end - -@interface FIRMessagingFileLogFormatter : NSObject <FIRMessagingLogFormatter> - -@end - -@interface FIRMessagingFileLogWriter : NSObject <FIRMessagingLogWriter> - -@end -#endif diff --git a/Firebase/Messaging/FIRMessagingFileLogger.m b/Firebase/Messaging/FIRMessagingFileLogger.m deleted file mode 100644 index 7570a79..0000000 --- a/Firebase/Messaging/FIRMessagingFileLogger.m +++ /dev/null @@ -1,108 +0,0 @@ -/* - * Copyright 2017 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 "FIRMessagingFileLogger.h" - -#if FIRMessaging_PROBER - -#import "DDFileLogger.h" -#import "DDLog.h" - -@interface FIRMessagingFileLogFilter () - -@property(nonatomic, readwrite, assign) FIRMessagingLogLevel level; -@end - -@implementation FIRMessagingFileLogFilter - -#pragma mark - GTMLogFilter protocol - -- (BOOL)filterAllowsMessage:(NSString *)msg level:(FIRMessagingLogLevel)level { - // allow everything - return YES; -} - -@end - -@interface FIRMessagingFileLogFormatter () - -@property(nonatomic, readwrite, strong) NSDateFormatter *dateFormatter; - -@end - -@implementation FIRMessagingFileLogFormatter - -static NSString *const kFIRMessagingLogPrefix = @"FIRMessaging"; - -- (id)init { - if ((self = [super init])) { - _dateFormatter = [[NSDateFormatter alloc] init]; - [_dateFormatter setFormatterBehavior:NSDateFormatterBehavior10_4]; - [_dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss.SSS"]; - } - return self; -} - -#pragma mark - GTMLogFormatter protocol - -static DDLogMessage *currentMessage; -- (NSString *)stringForFunc:(NSString *)func - withFormat:(NSString *)fmt - valist:(va_list)args - level:(FIRMessagingLogLevel)level { - NSString *logMessage = [[NSString alloc] initWithFormat:fmt arguments:args]; - currentMessage = [[DDLogMessage alloc] initWithMessage:logMessage - level:0 - flag:0 - context:0 - file:NULL - function:NULL - line:0 - tag:0 - options:0 - timestamp:[NSDate date]]; - return logMessage; -} - -@end - -@interface FIRMessagingFileLogWriter () - -@property(nonatomic, readwrite, strong) DDFileLogger *fileLogger; - -@end - -@implementation FIRMessagingFileLogWriter - -- (instancetype)init { - self = [super init]; - if (self) { - _fileLogger = [[DDFileLogger alloc] init]; - } - return self; -} - -#pragma mark - GTMLogWriter protocol - -- (void)logMessage:(NSString *)msg level:(FIRMessagingLogLevel)level { - // log to stdout - NSLog(@"%@", msg); - [self.fileLogger logMessage:currentMessage]; -} - -@end - -#endif diff --git a/Firebase/Messaging/FIRMessagingLogger.h b/Firebase/Messaging/FIRMessagingLogger.h index cd3c29a..d0ff41a 100644 --- a/Firebase/Messaging/FIRMessagingLogger.h +++ b/Firebase/Messaging/FIRMessagingLogger.h @@ -14,7 +14,6 @@ * limitations under the License. */ -#import "FIRMessagingConfig.h" #import "FIRMMessageCode.h" // The convenience macros are only defined if they haven't already been defined. @@ -35,37 +34,8 @@ #endif // !defined(FIRMessagingLoggerInfo) -/// Protocols -@protocol FIRMessagingLogFormatter <NSObject> -- (NSString *)stringForFunc:(NSString *)func - withFormat:(NSString *)fmt - valist:(va_list)args - level:(FIRMessagingLogLevel)level NS_FORMAT_FUNCTION(2, 0); -@end - -/// FIRMessagingLogWriter -@protocol FIRMessagingLogWriter <NSObject> -// Writes the given log message to where the log writer is configured to write. -- (void)logMessage:(NSString *)msg level:(FIRMessagingLogLevel)level; -@end - -/// FIRMessagingLogFilter -@protocol FIRMessagingLogFilter <NSObject> -// Returns YES if |msg| at |level| should be logged; NO otherwise. -- (BOOL)filterAllowsMessage:(NSString *)msg level:(FIRMessagingLogLevel)level; -@end - -@interface FIRMessagingLogLevelFilter : NSObject <FIRMessagingLogFilter> -- (instancetype)initWithLevel:(FIRMessagingLogLevel)level; -@end - - @interface FIRMessagingLogger : NSObject -@property(nonatomic, readwrite, strong) id<FIRMessagingLogFilter> filter; -@property(nonatomic, readwrite, strong) id<FIRMessagingLogWriter> writer; -@property(nonatomic, readwrite, strong) id<FIRMessagingLogFormatter> formatter; - - (void)logFuncDebug:(const char *)func messageCode:(FIRMessagingMessageCode)messageCode msg:(NSString *)fmt, ... NS_FORMAT_FUNCTION(3, 4); diff --git a/Firebase/Messaging/FIRMessagingLogger.m b/Firebase/Messaging/FIRMessagingLogger.m index 0ded97c..e8190d7 100644 --- a/Firebase/Messaging/FIRMessagingLogger.m +++ b/Firebase/Messaging/FIRMessagingLogger.m @@ -17,174 +17,11 @@ #import "FIRMessagingLogger.h" #import "FIRLogger.h" -#import "FIRMessagingFileLogger.h" - -/** - * A log formatter that prefixes log messages with "FIRMessaging". - */ -@interface FIRMessagingLogStandardFormatter : NSObject<FIRMessagingLogFormatter> - -@property(nonatomic, readwrite, strong) NSDateFormatter *dateFormatter; - -@end - -@implementation FIRMessagingLogStandardFormatter - -static NSString *const kFIRMessagingLogPrefix = @"FIRMessaging"; - -- (id)init { - if ((self = [super init])) { - _dateFormatter = [[NSDateFormatter alloc] init]; - [_dateFormatter setFormatterBehavior:NSDateFormatterBehavior10_4]; - [_dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss.SSS"]; - } - return self; -} -/** - * Returns a formatted string prefixed with "FIRMessaging" to allow - * FIRMessaging output to be easily differentiated in logs. - * - * @param func the name of the function calling the logger - * @param fmt the format string - * @param args the list of arguments for the format string - * @param level the logging level (eg. debug, info) - * @return the formatted string prefixed with "FIRMessaging". - */ -- (NSString *)stringForFunc:(NSString *)func - withFormat:(NSString *)fmt - valist:(va_list)args - level:(FIRMessagingLogLevel)level NS_FORMAT_FUNCTION(2, 0) { - if (!(fmt && args)) { - return nil; - } - - NSString *logMessage = [[NSString alloc] initWithFormat:fmt arguments:args]; - NSString *logLevelString = [self stringForLogLevel:level]; - NSString *dateString = [self.dateFormatter stringFromDate:[NSDate date]]; - return [NSString stringWithFormat:@"%@: <%@/%@> %@", - dateString, kFIRMessagingLogPrefix, logLevelString, logMessage]; -} - -- (NSString *)stringForLogLevel:(FIRMessagingLogLevel)level { - switch (level) { - case kFIRMessagingLogLevelDebug: - return @"DEBUG"; - - case kFIRMessagingLogLevelInfo: - return @"INFO"; - - case kFIRMessagingLogLevelError: - return @"WARNING"; - - case kFIRMessagingLogLevelAssert: - return @"ERROR"; - - default: - return @"INFO"; - } -} - -@end - -@interface FIRMessagingLogLevelFilter () - -@property(nonatomic, readwrite, assign) FIRMessagingLogLevel level; - -@end - -@implementation FIRMessagingLogLevelFilter - -- (instancetype)initWithLevel:(FIRMessagingLogLevel)level { - self = [super init]; - if (self) { - _level = level; - } - return self; -} - -- (BOOL)filterAllowsMessage:(NSString *)msg level:(FIRMessagingLogLevel)level { -#if defined(DEBUG) && DEBUG - return YES; -#endif - - BOOL allow = YES; - - switch (level) { - case kFIRMessagingLogLevelDebug: - allow = NO; - break; - case kFIRMessagingLogLevelInfo: - case kFIRMessagingLogLevelError: - case kFIRMessagingLogLevelAssert: - allow = (level >= self.level); - break; - default: - allow = NO; - break; - } - - return allow; -} - -@end - - -// Copied from FIRMessagingLogger. Standard implementation to write logs to console. -@interface NSFileHandle (FIRMessagingFileHandleLogWriter) <FIRMessagingLogWriter> -@end - -@implementation NSFileHandle (FIRMessagingFileHandleLogWriter) -- (void)logMessage:(NSString *)msg level:(FIRMessagingLogLevel)level { - @synchronized(self) { - // Closed pipes should not generate exceptions in our caller. Catch here - // as well [FIRMessagingLogger logInternalFunc:...] so that an exception in this - // writer does not prevent other writers from having a chance. - @try { - NSString *line = [NSString stringWithFormat:@"%@\n", msg]; - [self writeData:[line dataUsingEncoding:NSUTF8StringEncoding]]; - } - @catch (id e) { - // Ignored - } - } -} -@end - -@interface FIRMessagingLogger () - -@end @implementation FIRMessagingLogger + (instancetype)standardLogger { - - id<FIRMessagingLogWriter> writer; - id<FIRMessagingLogFormatter> formatter; - id<FIRMessagingLogFilter> filter; - -#if FIRMessaging_PROBER - writer = [[FIRMessagingFileLogWriter alloc] init]; - formatter = [[FIRMessagingFileLogFormatter alloc] init]; - filter = [[FIRMessagingFileLogFilter alloc] init]; -#else - writer = [NSFileHandle fileHandleWithStandardOutput]; - formatter = [[FIRMessagingLogStandardFormatter alloc] init]; - filter = [[FIRMessagingLogLevelFilter alloc] init]; -#endif - - return [[FIRMessagingLogger alloc] initWithFilter:filter formatter:formatter writer:writer]; -} - -- (instancetype)initWithFilter:(id<FIRMessagingLogFilter>)filter - formatter:(id<FIRMessagingLogFormatter>)formatter - writer:(id<FIRMessagingLogWriter>)writer { - self = [super init]; - if (self) { - _filter = filter; - _formatter = formatter; - _writer = writer; - } - return self; + return [[FIRMessagingLogger alloc] init]; } #pragma mark - Log Helpers @@ -201,11 +38,6 @@ static NSString *const kFIRMessagingLogPrefix = @"FIRMessaging"; FIRLogBasic(FIRLoggerLevelDebug, kFIRLoggerMessaging, [FIRMessagingLogger formatMessageCode:messageCode], fmt, args); va_end(args); -#if FIRMessaging_PROBER - va_start(args, fmt); - [self logInternalFunc:func format:fmt valist:args level:kFIRMessagingLogLevelDebug]; - va_end(args); -#endif } - (void)logFuncInfo:(const char *)func @@ -216,11 +48,6 @@ static NSString *const kFIRMessagingLogPrefix = @"FIRMessaging"; FIRLogBasic(FIRLoggerLevelInfo, kFIRLoggerMessaging, [FIRMessagingLogger formatMessageCode:messageCode], fmt, args); va_end(args); -#if FIRMessaging_PROBER - va_start(args, fmt); - [self logInternalFunc:func format:fmt valist:args level:kFIRMessagingLogLevelInfo]; - va_end(args); -#endif } - (void)logFuncNotice:(const char *)func @@ -231,12 +58,6 @@ static NSString *const kFIRMessagingLogPrefix = @"FIRMessaging"; FIRLogBasic(FIRLoggerLevelNotice, kFIRLoggerMessaging, [FIRMessagingLogger formatMessageCode:messageCode], fmt, args); va_end(args); -#if FIRMessaging_PROBER - va_start(args, fmt); - // Treat FIRLoggerLevelNotice as "info" locally, since we don't have an equivalent - [self logInternalFunc:func format:fmt valist:args level:kFIRMessagingLogLevelInfo]; - va_end(args); -#endif } - (void)logFuncWarning:(const char *)func @@ -247,12 +68,6 @@ static NSString *const kFIRMessagingLogPrefix = @"FIRMessaging"; FIRLogBasic(FIRLoggerLevelWarning, kFIRLoggerMessaging, [FIRMessagingLogger formatMessageCode:messageCode], fmt, args); va_end(args); -#if FIRMessaging_PROBER - va_start(args, fmt); - // Treat FIRLoggerLevelWarning as "error" locally, since we don't have an equivalent - [self logInternalFunc:func format:fmt valist:args level:kFIRMessagingLogLevelError]; - va_end(args); -#endif } - (void)logFuncError:(const char *)func @@ -263,33 +78,6 @@ static NSString *const kFIRMessagingLogPrefix = @"FIRMessaging"; FIRLogBasic(FIRLoggerLevelError, kFIRLoggerMessaging, [FIRMessagingLogger formatMessageCode:messageCode], fmt, args); va_end(args); -#if FIRMessaging_PROBER - va_start(args, fmt); - [self logInternalFunc:func format:fmt valist:args level:kFIRMessagingLogLevelError]; - va_end(args); -#endif -} - -#pragma mark - Internal Helpers - -- (void)logInternalFunc:(const char *)func - format:(NSString *)fmt - valist:(va_list)args - level:(FIRMessagingLogLevel)level { - // Primary point where logging happens, logging should never throw, catch - // everything. - @try { - NSString *fname = func ? [NSString stringWithUTF8String:func] : nil; - NSString *msg = [self.formatter stringForFunc:fname - withFormat:fmt - valist:args - level:level]; - if (msg && [self.filter filterAllowsMessage:msg level:level]) - [self.writer logMessage:msg level:level]; - } - @catch (id e) { - // Ignored - } } @end |