Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
CE4CE2E91C0E465B009F6029 /* SalesforceFileLogger.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = CE4CE2E11C0E465B009F6029 /* SalesforceFileLogger.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
CEA2A8EA2214C1B1009D923B /* CocoaLumberjack.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = CEA2A8C72214C184009D923B /* CocoaLumberjack.framework */; };
CEA2A8EB2214C1B9009D923B /* SalesforceSDKCommon.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = CEA2A8AC2214C174009D923B /* SalesforceSDKCommon.framework */; };
D291DB6C2E468AAF00AA4B64 /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = D291DB6B2E468AAF00AA4B64 /* ViewController.m */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand Down Expand Up @@ -168,6 +169,8 @@
CEA2A8B32214C184009D923B /* Lumberjack.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = Lumberjack.xcodeproj; path = ../../external/CocoaLumberjack/Lumberjack.xcodeproj; sourceTree = "<group>"; };
CECB662E1C1BB8CB008038AE /* SalesforceFileLogger-Dynamic-iOS-Debug.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; name = "SalesforceFileLogger-Dynamic-iOS-Debug.xcconfig"; path = "Configuration/SalesforceFileLogger-Dynamic-iOS-Debug.xcconfig"; sourceTree = "<group>"; };
CECB662F1C1BB8CB008038AE /* SalesforceFileLogger-Dynamic-iOS-Release.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; name = "SalesforceFileLogger-Dynamic-iOS-Release.xcconfig"; path = "Configuration/SalesforceFileLogger-Dynamic-iOS-Release.xcconfig"; sourceTree = "<group>"; };
D291DB6A2E468AAF00AA4B64 /* ViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ViewController.h; sourceTree = "<group>"; };
D291DB6B2E468AAF00AA4B64 /* ViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ViewController.m; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -293,6 +296,8 @@
82EFF30516E8049500A63CDF /* SalesforceFileLoggerTestApp */ = {
isa = PBXGroup;
children = (
D291DB6A2E468AAF00AA4B64 /* ViewController.h */,
D291DB6B2E468AAF00AA4B64 /* ViewController.m */,
4F06AFC31C49A87F00F70798 /* Supporting Files */,
B7282F4C1D8C717200475F79 /* SalesforceFileLoggerTestApp.entitlements */,
82EFF34116E80B6300A63CDF /* Classes */,
Expand Down Expand Up @@ -622,6 +627,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
D291DB6C2E468AAF00AA4B64 /* ViewController.m in Sources */,
82EFF30C16E8049500A63CDF /* main.m in Sources */,
82EFF34416E80B6300A63CDF /* AppDelegate.m in Sources */,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@
*/
@property (nonatomic, readwrite, assign, getter=isFileLoggingEnabled) BOOL fileLoggingEnabled;

/**
* Controls whether to use OSLog for console logging.
* Defaults to NO.
*/
@property (class, nonatomic, readwrite, assign) BOOL useOSLog;

/**
* By default, returns the default shared instance. Child classes implement this method to return an instance with
* their defined component name.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,15 @@

#import "SFSDKLogger.h"
#import <SalesforceSDKCommon/NSUserDefaults+SFAdditions.h>
#import <CocoaLumberjack/DDOSLogger.h>
#import <CocoaLumberjack/DDTTYLogger.h>

static NSString * const kDefaultComponentName = @"SFSDK";
static NSString * const kFileLoggerOnOffKey = @"file_logger_enabled";
static NSString * const kLogLevelKey = @"log_level";
static NSString * const kLogIdentifierFormat = @"COMPONENT: %@, CLASS: %@";
static NSMutableDictionary<NSString *, SFSDKLogger *> *loggerList = nil;
static BOOL _useOSLog = NO;

@interface SFSDKLogger ()

Expand Down Expand Up @@ -67,6 +69,14 @@ + (instancetype)sharedInstance {
return [self sharedInstanceWithComponent:kDefaultComponentName];
}

+ (BOOL)useOSLog {
return _useOSLog;
}

+ (void)setUseOSLog:(BOOL)useOSLogValue {
_useOSLog = useOSLogValue;
}

+ (void)flushAllComponents:(void (^)(void))completionBlock {
@synchronized ([SFSDKLogger class]) {
__block NSUInteger numberOfLogsLeftToFlush = loggerList.allKeys.count;
Expand Down Expand Up @@ -94,9 +104,17 @@ - (instancetype)initWithComponent:(NSString *)componentName {
self.componentName = componentName;
self.logger = [[DDLog alloc] init];
self.fileLogger = [[SFSDKFileLogger alloc] initWithComponent:componentName];
DDTTYLogger *consoleLogger = [DDTTYLogger sharedInstance];
consoleLogger.logFormatter = [[SFSDKFormatter alloc] init];
consoleLogger.colorsEnabled = YES;

id<DDLogger> consoleLogger;
if ([self.class useOSLog]) {
consoleLogger = [[DDOSLogger alloc] initWithSubsystem:[[NSBundle mainBundle] bundleIdentifier] category:componentName];
} else {
DDTTYLogger *ttyLogger = [DDTTYLogger sharedInstance];
ttyLogger.logFormatter = [[SFSDKFormatter alloc] init];
ttyLogger.colorsEnabled = YES;
consoleLogger = ttyLogger;
}

[self.logger addLogger:consoleLogger withLevel:DDLogLogLevelForSFLogLevel(self.logLevel)];
if (self.fileLoggingEnabled) {
[self.logger addLogger:self.fileLogger withLevel:DDLogLogLevelForSFLogLevel(self.logLevel)];
Expand Down Expand Up @@ -150,8 +168,16 @@ - (DDLogLevel)ddLogLevel {
- (void)setDdLogLevel:(DDLogLevel)logLevel {
[self storeLogLevel:logLevel];
[self.logger removeAllLoggers];
DDTTYLogger *consoleLogger = [DDTTYLogger sharedInstance];
consoleLogger.colorsEnabled = YES;

id<DDLogger> consoleLogger;
if ([self.class useOSLog]) {
consoleLogger = [[DDOSLogger alloc] initWithSubsystem:[[NSBundle mainBundle] bundleIdentifier] category:self.componentName];
} else {
DDTTYLogger *ttyLogger = [DDTTYLogger sharedInstance];
ttyLogger.colorsEnabled = YES;
consoleLogger = ttyLogger;
}

[self.logger addLogger:consoleLogger withLevel:logLevel];
[self.logger addLogger:self.fileLogger withLevel:logLevel];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/#import "AppDelegate.h"
*/
#import "AppDelegate.h"
#import "ViewController.h"

@interface AppDelegate ()

Expand All @@ -34,6 +36,13 @@ @implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.

// Create window and set up the view controller
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
ViewController *viewController = [[ViewController alloc] init];
self.window.rootViewController = viewController;
[self.window makeKeyAndVisible];

return YES;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#import "ViewController.h"
#import <SalesforceFileLogger/SalesforceFileLogger.h>

@interface ViewController ()

Expand All @@ -35,7 +36,21 @@ @implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.

// Log some messages using SFSDKLogger without enabling OSLog
[[SFSDKLogger sharedInstance] i:[self class] message:@"Info log message without OSLog"];
[[SFSDKLogger sharedInstance] w:[self class] message:@"Warning log message without OSLog"];
[[SFSDKLogger sharedInstance] e:[self class] message:@"Error log message without OSLog"];
[[SFSDKLogger sharedInstance] d:[self class] message:@"Debug log message without OSLog"];

[SFSDKLogger setUseOSLog:YES];

// Create a new logger instance with OSLog enabled and log some more messages
SFSDKLogger *osLogTestLogger = [SFSDKLogger sharedInstanceWithComponent:@"OSLog Test"];
[osLogTestLogger i:[self class] message:@"Info log message with OSLog"];
[osLogTestLogger w:[self class] message:@"Warning log message with OSLog"];
[osLogTestLogger e:[self class] message:@"Error log message with OSLog"];
[osLogTestLogger d:[self class] message:@"Debug log message with OSLog"];
}


@end
Loading