Skip to content

Commit

Permalink
Move the logging static methods in FBSession to public FBSettings class
Browse files Browse the repository at this point in the history
Summary: Create a new class FBSettings, and move to it the methods loggingBehavior and setLoggingBehaviour from FBSession.

Test Plan: Ran unit tests

Reviewers: clang, jacl, gregschechte, mmarucheck

Reviewed By: gregschechte

CC: yariv, bhiller

Differential Revision: https://phabricator.fb.com/D514198

Task ID: 1146322
  • Loading branch information
aydenw committed Jul 13, 2012
1 parent 0e7b033 commit ac018ab
Show file tree
Hide file tree
Showing 12 changed files with 139 additions and 79 deletions.
5 changes: 3 additions & 2 deletions src/FBFriendPickerViewController.m
Expand Up @@ -27,6 +27,7 @@
#import "FBRequestConnection.h"
#import "FBUtility.h"
#import "FBSession+Internal.h"
#import "FBSettings.h"

NSString *const FBFriendPickerCacheIdentity = @"FBFriendPicker";
static NSString *defaultImageName = @"FBiOSSDKResources.bundle/FBFriendPickerView/images/default.png";
Expand Down Expand Up @@ -192,7 +193,7 @@ - (FBSession*)session {
- (void)viewDidLoad
{
[super viewDidLoad];
[FBLogger registerCurrentTime:FBLogBehaviorPerformanceCharacteristics
[FBLogger registerCurrentTime:FBLoggingBehaviorPerformanceCharacteristics
withTag:self];
CGRect bounds = self.view.bounds;

Expand Down Expand Up @@ -427,7 +428,7 @@ - (void)pagingLoader:(FBGraphObjectPagingLoader*)pagingLoader didLoadData:(NSDic
// This logging currently goes here because we're effectively complete with our initial view when
// the first page of results come back. In the future, when we do caching, we will need to move
// this to a more appropriate place (e.g., after the cache has been brought in).
[FBLogger singleShotLogEntry:FBLogBehaviorPerformanceCharacteristics
[FBLogger singleShotLogEntry:FBLoggingBehaviorPerformanceCharacteristics
timestampTag:self
formatString:@"Friend Picker: first render "]; // logger will append "%d msec"

Expand Down
13 changes: 7 additions & 6 deletions src/FBLogger.m
Expand Up @@ -16,6 +16,7 @@

#import "FBLogger.h"
#import "FBSession.h"
#import "FBSettings.h"
#import "FBUtility.h"

static NSUInteger g_serialNumberCounter = 1111;
Expand All @@ -39,7 +40,7 @@ @implementation FBLogger

- (id)initWithLoggingBehavior:(NSString *)loggingBehavior {
if (self = [super init]) {
_isActive = [[FBSession loggingBehavior] containsObject:loggingBehavior];
_isActive = [[FBSettings loggingBehavior] containsObject:loggingBehavior];
_loggingBehavior = loggingBehavior;
if (_isActive) {
_internalContents = [[NSMutableString alloc] init];
Expand Down Expand Up @@ -117,7 +118,7 @@ + (NSUInteger)newSerialNumber {

+ (void)singleShotLogEntry:(NSString *)loggingBehavior
logEntry:(NSString *)logEntry {
if ([[FBSession loggingBehavior] containsObject:loggingBehavior]) {
if ([[FBSettings loggingBehavior] containsObject:loggingBehavior]) {
FBLogger *logger = [[FBLogger alloc] initWithLoggingBehavior:loggingBehavior];
[logger appendString:logEntry];
[logger emitToNSLog];
Expand All @@ -128,7 +129,7 @@ + (void)singleShotLogEntry:(NSString *)loggingBehavior
+ (void)singleShotLogEntry:(NSString *)loggingBehavior
formatString:(NSString *)formatString, ... {

if ([[FBSession loggingBehavior] containsObject:loggingBehavior]) {
if ([[FBSettings loggingBehavior] containsObject:loggingBehavior]) {
va_list vaArguments;
va_start(vaArguments, formatString);
NSString *logString = [[[NSString alloc] initWithFormat:formatString arguments:vaArguments] autorelease];
Expand All @@ -143,7 +144,7 @@ + (void)singleShotLogEntry:(NSString *)loggingBehavior
timestampTag:(NSObject *)timestampTag
formatString:(NSString *)formatString, ... {

if ([[FBSession loggingBehavior] containsObject:loggingBehavior]) {
if ([[FBSettings loggingBehavior] containsObject:loggingBehavior]) {
va_list vaArguments;
va_start(vaArguments, formatString);
NSString *logString = [[[NSString alloc] initWithFormat:formatString arguments:vaArguments] autorelease];
Expand Down Expand Up @@ -171,7 +172,7 @@ + (void)singleShotLogEntry:(NSString *)loggingBehavior
+ (void)registerCurrentTime:(NSString *)loggingBehavior
withTag:(NSObject *)timestampTag {

if ([[FBSession loggingBehavior] containsObject:loggingBehavior]) {
if ([[FBSettings loggingBehavior] containsObject:loggingBehavior]) {

if (!g_startTimesWithTags) {
g_startTimesWithTags = [[NSMutableDictionary alloc] init];
Expand All @@ -196,7 +197,7 @@ + (void)registerStringToReplace:(NSString *)replace

// Strings sent in here never get cleaned up, but that's OK, don't ever expect too many.

if ([[FBSession loggingBehavior] count] > 0) { // otherwise there's no logging.
if ([[FBSettings loggingBehavior] count] > 0) { // otherwise there's no logging.

if (!g_stringsToReplace) {
g_stringsToReplace = [[NSMutableDictionary alloc] init];
Expand Down
5 changes: 3 additions & 2 deletions src/FBPlacePickerViewController.m
Expand Up @@ -26,6 +26,7 @@
#import "FBUtility.h"
#import "FBPlacePickerCacheDescriptor.h"
#import "FBSession+Internal.h"
#import "FBSettings.h"

NSString *const FBPlacePickerCacheIdentity = @"FBPlacePicker";

Expand Down Expand Up @@ -247,7 +248,7 @@ + (FBCacheDescriptor*)cacheDescriptorWithLocationCoordinate:(CLLocationCoordinat
- (void)viewDidLoad
{
[super viewDidLoad];
[FBLogger registerCurrentTime:FBLogBehaviorPerformanceCharacteristics
[FBLogger registerCurrentTime:FBLoggingBehaviorPerformanceCharacteristics
withTag:self];
CGRect bounds = self.view.bounds;

Expand Down Expand Up @@ -428,7 +429,7 @@ - (void)pagingLoader:(FBGraphObjectPagingLoader*)pagingLoader didLoadData:(NSDic
// This logging currently goes here because we're effectively complete with our initial view when
// the first page of results come back. In the future, when we do caching, we will need to move
// this to a more appropriate place (e.g., after the cache has been brought in).
[FBLogger singleShotLogEntry:FBLogBehaviorPerformanceCharacteristics
[FBLogger singleShotLogEntry:FBLoggingBehaviorPerformanceCharacteristics
timestampTag:self
formatString:@"Places Picker: first render "]; // logger will append "%d msec"

Expand Down
5 changes: 3 additions & 2 deletions src/FBRequestConnection.m
Expand Up @@ -21,6 +21,7 @@
#import "FBRequestBody.h"
#import "FBSession.h"
#import "FBSession+Internal.h"
#import "FBSettings.h"
#import "FBRequestConnection.h"
#import "FBRequestConnection+Internal.h"
#import "FBRequest.h"
Expand Down Expand Up @@ -271,7 +272,7 @@ - (id)initWithTimeout:(NSTimeInterval)timeout
_requests = [[NSMutableArray alloc] init];
_timeout = timeout;
_state = kStateCreated;
_logger = [[FBLogger alloc] initWithLoggingBehavior:FBLogBehaviorFBRequests];
_logger = [[FBLogger alloc] initWithLoggingBehavior:FBLoggingBehaviorFBRequests];
_isResultFromCache = NO;
}
return self;
Expand Down Expand Up @@ -1201,7 +1202,7 @@ - (BOOL)isInvalidSessionError:(NSError *)error

- (void)registerTokenToOmitFromLog:(NSString *)token
{
if (![[FBSession loggingBehavior] containsObject:FBLogBehaviorAccessTokens]) {
if (![[FBSettings loggingBehavior] containsObject:FBLoggingBehaviorAccessTokens]) {
[FBLogger registerStringToReplace:token replaceWith:@"ACCESS_TOKEN_REMOVED"];
}
}
Expand Down
37 changes: 0 additions & 37 deletions src/FBSession.h
Expand Up @@ -36,25 +36,6 @@ extern NSString *const FBSessionDidSetActiveSessionNotification;
/*! NSNotificationCenter name indicating that an active session was unset */
extern NSString *const FBSessionDidUnsetActiveSessionNotification;

/*
* Constants defining logging behavior. Use with <[FBSession setLoggingBehavior]>.
*/

/*! Log requests from FBRequest* classes */
extern NSString *const FBLogBehaviorFBRequests;

/*! Log requests from FBURLConnection* classes */
extern NSString *const FBLogBehaviorFBURLConnections;

/*! Include access token in logging. */
extern NSString *const FBLogBehaviorAccessTokens;

/*! Log session state transitions. */
extern NSString *const FBLogBehaviorSessionStateTransitions;

/*! Log performance characteristics */
extern NSString *const FBLogBehaviorPerformanceCharacteristics;

/*!
@typedef FBSessionState enum
Expand Down Expand Up @@ -372,24 +353,6 @@ typedef void (^FBSessionReauthorizeResultHandler)(FBSession *session,
*/
+ (FBSession*)setActiveSession:(FBSession*)session;

/*!
@method
@abstract Retrieve the current Facebook SDK logging behavior.
*/
+ (NSSet *)loggingBehavior;

/*!
@method
@abstract Set the current Facebook SDK logging behavior. This should consist of strings defined as
constants with FBLogBehavior*, and can be constructed with [NSSet initWithObjects:].
@param loggingBehavior A set of strings indicating what information should be logged.
*/
+ (void)setLoggingBehavior:(NSSet *)loggingBehavior;

/*!
@method
Expand Down
29 changes: 6 additions & 23 deletions src/FBSession.m
Expand Up @@ -20,6 +20,7 @@
#import "FBSession+Internal.h"
#import "FBSession+Protected.h"
#import "FBSessionTokenCachingStrategy.h"
#import "FBSettings.h"
#import "FBError.h"
#import "FBLogger.h"
#import "FBUtility.h"
Expand Down Expand Up @@ -79,12 +80,6 @@ - (id)oauthToken;
static NSString *const FBLoginUXIOS = @"ios";
static NSString *const FBLoginUXSDK = @"sdk";

NSString *const FBLogBehaviorFBRequests = @"fb_requests";
NSString *const FBLogBehaviorFBURLConnections = @"fburl_connections";
NSString *const FBLogBehaviorAccessTokens = @"include_access_tokens";
NSString *const FBLogBehaviorSessionStateTransitions = @"state_transitions";
NSString *const FBLogBehaviorPerformanceCharacteristics = @"perf_characteristics";

// the following constant strings are used by NSNotificationCenter
NSString *const FBSessionDidSetActiveSessionNotification = @"com.facebook.FBiOSSDK:FBSessionDidSetActiveSessionNotification";
NSString *const FBSessionDidUnsetActiveSessionNotification = @"com.facebook.FBiOSSDK:FBSessionDidUnsetActiveSessionNotification";
Expand All @@ -102,7 +97,6 @@ - (id)oauthToken;
// module scoped globals
static NSString *g_defaultAppID = nil;
static FBSession *g_activeSession = nil;
static NSSet *g_loggingBehavior;

@interface FBSession () <FBLoginDialogDelegate> {
@private
Expand Down Expand Up @@ -233,7 +227,7 @@ - (id)initWithAppID:(NSString*)appID
self.refreshDate = nil;
self.state = FBSessionStateCreated;
self.affinitizedThread = [NSThread currentThread];
[FBLogger registerCurrentTime:FBLogBehaviorPerformanceCharacteristics
[FBLogger registerCurrentTime:FBLoggingBehaviorPerformanceCharacteristics
withTag:self];
//first notification
[self notifyOfState:self.state];
Expand Down Expand Up @@ -504,17 +498,6 @@ + (FBSession*)setActiveSession:(FBSession*)session {
return session;
}


+ (NSSet *)loggingBehavior {
return g_loggingBehavior;
}

+ (void)setLoggingBehavior:(NSSet *)newValue {
[g_loggingBehavior release];
g_loggingBehavior = newValue;
[g_loggingBehavior retain];
}

+ (void)setDefaultAppID:(NSString*)appID {
NSString *oldValue = g_defaultAppID;
g_defaultAppID = [appID copy];
Expand Down Expand Up @@ -583,7 +566,7 @@ - (BOOL)transitionToState:(FBSessionState)state

// invalid transition short circuits
if (!isValidTransition) {
[FBLogger singleShotLogEntry:FBLogBehaviorSessionStateTransitions
[FBLogger singleShotLogEntry:FBLoggingBehaviorSessionStateTransitions
logEntry:[NSString stringWithFormat:@"FBSession **INVALID** transition from %@ to %@",
[FBSession sessionStateDescription:statePrior],
[FBSession sessionStateDescription:state]]];
Expand All @@ -605,14 +588,14 @@ - (BOOL)transitionToState:(FBSessionState)state
NSString *logString = [NSString stringWithFormat:@"FBSession transition from %@ to %@ ",
[FBSession sessionStateDescription:statePrior],
[FBSession sessionStateDescription:state]];
[FBLogger singleShotLogEntry:FBLogBehaviorSessionStateTransitions logEntry:logString];
[FBLogger singleShotLogEntry:FBLoggingBehaviorSessionStateTransitions logEntry:logString];

[FBLogger singleShotLogEntry:FBLogBehaviorPerformanceCharacteristics
[FBLogger singleShotLogEntry:FBLoggingBehaviorPerformanceCharacteristics
timestampTag:self
formatString:@"%@", logString];

// Re-start session transition timer for the next time around.
[FBLogger registerCurrentTime:FBLogBehaviorPerformanceCharacteristics
[FBLogger registerCurrentTime:FBLoggingBehaviorPerformanceCharacteristics
withTag:self];

// identify whether we will update token and date, and what the values will be
Expand Down
58 changes: 58 additions & 0 deletions src/FBSettings.h
@@ -0,0 +1,58 @@
/*
* Copyright 2012 Facebook
*
* 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>

/*
* Constants defining logging behavior. Use with <[FBSettings setLoggingBehavior]>.
*/

/*! Log requests from FBRequest* classes */
extern NSString *const FBLoggingBehaviorFBRequests;

/*! Log requests from FBURLConnection* classes */
extern NSString *const FBLoggingBehaviorFBURLConnections;

/*! Include access token in logging. */
extern NSString *const FBLoggingBehaviorAccessTokens;

/*! Log session state transitions. */
extern NSString *const FBLoggingBehaviorSessionStateTransitions;

/*! Log performance characteristics */
extern NSString *const FBLoggingBehaviorPerformanceCharacteristics;

@interface FBSettings : NSObject

/*!
@method
@abstract Retrieve the current Facebook SDK logging behavior.
*/
+ (NSSet *)loggingBehavior;

/*!
@method
@abstract Set the current Facebook SDK logging behavior. This should consist of strings defined as
constants with FBLogBehavior*, and can be constructed with [NSSet initWithObjects:].
@param loggingBehavior A set of strings indicating what information should be logged.
*/
+ (void)setLoggingBehavior:(NSSet *)loggingBehavior;

@end
39 changes: 39 additions & 0 deletions src/FBSettings.m
@@ -0,0 +1,39 @@
/*
* Copyright 2010 Facebook
*
* 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 "FBSettings.h"

NSString *const FBLoggingBehaviorFBRequests = @"fb_requests";
NSString *const FBLoggingBehaviorFBURLConnections = @"fburl_connections";
NSString *const FBLoggingBehaviorAccessTokens = @"include_access_tokens";
NSString *const FBLoggingBehaviorSessionStateTransitions = @"state_transitions";
NSString *const FBLoggingBehaviorPerformanceCharacteristics = @"perf_characteristics";

@implementation FBSettings

static NSSet *g_loggingBehavior;

+ (NSSet *)loggingBehavior {
return g_loggingBehavior;
}

+ (void)setLoggingBehavior:(NSSet *)newValue {
[newValue retain];
[g_loggingBehavior release];
g_loggingBehavior = newValue;
}

@end

0 comments on commit ac018ab

Please sign in to comment.