diff --git a/CHANGELOG.md b/CHANGELOG.md index b4f2751d..f136cf3b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,7 @@ The change log has moved to this repo's [GitHub Releases Page](https://github.co ## Release Notes Tagging Conventions -1. Every entry within the PackageReleaseNotes element is expected to be started with +1. Every entry within the PackageReleaseNotes element is expected to be started with at least one of the tags listed: feat: A new feature @@ -16,81 +16,112 @@ The change log has moved to this repo's [GitHub Releases Page](https://github.co test: Adding or modifying unit test code chore: Changes to the build process or auxiliary tools and libraries such as documentation generation, etc. -2. Every entry within the PackageReleaseNotes element is expected to be tagged with - EITHER +2. Every entry within the PackageReleaseNotes element is expected to be tagged with + EITHER "resolve #GITHUB_ISSUE_NUMBER:" - meaning completely addresses the GitHub issue - OR + OR "ref #GITHUB_ISSUE_NUMBER:" - meaning relevant to the GitHub issue depending on what is more appropriate in each case. ## Release Notes -**2.0.3 -- docs: resolve #122 - Update RollbarCommon public API doc comments so they are properly rendered by Xcode Quick Help -- docs: resolve #124 - Update RollbarDeploys public API doc comments so they are properly rendered by Xcode Quick Help -- docs: resolve #126 - Update RollbarSwift, RollbarAUL, RollbarPLCrashReporter, and RollbarKSCrash public API doc comments so they are properly rendered by Xcode Quick Help -- docs: resolve #127 - Update RollbarNotifier public API doc comments so they are properly rendered by Xcode Quick Help +### 2.1.0 + +- feat: resolve #141 - Apply developer options of the persisted payload when sending the payload +- feat: resolve #133 - Implement RollbarCocoaLumberjack module +- test: resolve #134 - Implement unit tests for RollbarCocoaLumberjack +- fix: resolve #136 - RollbarPLCrashReporter.init() no longer available +- test: resolve #140 - Factor out common SDK unit testing API +- chore: resolve #112 - Upgrade to the latest PLCrashReporter 1.0.1 +- docs: resolve #138 - Move current SDK documentation from readme.io to the repo +- docs: resolve #139 - Document new RollbarCocoaLumberjack module + +### 2.0.3 + +- docs: resolve #122 - Update RollbarCommon public API doc comments so they are properly rendered by Xcode Quick Help +- docs: resolve #124 - Update RollbarDeploys public API doc comments so they are properly rendered by Xcode Quick Help +- docs: resolve #126 - Update RollbarSwift, RollbarAUL, RollbarPLCrashReporter, and RollbarKSCrash public API doc comments so they are properly rendered by Xcode Quick Help +- docs: resolve #127 - Update RollbarNotifier public API doc comments so they are properly rendered by Xcode Quick Help - chore: resolve #114 - Consolidate destination parameters for samples - chore: resolve #113 - Consolidate destination parameters for unit tests -**2.0.2 +### 2.0.2 + - fix: resolve #110 - Xcode autocomplete for Swift expects person.id, but codebase expects person.ID - chore: resolve #118 - Remove source file header comments from RollbarCommon -**2.0.1 +### 2.0.1 + - moving from Beta to GA -**2.0.0-beta.23** +### 2.0.0-beta.23 + - refactor: upgraded KSCRash to v1.15.25 - refactor: upgraded PLCrashReporter to v1.10.0 - chore: updated macosAppObjC Xcode scheme - chore: update SonarCloud build wrapper - chore: update SonarCloud scanner -**2.0.0-beta.22** -**2.0.0-beta.21** +### 2.0.0-beta.22 + +### 2.0.0-beta.21 + - feat: new RollbarAUL module is code complete -**2.0.0-beta.15** +### 2.0.0-beta.15 + - fix: resolve #81 - SPM - Resolving Package Graph Failed -**2.0.0-beta.14** +### 2.0.0-beta.14 + - feat: allocated new RollbarAUL module project -- fix: resolve #72 - Rollbar* pods 2.0.0-beta.10 not all published +- fix: resolve #72 - Rollbar pods 2.0.0-beta.10 not all published + +### 2.0.0-beta.13 -**2.0.0-beta.13** -**2.0.0-beta.12** -**2.0.0-beta.11** -- fix: resolve #72 - Rollbar* pods 2.0.0-beta.10 not all published +### 2.0.0-beta.12 + +### 2.0.0-beta.11 + +- fix: resolve #72 - Rollbar pods 2.0.0-beta.10 not all published + +### 2.0.0-beta.10 -**2.0.0-beta.10** - fix: resolve #66 - App terminated due to signal 5 instantiating RollbarPLCrashCollector -**2.0.0-beta8** +### 2.0.0-beta8 + - fix: point all the Cocoapods podspecs to proper documentation site. -**2.0.0-beta7** -**2.0.0-beta6** -**2.0.0-beta5** -**2.0.0-beta4** +### 2.0.0-beta7 + +### 2.0.0-beta6 + +### 2.0.0-beta5 + +### 2.0.0-beta4 + - fix: RollbarSwift.podspec -**2.0.0-beta3** +### 2.0.0-beta3 + - feat: added RollbarSwift -**2.0.0-beta2** +### 2.0.0-beta2 + - feat: added new developer option: suppressSdkInfoLogging -**2.0.0-beta1** - comparing to Rollbar-iOS +### 2.0.0-beta1 - comparing to Rollbar-iOS + - feat: added RollbarPLCrashReporter module - feat: added RollbarKSCrash module -- feat: added explicit reporting of NSErrors +- feat: added explicit reporting of NSErrors - feat: defined default scrub fields - refactor: split out RollbarCommon, RollbarNotifier, RollbarDeploys - refactor: added use of lightweight generics - refactor: added use of nullability attributes - refactor: removed RollbarConfiguration and replaced it with RollbarConfig - refactor: changed WhitelistFields into SafeListFields when it comes to the RollbarScrubbingOptions -- refactor: removed all the deprecated API +- refactor: removed all the deprecated API - refactor: replaced NSString-like log level parameters in RollbarLogger interface with RollbarLevel enum - refactor: replaced sync-all log methods of Rollbar and RolbarLogger with ones dedicated to each type of payload: string-message, NSException, NSError, etc. diff --git a/Package.swift b/Package.swift index 6feec7ba..283c4d07 100644 --- a/Package.swift +++ b/Package.swift @@ -35,6 +35,9 @@ let package = Package( .library( name: "RollbarSwift", targets: ["RollbarSwift"]), + .library( + name: "RollbarCocoaLumberjack", + targets: ["RollbarCocoaLumberjack"]), ], dependencies: [ // Dependencies declare other packages that this package depends on. @@ -45,15 +48,20 @@ let package = Package( ), .package(name:"PLCrashReporter", url: "https://github.com/microsoft/plcrashreporter.git", - from: "1.10.0" //Package.Dependency.Requirement.branch("master") + from: "1.10.1" //Package.Dependency.Requirement.branch("master") ), + .package(name:"CocoaLumberjack", + url: "https://github.com/CocoaLumberjack/CocoaLumberjack.git", + from: "3.7.4" //Package.Dependency.Requirement.branch("master") + ), ], targets: [ // Targets are the basic building blocks of a package. A target can define a module or a test suite. // Targets can depend on other targets in this package, and on products in packages which this package depends on. .target( name: "RollbarCommon", - dependencies: [], + dependencies: [ + ], path: "RollbarCommon/Sources/RollbarCommon", publicHeadersPath: "include", cSettings: [ @@ -63,7 +71,9 @@ let package = Package( .target( name: "RollbarDeploys", - dependencies: ["RollbarCommon",], + dependencies: [ + "RollbarCommon", + ], path: "RollbarDeploys/Sources/RollbarDeploys", publicHeadersPath: "include", cSettings: [ @@ -73,7 +83,9 @@ let package = Package( .target( name: "RollbarNotifier", - dependencies: ["RollbarCommon",], + dependencies: [ + "RollbarCommon", + ], path: "RollbarNotifier/Sources/RollbarNotifier", publicHeadersPath: "include", cSettings: [ @@ -83,7 +95,10 @@ let package = Package( .target( name: "RollbarKSCrash", - dependencies: ["RollbarCommon", "KSCrash"], + dependencies: [ + "RollbarCommon", + "KSCrash", + ], path: "RollbarKSCrash/Sources/RollbarKSCrash", publicHeadersPath: "include", cSettings: [ @@ -93,7 +108,10 @@ let package = Package( .target( name: "RollbarPLCrashReporter", - dependencies: ["RollbarCommon", .product(name: "CrashReporter", package: "PLCrashReporter")], + dependencies: [ + "RollbarCommon", + .product(name: "CrashReporter", package: "PLCrashReporter"), + ], path: "RollbarPLCrashReporter/Sources/RollbarPLCrashReporter", publicHeadersPath: "include", cSettings: [ @@ -103,7 +121,10 @@ let package = Package( .target( name: "RollbarAUL", - dependencies: ["RollbarCommon", "RollbarNotifier"], + dependencies: [ + "RollbarCommon", + "RollbarNotifier", + ], path: "RollbarAUL/Sources/RollbarAUL", publicHeadersPath: "include", cSettings: [ @@ -113,7 +134,10 @@ let package = Package( .target( name: "RollbarSwift", - dependencies: ["RollbarCommon", "RollbarNotifier"], + dependencies: [ + "RollbarCommon", + "RollbarNotifier", + ], path: "RollbarSwift/Sources/RollbarSwift", publicHeadersPath: "include", cSettings: [ @@ -121,6 +145,20 @@ let package = Package( ] ), + .target( + name: "RollbarCocoaLumberjack", + dependencies: [ + "RollbarCommon", + "RollbarNotifier", + "CocoaLumberjack", + ], + path: "RollbarCocoaLumberjack/Sources/RollbarCocoaLumberjack", + publicHeadersPath: "include", + cSettings: [ + .headerSearchPath("RollbarCocoaLumberjack/Sources/RollbarCocoaLumberjack/**"), + ] + ), + ], swiftLanguageVersions: [ SwiftVersion.v4, diff --git a/README.md b/README.md index 7b23d745..abbf7c6d 100644 --- a/README.md +++ b/README.md @@ -83,4 +83,9 @@ See our [Releases](https://github.com/rollbar/rollbar-apple/releases) page for a ## Help / Support -If you run into any problems, please email us at `support@rollbar.com` or [file a bug report](https://github.com/rollbar/rollbar-apple/issues/new). +- [Gitter Community](https://gitter.im/rollbar/SDK-Apple) +- [Stack Overflow](https://stackoverflow.com/questions/tagged/rollbar) +- [GitHub Issues](https://github.com/rollbar/rollbar-apple/issues) +- [GitHub Discussions](https://github.com/rollbar/rollbar-apple/discussions) +- [File a bug report](https://github.com/rollbar/rollbar-apple/issues/new) +- Rollbar Support: `support@rollbar.com` \ No newline at end of file diff --git a/RollbarAUL.podspec b/RollbarAUL.podspec index c7552930..1c14c879 100644 --- a/RollbarAUL.podspec +++ b/RollbarAUL.podspec @@ -7,7 +7,7 @@ Pod::Spec.new do |s| - s.version = "2.0.3" + s.version = "2.1.0" s.name = "RollbarAUL" s.summary = "Application or client side SDK for interacting with the Rollbar API Server." s.description = <<-DESC diff --git a/RollbarAUL/Package.swift b/RollbarAUL/Package.swift index 3cf02f7b..73bf410f 100644 --- a/RollbarAUL/Package.swift +++ b/RollbarAUL/Package.swift @@ -23,9 +23,7 @@ let package = Package( // .package(url: /* package url */, from: "1.0.0"), .package(path: "../RollbarCommon"), .package(path: "../RollbarNotifier"), - .package(name: "UnitTesting", - path: "../UnitTesting" - ), + .package(path: "../UnitTesting"), ], targets: [ // Targets are the basic building blocks of a package. A target can define a module or a test suite. @@ -36,8 +34,6 @@ let package = Package( publicHeadersPath: "include", cSettings: [ .headerSearchPath("Sources/RollbarAUL/**"), -// .headerSearchPath("Sources/RollbarAUL"), -// .headerSearchPath("Sources/RollbarAUL/include"), // .headerSearchPath("Sources/RollbarAUL/DTOs"), // .define("DEFINES_MODULE"), @@ -52,11 +48,12 @@ let package = Package( ), .testTarget( name: "RollbarAULTests-ObjC", - dependencies: ["RollbarAUL"], + dependencies: [ + "UnitTesting", + "RollbarAUL" + ], cSettings: [ .headerSearchPath("Tests/RollbarAULTests-ObjC/**"), -// .headerSearchPath("Sources/RollbarNotifier"), -// .headerSearchPath("Sources/RollbarNotifier/include"), // .headerSearchPath("Sources/RollbarNotifier/DTOs"), // .define("DEFINES_MODULE"), diff --git a/RollbarAUL/Tests/RollbarAULTests-ObjC/RollbarAulStoreMonitorTest.m b/RollbarAUL/Tests/RollbarAULTests-ObjC/RollbarAulStoreMonitorTest.m index a656070e..7dbeb343 100644 --- a/RollbarAUL/Tests/RollbarAULTests-ObjC/RollbarAulStoreMonitorTest.m +++ b/RollbarAUL/Tests/RollbarAULTests-ObjC/RollbarAulStoreMonitorTest.m @@ -15,8 +15,8 @@ #if !TARGET_OS_WATCH #import -#import "../../../UnitTests/RollbarUnitTestSettings.h" +@import UnitTesting; @import RollbarNotifier; @import RollbarAUL; diff --git a/RollbarCocoaLumberjack/.gitignore b/RollbarCocoaLumberjack/.gitignore new file mode 100644 index 00000000..bb460e7b --- /dev/null +++ b/RollbarCocoaLumberjack/.gitignore @@ -0,0 +1,7 @@ +.DS_Store +/.build +/Packages +/*.xcodeproj +xcuserdata/ +DerivedData/ +.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata diff --git a/RollbarCocoaLumberjack/.swiftpm/xcode/xcshareddata/xcschemes/RollbarCocoaLumberjack.xcscheme b/RollbarCocoaLumberjack/.swiftpm/xcode/xcshareddata/xcschemes/RollbarCocoaLumberjack.xcscheme new file mode 100644 index 00000000..17a2082d --- /dev/null +++ b/RollbarCocoaLumberjack/.swiftpm/xcode/xcshareddata/xcschemes/RollbarCocoaLumberjack.xcscheme @@ -0,0 +1,101 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/RollbarCocoaLumberjack/Package.swift b/RollbarCocoaLumberjack/Package.swift new file mode 100644 index 00000000..e96d181c --- /dev/null +++ b/RollbarCocoaLumberjack/Package.swift @@ -0,0 +1,74 @@ +// swift-tools-version:5.5 +// The swift-tools-version declares the minimum version of Swift required to build this package. + +import PackageDescription + +let package = Package( + name: "RollbarCocoaLumberjack", + platforms: [ + // Oldest targeted platform versions that are supported by this product. + .macOS(.v10_10), + .iOS(.v9), + .tvOS(.v11), + .watchOS(.v4), + ], + products: [ + // Products define the executables and libraries a package produces, and make them visible to other packages. + .library( + name: "RollbarCocoaLumberjack", + targets: ["RollbarCocoaLumberjack"]), + ], + dependencies: [ + // Dependencies declare other packages that this package depends on. + // .package(url: /* package url */, from: "1.0.0"), + .package(path: "../RollbarCommon"), + .package(path: "../RollbarNotifier"), + .package(path: "../UnitTesting"), + .package(name:"CocoaLumberjack", + url: "https://github.com/CocoaLumberjack/CocoaLumberjack.git", + from: "3.7.4" //Package.Dependency.Requirement.branch("master") + ), + ], + targets: [ + // Targets are the basic building blocks of a package. A target can define a module or a test suite. + // Targets can depend on other targets in this package, and on products in packages this package depends on. + .target( + name: "RollbarCocoaLumberjack", + dependencies: [ + "RollbarCommon", + "RollbarNotifier", + "CocoaLumberjack", + ], + publicHeadersPath: "include", + cSettings: [ + .headerSearchPath("Sources/RollbarCocoaLumberjack/**"), + // .headerSearchPath("Sources/RollbarCocoaLumberjack/DTOs"), + // .define("DEFINES_MODULE"), + ] + ), + .testTarget( + name: "RollbarCocoaLumberjackTests", + dependencies: [ + "UnitTesting", + "CocoaLumberjack", + "RollbarCocoaLumberjack", + .productItem(name: "CocoaLumberjackSwift", package: "CocoaLumberjack", condition: nil), + ] + ), + .testTarget( + name: "RollbarCocoaLumberjackTests-ObjC", + dependencies: [ + "UnitTesting", + "RollbarCocoaLumberjack", + ], + cSettings: [ + .headerSearchPath("Tests/RollbarCocoaLumberjackTests-ObjC/**"), + ] + ), + ], + swiftLanguageVersions: [ + SwiftVersion.v4, + SwiftVersion.v4_2, + SwiftVersion.v5, + ] +) diff --git a/RollbarCocoaLumberjack/README.md b/RollbarCocoaLumberjack/README.md new file mode 100644 index 00000000..e7d8d3af --- /dev/null +++ b/RollbarCocoaLumberjack/README.md @@ -0,0 +1,9 @@ +# RollbarCocoaLumberjack + + +This SDK module implements integration of Rollbar into the popular CocoaLumberjack logging framework. + +So if you either already use CocoaLumberjack or you are planning to use it for your software product logging needs, +then you can easily integrate Rollbar into it via this module and have all or some of the logs performed via the +CocoaLumberjack framework redirected into a dedicated Rollbar project at www.rollbar.com and monitor the health of +your software product/service remotely. diff --git a/RollbarCocoaLumberjack/Sources/RollbarCocoaLumberjack/RollbarCocoaLumberjackLogger.m b/RollbarCocoaLumberjack/Sources/RollbarCocoaLumberjack/RollbarCocoaLumberjackLogger.m new file mode 100644 index 00000000..73621bc3 --- /dev/null +++ b/RollbarCocoaLumberjack/Sources/RollbarCocoaLumberjack/RollbarCocoaLumberjackLogger.m @@ -0,0 +1,171 @@ +#import "RollbarCocoaLumberjackLogger.h" + +@implementation RollbarCocoaLumberjackLogger + +#pragma mark - factory methods + ++ (NSObject *)createWithRollbarConfig:(RollbarConfig *)rollbarConfig { + + return [[RollbarCocoaLumberjackLogger alloc] initWithRollbarConfig:rollbarConfig]; +} + ++ (NSObject *)createWithRollbarLogger:(RollbarLogger *)rollbarLogger { + + return [[RollbarCocoaLumberjackLogger alloc] initWithRollbarLogger:rollbarLogger]; +} + +#pragma mark - instance initializers + +- (instancetype)initWithRollbarLogger:(RollbarLogger *)rollbarLogger { + + if ((self = [super init])) { + _rollbarLogger = rollbarLogger; + } + return self; +} + +- (instancetype)initWithRollbarConfig:(RollbarConfig *)rollbarConfig { + + RollbarLogger *rollbarLogger = [[RollbarLogger alloc] initWithConfiguration:rollbarConfig]; + return [self initWithRollbarLogger:rollbarLogger]; +} + +#pragma mark - DDLogger protocol + +- (void)logMessage:(DDLogMessage *)logMessage { + NSString *logMsg = logMessage.message; + + if (self->_logFormatter) + logMsg = [self->_logFormatter formatLogMessage:logMessage]; + + if (logMsg) { + // let's send it to Rollbar: + [self->_rollbarLogger log:[RollbarCocoaLumberjackLogger convertDDLogFlagToRollbarLevel:logMessage.flag] + message:logMsg + data:[RollbarCocoaLumberjackLogger dataWithDDLogMessage:logMessage] + context:@"RollbarCocoaLumberjackLogger" + ]; + } +} + +#pragma mark - utility methods + ++ (NSDictionary *)dataWithDDLogMessage:(DDLogMessage *)logMessage { + + return @{ + @"DDLogMessage.message": + logMessage.message, + @"DDLogMessage.level": + [RollbarCocoaLumberjackLogger convertDDLogLevelToString:logMessage.level], + @"DDLogMessage.flag": + [RollbarCocoaLumberjackLogger convertDDLogFlagToString:logMessage.flag], + @"DDLogMessage.context": + [NSNumber numberWithInteger:logMessage.context], + @"DDLogMessage.file": + logMessage.file, + @"DDLogMessage.fileName": + logMessage.fileName, + @"DDLogMessage.function": + (nil != logMessage.function) ? logMessage.function : @"", + @"DDLogMessage.line": + [NSNumber numberWithUnsignedInteger:logMessage.line], + @"DDLogMessage.representedObject": + (nil != logMessage.representedObject) ? [logMessage.representedObject description] : @"", + @"DDLogMessage.options": + [RollbarCocoaLumberjackLogger convertDDLogMessageOptionsToString:logMessage.options], + @"DDLogMessage.timestamp": + logMessage.timestamp.description, // !!!!!!!!!!!! ********* + @"DDLogMessage.threadID": + logMessage.threadID, + @"DDLogMessage.threadName": + (nil != logMessage.threadName) ? logMessage.threadName : @"", + @"DDLogMessage.queueLabel": + logMessage.queueLabel, + @"DDLogMessage.qos": + [NSNumber numberWithUnsignedInteger:logMessage.qos], +// @"DDLogMessage.tag": +// (nil != logMessage.tag) ? [logMessage.tag description] : @"", + }; +} + ++ (NSString *)convertDDLogMessageOptionsToString:(DDLogMessageOptions) options { + + NSString *stringValue = [NSString string]; + if (options & DDLogMessageCopyFile) { + if (stringValue.length > 0) { + stringValue = [stringValue stringByAppendingString:@" | "]; + } + stringValue = [stringValue stringByAppendingString:@"DDLogMessageCopyFile"]; + } + if (options & DDLogMessageCopyFunction) { + if (stringValue.length > 0) { + stringValue = [stringValue stringByAppendingString:@" | "]; + } + stringValue = [stringValue stringByAppendingString:@"DDLogMessageCopyFunction"]; + } + if (options & DDLogMessageDontCopyMessage) { + if (stringValue.length > 0) { + stringValue = [stringValue stringByAppendingString:@" | "]; + } + stringValue = [stringValue stringByAppendingString:@"DDLogMessageDontCopyMessage"]; + } + return stringValue; +} + ++ (NSString *)convertDDLogLevelToString:(DDLogLevel) logLevel { + + switch(logLevel) { + case DDLogLevelOff: + return @"DDLogLevelOff"; + case DDLogLevelAll: + return @"DDLogLevelAll"; + case DDLogLevelInfo: + return @"DDLogLevelError"; + case DDLogLevelError: + return @"DDLogLevelError"; + case DDLogLevelDebug: + return @"DDLogLevelDebug"; + case DDLogLevelWarning: + return @"DDLogLevelWarning"; + case DDLogLevelVerbose: + return @"DDLogLevelVerbose"; + default: + return @"Unexpected_DDLogLevel_value"; + } +} + ++ (NSString *)convertDDLogFlagToString:(DDLogFlag) ddLogFlag { + + switch(ddLogFlag) { + case DDLogFlagError: + return @"DDLogFlagError"; + case DDLogFlagWarning: + return @"DDLogFlagWarning"; + case DDLogFlagInfo: + return @"DDLogFlagInfo"; + case DDLogFlagDebug: + return @"DDLogFlagDebug"; + case DDLogFlagVerbose: + return @"DDLogFlagVerbose"; + default: + return @"Unexpected_DDLogFlag_value"; + } +} + ++ (RollbarLevel) convertDDLogFlagToRollbarLevel:(DDLogFlag) ddLogFlag { + + switch(ddLogFlag) { + case DDLogFlagError: + return RollbarLevel_Error; + case DDLogFlagWarning: + return RollbarLevel_Warning; + case DDLogFlagInfo: + return RollbarLevel_Info; + case DDLogFlagDebug: + case DDLogFlagVerbose: + return RollbarLevel_Debug; + default: + return RollbarLevel_Critical; + } +} +@end diff --git a/RollbarCocoaLumberjack/Sources/RollbarCocoaLumberjack/include/RollbarCocoaLumberjackLogger.h b/RollbarCocoaLumberjack/Sources/RollbarCocoaLumberjack/include/RollbarCocoaLumberjackLogger.h new file mode 100644 index 00000000..b4a7bdd9 --- /dev/null +++ b/RollbarCocoaLumberjack/Sources/RollbarCocoaLumberjack/include/RollbarCocoaLumberjackLogger.h @@ -0,0 +1,40 @@ +#import +@import CocoaLumberjack; +@import RollbarNotifier; + +NS_ASSUME_NONNULL_BEGIN + +/// Rollbar logger for CocoaLumberjack +@interface RollbarCocoaLumberjackLogger : DDAbstractLogger { + @private + RollbarLogger *_rollbarLogger; +} + +#pragma mark - factory methods + +/// Creates initialized instance of the Rollbar logger for CocoaLumberjack +/// @param rollbarLogger a RollbarLogger to use ++ (NSObject *)createWithRollbarLogger:(RollbarLogger *)rollbarLogger; + +/// Creates initialized instance of the Rollbar logger for CocoaLumberjack +/// @param rollbarConfig a RollbarConfig to use ++ (NSObject *)createWithRollbarConfig:(RollbarConfig *)rollbarConfig; + +#pragma mark - instance initializers + +/// Initializer +/// @param rollbarLogger a RollbarLogger to use +- (instancetype)initWithRollbarLogger:(RollbarLogger *)rollbarLogger +NS_DESIGNATED_INITIALIZER; + +/// Initializer +/// @param rollbarConfig a RollbarConfig to use +- (instancetype)initWithRollbarConfig:(RollbarConfig *)rollbarConfig; + +/// Hides initializer +- (instancetype)init +NS_UNAVAILABLE; + +@end + +NS_ASSUME_NONNULL_END diff --git a/RollbarCocoaLumberjack/Sources/RollbarCocoaLumberjack/include/module.modulemap b/RollbarCocoaLumberjack/Sources/RollbarCocoaLumberjack/include/module.modulemap new file mode 100644 index 00000000..543b66ad --- /dev/null +++ b/RollbarCocoaLumberjack/Sources/RollbarCocoaLumberjack/include/module.modulemap @@ -0,0 +1,8 @@ +module RollbarCocoaLumberjack { + umbrella "." + + export * + module * { export * } + + requires objc +} diff --git a/RollbarCocoaLumberjack/Tests/LinuxMain.swift b/RollbarCocoaLumberjack/Tests/LinuxMain.swift new file mode 100644 index 00000000..3876c733 --- /dev/null +++ b/RollbarCocoaLumberjack/Tests/LinuxMain.swift @@ -0,0 +1,7 @@ +import XCTest + +import RollbarCocoaLumberjackTests + +var tests = [XCTestCaseEntry]() +tests += RollbarCocoaLumberjackTests.allTests() +XCTMain(tests) diff --git a/RollbarCocoaLumberjack/Tests/RollbarCocoaLumberjackTests-ObjC/RollbarCocoaLumberjackTests.m b/RollbarCocoaLumberjack/Tests/RollbarCocoaLumberjackTests-ObjC/RollbarCocoaLumberjackTests.m new file mode 100644 index 00000000..cf06cf7e --- /dev/null +++ b/RollbarCocoaLumberjack/Tests/RollbarCocoaLumberjackTests-ObjC/RollbarCocoaLumberjackTests.m @@ -0,0 +1,70 @@ +#import + +#define LOG_LEVEL_DEF ddLogLevel + +@import CocoaLumberjack; +@import RollbarNotifier; +@import UnitTesting; + +@import RollbarCocoaLumberjack; + +static const DDLogLevel ddLogLevel = DDLogLevelDebug; + +@interface RollbarCocoaLumberjackTests : XCTestCase +@end + +@implementation RollbarCocoaLumberjackTests + +- (void)setUp { + + [super setUp]; + + // Put setup code here. This method is called before the invocation of each test method in the class. + NSLog(@"Set to go..."); + + [RollbarLogger clearSdkDataStore]; + + [DDLog addLogger:[DDOSLogger sharedInstance]]; + + DDFileLogger *fileLogger = [[DDFileLogger alloc] init]; + fileLogger.rollingFrequency = 60 * 60 * 24; // 24 hour rolling + fileLogger.logFileManager.maximumNumberOfLogFiles = 1; + // the above code tells the application to keep a day worth of log files on the system. + + [DDLog addLogger:fileLogger]; +} + +- (void)tearDown { + // Put teardown code here. This method is called after the invocation of each test method in the class. + NSLog(@"Teared down."); +} + +- (void)testLiveRollbarCocoaLumberjackBasics { + + + DDLogError(@"Broken sprocket detected!"); + DDLogVerbose(@"User selected file:%@ withSize:%u", @"somewhere/file.ext", 100); + + RollbarConfig *config = [[RollbarConfig alloc] init]; + config.destination.accessToken = [RollbarTestHelper getRollbarPayloadsAccessToken]; + config.destination.environment = [RollbarTestHelper getRollbarEnvironment]; + config.developerOptions.transmit = YES; + config.developerOptions.logPayload = YES; + config.loggingOptions.maximumReportsPerMinute = 5000; + + [DDLog addLogger:[RollbarCocoaLumberjackLogger createWithRollbarConfig:config]]; + + DDLogDebug(@"*** Via CocoaLumberjack!!!"); + + [NSThread sleepForTimeInterval:5.0f]; +} + +- (void)testPerformanceExample { + // This is an example of a performance test case. + [self measureBlock:^{ + // Put the code you want to measure the time of here. + }]; +} + +@end + diff --git a/RollbarCocoaLumberjack/Tests/RollbarCocoaLumberjackTests/RollbarCocoaLumberjackTests.swift b/RollbarCocoaLumberjack/Tests/RollbarCocoaLumberjackTests/RollbarCocoaLumberjackTests.swift new file mode 100644 index 00000000..768a650d --- /dev/null +++ b/RollbarCocoaLumberjack/Tests/RollbarCocoaLumberjackTests/RollbarCocoaLumberjackTests.swift @@ -0,0 +1,59 @@ +import XCTest +import UnitTesting +import RollbarNotifier +import CocoaLumberjackSwift +@testable import RollbarCocoaLumberjack + +final class RollbarCocoaLumberjackTests: XCTestCase { + + override func setUp() { + + super.setUp(); + + RollbarLogger.clearSdkDataStore(); + + let rollbarConfig = RollbarConfig(); + rollbarConfig.destination.accessToken = RollbarTestHelper.getRollbarPayloadsAccessToken(); + rollbarConfig.destination.environment = RollbarTestHelper.getRollbarEnvironment(); + rollbarConfig.developerOptions.transmit = false; + rollbarConfig.developerOptions.logPayload = true; + + XCTAssertTrue(RollbarLogger.readPayloadsFromSdkLog().count == 0); + XCTAssertEqual(RollbarLogger.readPayloadsFromSdkLog().count, 0); + + dynamicLogLevel = DDLogLevel.debug; + DDLog.add(DDOSLogger.sharedInstance); + let ddFileLogger = DDFileLogger(); + ddFileLogger.rollingFrequency = 60 * 60 * 24; // 24-hours rolling + ddFileLogger.logFileManager.maximumNumberOfLogFiles = 1; + // the above code tells the application to keep a day worth of log files on the system. + DDLog.add(ddFileLogger); + + DDLog.add(RollbarCocoaLumberjackLogger.create(with: rollbarConfig)); + } + + func testBasics() { + + XCTAssertEqual(RollbarLogger.readPayloadsFromSdkLog().count, 0); + + DDLogError("Get it to Rollbar #1!"); + DDLogError("Get it to Rollbar #2!"); + DDLogError("Get it to Rollbar #3!"); + + Thread.sleep(forTimeInterval: 3.0); + + XCTAssertEqual(RollbarLogger.readPayloadsFromSdkLog().count, 3); + } + +// func testExample() throws { +// // This is an example of a functional test case. +// // Use XCTAssert and related functions to verify your tests produce the correct +// // results. +// //XCTAssertEqual(RollbarCocoaLumberjack().text, "Hello, World!") +// } + +// static var allTests = [ +// ("testBasics", testBasics), +// ("testExample", testExample), +// ] +} diff --git a/RollbarCommon.podspec b/RollbarCommon.podspec index d11d958c..339ec334 100644 --- a/RollbarCommon.podspec +++ b/RollbarCommon.podspec @@ -7,7 +7,7 @@ Pod::Spec.new do |s| - s.version = "2.0.3" + s.version = "2.1.0" s.name = "RollbarCommon" s.summary = "Application or client side SDK for interacting with the Rollbar API Server." s.description = <<-DESC diff --git a/RollbarCommon/Package.swift b/RollbarCommon/Package.swift index 97da63bb..155f897a 100644 --- a/RollbarCommon/Package.swift +++ b/RollbarCommon/Package.swift @@ -29,7 +29,7 @@ let package = Package( dependencies: [ // Dependencies declare other packages that this package depends on. // .package(url: /* package url */, from: "1.0.0"), - .package(path: "../UnitTesting"), + //.package(path: "../UnitTesting"), ], targets: [ // Targets are the basic building blocks of a package. A target can define a module or a test suite. @@ -50,13 +50,14 @@ let package = Package( .testTarget( name: "RollbarCommonTests", dependencies: [ - "UnitTesting", + //"UnitTesting", "RollbarCommon", ] ), .testTarget( name: "RollbarCommonTests-ObjC", dependencies: ["RollbarCommon"], + exclude: ["TestData/rollbar-crash-report-147120812218-raw.txt"], cSettings: [ .headerSearchPath("Tests/RollbarCommonTests-ObjC/**"), // .headerSearchPath("Sources/RollbarCommon"), diff --git a/RollbarCommon/Sources/RollbarCommon/include/RollbarCrashCollectorBase.h b/RollbarCommon/Sources/RollbarCommon/include/RollbarCrashCollectorBase.h index 6965eaae..aac64e03 100644 --- a/RollbarCommon/Sources/RollbarCommon/include/RollbarCrashCollectorBase.h +++ b/RollbarCommon/Sources/RollbarCommon/include/RollbarCrashCollectorBase.h @@ -20,9 +20,8 @@ NS_ASSUME_NONNULL_BEGIN - (instancetype)initWithObserver:(nullable id)observer NS_DESIGNATED_INITIALIZER; -/// Hides parametrless initializer. -- (instancetype)init -NS_UNAVAILABLE; +/// Initializer. +- (instancetype)init; @end diff --git a/RollbarCommon/Tests/RollbarCommonTests-ObjC/RollbarCommonTests.m b/RollbarCommon/Tests/RollbarCommonTests-ObjC/RollbarCommonTests.m index 17ec4299..803321db 100644 --- a/RollbarCommon/Tests/RollbarCommonTests-ObjC/RollbarCommonTests.m +++ b/RollbarCommon/Tests/RollbarCommonTests-ObjC/RollbarCommonTests.m @@ -1,12 +1,3 @@ -// -// DTOsTests.m -// Rollbar -// -// Created by Andrey Kornich on 2019-10-10. -// Copyright © 2019 Rollbar. All rights reserved. -// - - @import Foundation; #if !TARGET_OS_WATCH diff --git a/RollbarCommon/Tests/RollbarCommonTests-ObjC/RollbarCrashReportUtilTest.m b/RollbarCommon/Tests/RollbarCommonTests-ObjC/RollbarCrashReportUtilTest.m index ce559fea..6ac6f743 100644 --- a/RollbarCommon/Tests/RollbarCommonTests-ObjC/RollbarCrashReportUtilTest.m +++ b/RollbarCommon/Tests/RollbarCommonTests-ObjC/RollbarCrashReportUtilTest.m @@ -1,10 +1,3 @@ -// -// Test.m -// -// -// Created by Andrey Kornich on 2021-01-04. -// - #import @import Foundation; diff --git a/RollbarCommon/Tests/RollbarCommonTests-ObjC/RollbarHostingProcessUtilTest.m b/RollbarCommon/Tests/RollbarCommonTests-ObjC/RollbarHostingProcessUtilTest.m index 81397456..8a4341b5 100644 --- a/RollbarCommon/Tests/RollbarCommonTests-ObjC/RollbarHostingProcessUtilTest.m +++ b/RollbarCommon/Tests/RollbarCommonTests-ObjC/RollbarHostingProcessUtilTest.m @@ -1,10 +1,3 @@ -// -// Test.m -// -// -// Created by Andrey Kornich on 2021-05-06. -// - #import @import RollbarCommon; diff --git a/RollbarCommon/Tests/RollbarCommonTests-ObjC/RollbarPredicateBuilderTests.m b/RollbarCommon/Tests/RollbarCommonTests-ObjC/RollbarPredicateBuilderTests.m index 98fc4825..f1294c0a 100644 --- a/RollbarCommon/Tests/RollbarCommonTests-ObjC/RollbarPredicateBuilderTests.m +++ b/RollbarCommon/Tests/RollbarCommonTests-ObjC/RollbarPredicateBuilderTests.m @@ -1,10 +1,3 @@ -// -// RollbarPredicateBuilderTests.m -// -// -// Created by Andrey Kornich on 2021-04-29. -// - #import @import Foundation; diff --git a/RollbarCommon/Tests/RollbarCommonTests/NSDictionary+RollbarTest.swift b/RollbarCommon/Tests/RollbarCommonTests/NSDictionary+RollbarTest.swift index 8d7a660f..1583debe 100644 --- a/RollbarCommon/Tests/RollbarCommonTests/NSDictionary+RollbarTest.swift +++ b/RollbarCommon/Tests/RollbarCommonTests/NSDictionary+RollbarTest.swift @@ -1,10 +1,3 @@ -// -// File.swift -// -// -// Created by Andrey Kornich on 2020-09-30. -// - import XCTest import Foundation import RollbarCommon @@ -40,6 +33,5 @@ final class NSDictionaryRollbarTests: XCTestCase { static var allTests = [ ("testNSDictionaryRollbar_keyPresent", testNSDictionaryRollbar_keyPresent), - //("testExample", testExample), ] } diff --git a/RollbarCommon/Tests/RollbarCommonTests/NSJSONSerialization+RollbarTests.swift b/RollbarCommon/Tests/RollbarCommonTests/NSJSONSerialization+RollbarTests.swift index 599d36e9..c904f87b 100644 --- a/RollbarCommon/Tests/RollbarCommonTests/NSJSONSerialization+RollbarTests.swift +++ b/RollbarCommon/Tests/RollbarCommonTests/NSJSONSerialization+RollbarTests.swift @@ -1,10 +1,3 @@ -// -// NSJSONSerialization+RollbarTests.swift -// -// -// Created by Andrey Kornich on 2020-05-26. -// - import XCTest import Foundation @testable import RollbarCommon @@ -89,17 +82,9 @@ final class NSJSONSerializationRollbarTests: XCTestCase { } } -// func testExample() { -// // This is an example of a functional test case. -// // Use XCTAssert and related functions to verify your tests produce the correct -// // results. -// XCTAssertEqual(RollbarDeploys().text, "Hello, World!") -// } - static var allTests = [ ("testNSJSONSerializationRollbar_measureJSONDataByteSize", testNSJSONSerializationRollbar_measureJSONDataByteSize), ("testNSJSONSerializationRollbar_dataWithJSONObject", testNSJSONSerializationRollbar_dataWithJSONObject), ("testNSJSONSerializationRollbar_safeDataFromJSONObject", testNSJSONSerializationRollbar_safeDataFromJSONObject), - //("testExample", testExample), ] } diff --git a/RollbarCommon/Tests/RollbarCommonTests/RollbarCommonTests.swift b/RollbarCommon/Tests/RollbarCommonTests/RollbarCommonTests.swift index a5d3e534..cdc1f826 100644 --- a/RollbarCommon/Tests/RollbarCommonTests/RollbarCommonTests.swift +++ b/RollbarCommon/Tests/RollbarCommonTests/RollbarCommonTests.swift @@ -2,14 +2,15 @@ import XCTest @testable import RollbarCommon final class RollbarCommonTests: XCTestCase { - func testExample() { - // This is an example of a functional test case. - // Use XCTAssert and related functions to verify your tests produce the correct - // results. - //XCTAssertEqual(RollbarCommon().text, "Hello, World!") - } - - static var allTests = [ - ("testExample", testExample), - ] + +// func testExample() { +// // This is an example of a functional test case. +// // Use XCTAssert and related functions to verify your tests produce the correct +// // results. +// //XCTAssertEqual(RollbarCommon().text, "Hello, World!") +// } +// +// static var allTests = [ +// ("testExample", testExample), +// ] } diff --git a/RollbarCommon/Tests/RollbarCommonTests/RollbarTriStateFlagTests.swift b/RollbarCommon/Tests/RollbarCommonTests/RollbarTriStateFlagTests.swift index 528b0dca..ecdbd210 100644 --- a/RollbarCommon/Tests/RollbarCommonTests/RollbarTriStateFlagTests.swift +++ b/RollbarCommon/Tests/RollbarCommonTests/RollbarTriStateFlagTests.swift @@ -1,10 +1,3 @@ -// -// RollbarTriStateFlagTests.swift -// -// -// Created by Andrey Kornich on 2020-05-26. -// - import XCTest import Foundation @testable import RollbarCommon @@ -13,8 +6,6 @@ final class RollbarTriStateFlagTests: XCTestCase { func testRollbarTriStateFlagUtil_FromStringConversion() { - //XCTAssertTrue(); - XCTAssertEqual(RollbarTriStateFlag.none, RollbarTriStateFlagUtil.triStateFlag(from: "None")); XCTAssertEqual(RollbarTriStateFlag.none, RollbarTriStateFlagUtil.triStateFlag(from: "none")); XCTAssertEqual(RollbarTriStateFlag.none, RollbarTriStateFlagUtil.triStateFlag(from: "NONE")); @@ -47,16 +38,8 @@ final class RollbarTriStateFlagTests: XCTestCase { XCTAssertEqual("ON", RollbarTriStateFlagUtil.triStateFlag(toString: RollbarTriStateFlag.on)); } -// func testExample() { -// // This is an example of a functional test case. -// // Use XCTAssert and related functions to verify your tests produce the correct -// // results. -// XCTAssertEqual(RollbarDeploys().text, "Hello, World!") -// } - static var allTests = [ ("testRollbarTriStateFlagUtil_FromStringConversion", testRollbarTriStateFlagUtil_FromStringConversion), ("testRollbarTriStateFlagUtil_ToStringConversion", testRollbarTriStateFlagUtil_ToStringConversion), - //("testExample", testExample), ] } diff --git a/RollbarDeploys.podspec b/RollbarDeploys.podspec index a75824d2..f3f230c9 100644 --- a/RollbarDeploys.podspec +++ b/RollbarDeploys.podspec @@ -7,7 +7,7 @@ Pod::Spec.new do |s| - s.version = "2.0.3" + s.version = "2.1.0" s.name = "RollbarDeploys" s.summary = "Application or client side SDK for interacting with the Rollbar API Server." s.description = <<-DESC diff --git a/RollbarDeploys/Package.swift b/RollbarDeploys/Package.swift index 51740e02..22a1cd38 100644 --- a/RollbarDeploys/Package.swift +++ b/RollbarDeploys/Package.swift @@ -49,7 +49,10 @@ let package = Package( ), .testTarget( name: "RollbarDeploysTests-ObjC", - dependencies: ["RollbarDeploys"], + dependencies: [ + "UnitTesting", + "RollbarDeploys", + ], cSettings: [ .headerSearchPath("Tests/RollbarDeploysTests-ObjC/**"), // .headerSearchPath("Sources/RollbarDeploys"), diff --git a/RollbarDeploys/Tests/RollbarDeploysTests-ObjC/RollbarDeploysTests.m b/RollbarDeploys/Tests/RollbarDeploysTests-ObjC/RollbarDeploysTests.m index 7b6e8360..603ae528 100644 --- a/RollbarDeploys/Tests/RollbarDeploysTests-ObjC/RollbarDeploysTests.m +++ b/RollbarDeploys/Tests/RollbarDeploysTests-ObjC/RollbarDeploysTests.m @@ -1,8 +1,6 @@ -// Copyright (c) 2018 Rollbar, Inc. All rights reserved. - #import -#import "../../../UnitTests/RollbarUnitTestSettings.h" +@import UnitTesting; @import RollbarDeploys; @interface RollbarDeploysObserver : NSObject @@ -49,7 +47,7 @@ @interface RollbarDeploysTests : XCTestCase @implementation RollbarDeploysTests - (void)testDeploymentDto { - NSString * const environment = ROLLBAR_UNIT_TEST_ENVIRONMENT; + NSString * const environment = [RollbarTestHelper getRollbarEnvironment]; NSString * const comment = @"a new deploy"; NSString * const revision = @"a_revision"; NSString * const localUsername = @"UnitTestRunner"; @@ -78,7 +76,7 @@ - (void)testDeploymentRegistration { NSDateFormatter *dateFormatter=[[NSDateFormatter alloc] init]; [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"]; - NSString * const environment = ROLLBAR_UNIT_TEST_ENVIRONMENT; + NSString * const environment = [RollbarTestHelper getRollbarEnvironment]; NSString * const comment = [NSString stringWithFormat:@"a new deploy at %@", [dateFormatter stringFromDate:[NSDate date]]]; NSString * const revision = @"a_revision"; @@ -92,8 +90,8 @@ - (void)testDeploymentRegistration { localUserName:localUsername rollbarUserName:rollbarUsername]; RollbarDeploysManager *deploysManager = - [[RollbarDeploysManager alloc] initWithWriteAccessToken:ROLLBAR_UNIT_TEST_DEPLOYS_WRITE_ACCESS_TOKEN - readAccessToken:ROLLBAR_UNIT_TEST_DEPLOYS_READ_ACCESS_TOKEN + [[RollbarDeploysManager alloc] initWithWriteAccessToken:[RollbarTestHelper getRollbarDeploysWriteAccessToken] + readAccessToken:[RollbarTestHelper getRollbarDeploysReadAccessToken] deploymentRegistrationObserver:observer deploymentDetailsObserver:observer deploymentDetailsPageObserver:observer @@ -105,8 +103,8 @@ - (void)testGetDeploymentDetailsById { NSString * const testDeploymentId = @"23922850"; RollbarDeploysObserver *observer = [[RollbarDeploysObserver alloc] init]; RollbarDeploysManager *deploysManager = - [[RollbarDeploysManager alloc] initWithWriteAccessToken:ROLLBAR_UNIT_TEST_DEPLOYS_WRITE_ACCESS_TOKEN - readAccessToken:ROLLBAR_UNIT_TEST_DEPLOYS_READ_ACCESS_TOKEN + [[RollbarDeploysManager alloc] initWithWriteAccessToken:[RollbarTestHelper getRollbarDeploysWriteAccessToken] + readAccessToken:[RollbarTestHelper getRollbarDeploysReadAccessToken] deploymentRegistrationObserver:observer deploymentDetailsObserver:observer deploymentDetailsPageObserver:observer @@ -117,8 +115,8 @@ - (void)testGetDeploymentDetailsById { - (void)testGetDeploymentsPage { RollbarDeploysObserver *observer = [[RollbarDeploysObserver alloc] init]; RollbarDeploysManager *deploysManager = - [[RollbarDeploysManager alloc] initWithWriteAccessToken:ROLLBAR_UNIT_TEST_DEPLOYS_WRITE_ACCESS_TOKEN - readAccessToken:ROLLBAR_UNIT_TEST_DEPLOYS_READ_ACCESS_TOKEN + [[RollbarDeploysManager alloc] initWithWriteAccessToken:[RollbarTestHelper getRollbarDeploysWriteAccessToken] + readAccessToken:[RollbarTestHelper getRollbarDeploysReadAccessToken] deploymentRegistrationObserver:observer deploymentDetailsObserver:observer deploymentDetailsPageObserver:observer diff --git a/RollbarDeploys/Tests/RollbarDeploysTests/RollbarDeploysTests.swift b/RollbarDeploys/Tests/RollbarDeploysTests/RollbarDeploysTests.swift index 74a304e5..b0933d8a 100644 --- a/RollbarDeploys/Tests/RollbarDeploysTests/RollbarDeploysTests.swift +++ b/RollbarDeploys/Tests/RollbarDeploysTests/RollbarDeploysTests.swift @@ -7,7 +7,7 @@ final class RollbarDeploysTests: XCTestCase { func testDeploymentDto() { - let environment = RollbarUnitTestSettings.environment; + let environment = RollbarTestHelper.getRollbarEnvironment(); let comment = "a new deploy"; let revision = "a_revision"; let localUsername = "UnitTestRunner"; @@ -41,7 +41,7 @@ final class RollbarDeploysTests: XCTestCase { let dateFormatter = DateFormatter() dateFormatter.dateFormat = "yyyy-MM-dd HH:mm:ss" - let environment = RollbarUnitTestSettings.environment; + let environment = RollbarTestHelper.getRollbarEnvironment(); let comment = "a new deploy at \(dateFormatter.string(from:Date.init()))"; let revision = "a_revision"; let localUsername = "UnitTestRunner"; @@ -58,8 +58,8 @@ final class RollbarDeploysTests: XCTestCase { ); let deploysManager = RollbarDeploysManager( - writeAccessToken:RollbarUnitTestSettings.deploysWriteAccessToken, - readAccessToken:RollbarUnitTestSettings.deploysReadAccessToken, + writeAccessToken:RollbarTestHelper.getRollbarDeploysWriteAccessToken(), + readAccessToken:RollbarTestHelper.getRollbarDeploysReadAccessToken(), deploymentRegistrationObserver:observer, deploymentDetailsObserver:observer, deploymentDetailsPageObserver:observer @@ -76,8 +76,8 @@ final class RollbarDeploysTests: XCTestCase { let observer = RollbarDeploysObserver(); let deploysManager = RollbarDeploysManager( - writeAccessToken:RollbarUnitTestSettings.deploysWriteAccessToken, - readAccessToken:RollbarUnitTestSettings.deploysReadAccessToken, + writeAccessToken:RollbarTestHelper.getRollbarDeploysWriteAccessToken(), + readAccessToken:RollbarTestHelper.getRollbarDeploysReadAccessToken(), deploymentRegistrationObserver:observer, deploymentDetailsObserver:observer, deploymentDetailsPageObserver:observer @@ -91,8 +91,8 @@ final class RollbarDeploysTests: XCTestCase { let observer = RollbarDeploysObserver(); let deploysManager = RollbarDeploysManager( - writeAccessToken:RollbarUnitTestSettings.deploysWriteAccessToken, - readAccessToken:RollbarUnitTestSettings.deploysReadAccessToken, + writeAccessToken:RollbarTestHelper.getRollbarDeploysWriteAccessToken(), + readAccessToken:RollbarTestHelper.getRollbarDeploysReadAccessToken(), deploymentRegistrationObserver:observer, deploymentDetailsObserver:observer, deploymentDetailsPageObserver:observer diff --git a/RollbarKSCrash.podspec b/RollbarKSCrash.podspec index d78836aa..54fe7e25 100644 --- a/RollbarKSCrash.podspec +++ b/RollbarKSCrash.podspec @@ -7,7 +7,7 @@ Pod::Spec.new do |s| - s.version = "2.0.3" + s.version = "2.1.0" s.name = "RollbarKSCrash" s.summary = "Application or client side SDK for interacting with the Rollbar API Server." s.description = <<-DESC diff --git a/RollbarNotifier.podspec b/RollbarNotifier.podspec index 1c38bf94..72c1e3a5 100644 --- a/RollbarNotifier.podspec +++ b/RollbarNotifier.podspec @@ -7,7 +7,7 @@ Pod::Spec.new do |s| - s.version = "2.0.3" + s.version = "2.1.0" s.name = "RollbarNotifier" s.summary = "Application or client side SDK for interacting with the Rollbar API Server." s.description = <<-DESC diff --git a/RollbarNotifier/Package.swift b/RollbarNotifier/Package.swift index a6e627bc..1406f752 100644 --- a/RollbarNotifier/Package.swift +++ b/RollbarNotifier/Package.swift @@ -29,14 +29,14 @@ let package = Package( // Targets can depend on other targets in this package, and on products in packages which this package depends on. .target( name: "RollbarNotifier", - dependencies: ["RollbarCommon",], + dependencies: [ + "RollbarCommon", + ], publicHeadersPath: "include", cSettings: [ .headerSearchPath("Sources/RollbarNotifier/**"), -// .headerSearchPath("Sources/RollbarNotifier"), -// .headerSearchPath("Sources/RollbarNotifier/include"), -// .headerSearchPath("Sources/RollbarNotifier/DTOs"), - + // .headerSearchPath("Sources/RollbarNotifier/DTOs"), + // .define("DEFINES_MODULE"), ] ), @@ -49,11 +49,12 @@ let package = Package( ), .testTarget( name: "RollbarNotifierTests-ObjC", - dependencies: ["RollbarNotifier"], + dependencies: [ + "UnitTesting", + "RollbarNotifier", + ], cSettings: [ .headerSearchPath("Tests/RollbarNotifierTests-ObjC/**"), -// .headerSearchPath("Sources/RollbarNotifier"), -// .headerSearchPath("Sources/RollbarNotifier/include"), // .headerSearchPath("Sources/RollbarNotifier/DTOs"), // .define("DEFINES_MODULE"), diff --git a/RollbarNotifier/Sources/RollbarNotifier/DTOs/RollbarConfig.m b/RollbarNotifier/Sources/RollbarNotifier/DTOs/RollbarConfig.m index 0ddb117f..153aacb6 100644 --- a/RollbarNotifier/Sources/RollbarNotifier/DTOs/RollbarConfig.m +++ b/RollbarNotifier/Sources/RollbarNotifier/DTOs/RollbarConfig.m @@ -14,7 +14,7 @@ #pragma mark - constants -static NSString * const NOTIFIER_VERSION = @"2.0.3"; +static NSString * const NOTIFIER_VERSION = @"2.1.0"; static NSString * const NOTIFIER_NAME = @"rollbar-apple"; diff --git a/RollbarNotifier/Sources/RollbarNotifier/RollbarLogger.m b/RollbarNotifier/Sources/RollbarNotifier/RollbarLogger.m index 7246fa95..f7b5d4bb 100644 --- a/RollbarNotifier/Sources/RollbarNotifier/RollbarLogger.m +++ b/RollbarNotifier/Sources/RollbarNotifier/RollbarLogger.m @@ -7,6 +7,7 @@ @import RollbarCommon; #import "RollbarLogger.h" +#import "RollbarLogger+Test.h" #import "RollbarThread.h" #import "RollbarReachability.h" #import @@ -18,18 +19,18 @@ #define MAX_PAYLOAD_SIZE 128 // The maximum payload size in kb -static NSString *QUEUED_ITEMS_FILE_NAME = @"rollbar.items"; -static NSString *STATE_FILE_NAME = @"rollbar.state"; -static NSString *PAYLOADS_FILE_NAME = @"rollbar.payloads"; +static NSString * const QUEUED_ITEMS_FILE_NAME = @"rollbar.items"; +static NSString * const QUEUED_ITEMS_STATE_FILE_NAME = @"rollbar.state"; +static NSString * const PAYLOADS_FILE_NAME = @"rollbar.payloads"; -// Rollbar API Service enforced payload rate limit: -static NSString *RESPONSE_HEADER_RATE_LIMIT = @"x-rate-limit-limit"; -// Rollbar API Service enforced remaining payload count until the limit is reached: -static NSString *RESPONSE_HEADER_REMAINING_COUNT = @"x-rate-limit-remaining"; -// Rollbar API Service enforced rate limit reset time for the current limit window: -static NSString *RESPONSE_HEADER_RESET_TIME = @"x-rate-limit-reset"; -// Rollbar API Service enforced rate limit remaining seconds of the current limit window: -static NSString *RESPONSE_HEADER_REMAINING_SECONDS = @"x-rate-limit-remaining-seconds"; +/// Rollbar API Service enforced payload rate limit: +static NSString * const RESPONSE_HEADER_RATE_LIMIT = @"x-rate-limit-limit"; +/// Rollbar API Service enforced remaining payload count until the limit is reached: +static NSString * const RESPONSE_HEADER_REMAINING_COUNT = @"x-rate-limit-remaining"; +/// Rollbar API Service enforced rate limit reset time for the current limit window: +static NSString * const RESPONSE_HEADER_RESET_TIME = @"x-rate-limit-reset"; +/// Rollbar API Service enforced rate limit remaining seconds of the current limit window: +static NSString * const RESPONSE_HEADER_REMAINING_SECONDS = @"x-rate-limit-remaining-seconds"; static NSUInteger MAX_RETRY_COUNT = 5; @@ -45,14 +46,6 @@ static BOOL isNetworkReachable = YES; #endif -@interface RollbarLogger () - -- (NSThread *)_rollbarThread; - -- (void)_test_doNothing; - -@end - @implementation RollbarLogger { NSDate *nextSendTime; @@ -84,8 +77,10 @@ + (void)initialize { queuedItemsFilePath = [cachesDirectory stringByAppendingPathComponent:QUEUED_ITEMS_FILE_NAME]; stateFilePath = - [cachesDirectory stringByAppendingPathComponent:STATE_FILE_NAME]; - + [cachesDirectory stringByAppendingPathComponent:QUEUED_ITEMS_STATE_FILE_NAME]; + payloadsFilePath = + [cachesDirectory stringByAppendingPathComponent:PAYLOADS_FILE_NAME]; + // either create or overwrite the payloads log file: [[NSFileManager defaultManager] createFileAtPath:payloadsFilePath contents:nil @@ -797,33 +792,48 @@ - (BOOL)sendItem:(NSDictionary *)payload NSUInteger retryCount = [queueState[@"retry_count"] unsignedIntegerValue]; - if (0 == retryCount && YES == self.configuration.developerOptions.logPayload) { - if (NO == self.configuration.developerOptions.suppressSdkInfoLogging) { + RollbarConfig *rollbarConfig = + [[RollbarConfig alloc] initWithDictionary:rollbarPayload.data.notifier.jsonFriendlyData[@"configured_options"]]; + + if (0 == retryCount && YES == rollbarConfig.developerOptions.logPayload) { + if (NO == rollbarConfig.developerOptions.suppressSdkInfoLogging) { RollbarSdkLog(@"About to send payload: %@", [[NSString alloc] initWithData:jsonPayload encoding:NSUTF8StringEncoding] ); } + // - save this payload into a proper payloads log file: + //***************************************************** + + // compose the payloads log file path: + NSString *cachesDirectory = [RollbarCachesDirectory directory]; + NSString *payloadsLogFilePath = + [cachesDirectory stringByAppendingPathComponent:rollbarConfig.developerOptions.payloadLogFile]; + // create the payloads log file if it does not exist already: + if (![[NSFileManager defaultManager] fileExistsAtPath:payloadsLogFilePath]) { + + [[NSFileManager defaultManager] createFileAtPath:payloadsLogFilePath + contents:nil + attributes:nil]; + } // append-save this jsonPayload into the payloads log file: NSFileHandle *fileHandle = - [NSFileHandle fileHandleForWritingAtPath:payloadsFilePath]; - + [NSFileHandle fileHandleForWritingAtPath:payloadsLogFilePath]; [fileHandle seekToEndOfFile]; [fileHandle writeData:jsonPayload]; [fileHandle writeData:[@"\n" dataUsingEncoding:NSUTF8StringEncoding]]; [fileHandle closeFile]; } - RollbarConfig *rollbarConfig = - [[RollbarConfig alloc] initWithDictionary:rollbarPayload.data.notifier.jsonFriendlyData[@"configured_options"]]; - BOOL success = rollbarConfig ? [self sendPayload:jsonPayload usingConfig:rollbarConfig] : [self sendPayload:jsonPayload]; // backward compatibility with just upgraded very old SDKs... if (!success) { + if (retryCount < MAX_RETRY_COUNT) { + queueState[@"retry_count"] = [NSNumber numberWithUnsignedInteger:retryCount + 1]; @@ -1018,6 +1028,8 @@ - (BOOL)checkPayloadResponse:(NSURLResponse *)response error:(NSError *)error data:(NSData *)data { + NSLog(@"HTTP response from Rollbar: %@", response); + // Lookup rate limiting headers and adjust reporting rate accordingly: NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *)response; NSDictionary *httpHeaders = [httpResponse allHeaderFields]; @@ -1134,12 +1146,134 @@ - (void)captureTelemetryDataForNetwork:(BOOL)reachable { #endif } -// THIS IS ONLY FOR TESTS, DO NOT ACTUALLY USE THIS METHOD, HENCE BEING "PRIVATE" -- (NSThread *)_rollbarThread { +@end + +#pragma mark - RollbarLogger (Test) + +static NSString * const QUEUED_TELEMETRY_ITEMS_FILE_NAME = @"rollbar.telemetry"; + +@implementation RollbarLogger (Test) + ++ (void)clearSdkDataStore { + + [RollbarLogger clearLogItemsStore]; + [RollbarLogger _clearFile:[RollbarLogger _telemetryItemsStorePath]]; + [RollbarLogger _clearFile:[RollbarLogger _payloadsLogStorePath]]; +} + ++ (void)clearLogItemsStore { + + [RollbarLogger _clearFile:[RollbarLogger _logItemsStoreStatePath]]; + [RollbarLogger _clearFile:[RollbarLogger _logItemsStorePath]]; +} + ++ (void)clearSdkFile:(nonnull NSString *)sdkFileName { + + [RollbarLogger _clearFile:[RollbarLogger _getSDKDataFilePath:sdkFileName]]; +} + ++ (nonnull NSArray *)readLogItemsFromStore { + + NSString *filePath = [RollbarLogger _logItemsStorePath]; + return [RollbarLogger readPayloadsDataFromFile:filePath]; +} + ++ (nonnull NSArray *)readPayloadsFromSdkLog { + + NSString *filePath = [RollbarLogger _payloadsLogStorePath]; + return [RollbarLogger readPayloadsDataFromFile:filePath]; +} + ++ (nonnull NSArray *)readPayloadsDataFromFile:(nonnull NSString *)filePath { + + RollbarFileReader *reader = [[RollbarFileReader alloc] initWithFilePath:filePath + andOffset:0]; + + NSMutableArray *items = [NSMutableArray array]; + [reader enumerateLinesUsingBlock:^(NSString *line, NSUInteger nextOffset, BOOL *stop) { + NSError *error = nil; + NSMutableDictionary *payload = + [NSJSONSerialization JSONObjectWithData:[line dataUsingEncoding:NSUTF8StringEncoding] + options:(NSJSONReadingMutableContainers | NSJSONReadingMutableLeaves) + error:&error + ]; + if ((nil == payload) && (nil != error)) { + RollbarSdkLog(@"Error serializing log item from the store: %@", [error localizedDescription]); + return; + } + else if (nil == payload) { + RollbarSdkLog(@"Error serializing log item from the store!"); + return; + } + + NSMutableDictionary *data = payload[@"data"]; + [items addObject:data]; + }]; + + return items; +} + ++ (void)flushRollbarThread { + + [RollbarLogger performSelector:@selector(_test_doNothing) + onThread:[RollbarLogger _test_rollbarThread] + withObject:nil + waitUntilDone:YES + ]; +} + ++ (void)_clearFile:(nonnull NSString *)filePath { + + NSFileManager *fileManager = [NSFileManager defaultManager]; + NSError *error; + BOOL fileExists = [fileManager fileExistsAtPath:filePath]; + + if (fileExists) { + BOOL success = [fileManager removeItemAtPath:filePath + error:&error]; + if (!success) { + NSLog(@"Error: %@", [error localizedDescription]); + } + [[NSFileManager defaultManager] createFileAtPath:filePath + contents:nil + attributes:nil]; + } +} + ++ (nonnull NSString *)_logItemsStorePath { + + return [RollbarLogger _getSDKDataFilePath:QUEUED_ITEMS_FILE_NAME]; +} + ++ (nonnull NSString *)_logItemsStoreStatePath { + + return [RollbarLogger _getSDKDataFilePath:QUEUED_ITEMS_STATE_FILE_NAME]; +} + ++ (nonnull NSString *)_telemetryItemsStorePath { + + return [RollbarLogger _getSDKDataFilePath:QUEUED_TELEMETRY_ITEMS_FILE_NAME]; +} + ++ (nonnull NSString *)_payloadsLogStorePath { + + return [RollbarLogger _getSDKDataFilePath:PAYLOADS_FILE_NAME]; +} + ++ (nonnull NSString *)_getSDKDataFilePath:(nonnull NSString *)sdkFileName { + + NSString *cachesDirectory = [RollbarCachesDirectory directory]; + return [cachesDirectory stringByAppendingPathComponent:sdkFileName]; +} + ++ (NSThread *)_test_rollbarThread { + return rollbarThread; } -- (void)_test_doNothing { ++ (void)_test_doNothing { + + // no-Op simulation... } @end diff --git a/RollbarNotifier/Sources/RollbarNotifier/include/RollbarLogger+Test.h b/RollbarNotifier/Sources/RollbarNotifier/include/RollbarLogger+Test.h new file mode 100644 index 00000000..758bc56b --- /dev/null +++ b/RollbarNotifier/Sources/RollbarNotifier/include/RollbarLogger+Test.h @@ -0,0 +1,41 @@ +#import +#import "RollbarLogger.h" + +NS_ASSUME_NONNULL_BEGIN + +/// Test category of RollbarLogger +///@note THIS CATEGORY IS TO BE USED FOR TESTING PURPOSES ONLY. +@interface RollbarLogger (Test) + +/// Returns after all the queued up payloads are processed by the RollbarThread +///@note THIS METHOD IS TO BE USED FOR TESTING PURPOSES ONLY. ++ (void)flushRollbarThread; + +/// Reads all the payloads queued up in the persistent store +///@note THIS METHOD IS TO BE USED FOR TESTING PURPOSES ONLY. ++ (nonnull NSArray *)readLogItemsFromStore; + +/// Reads all payloads from the default payloads log +///@note THIS METHOD IS TO BE USED FOR TESTING PURPOSES ONLY. ++ (nonnull NSArray *)readPayloadsFromSdkLog; + +/// Reads all payloads from the provided file path +///@note THIS METHOD IS TO BE USED FOR TESTING PURPOSES ONLY. ++ (nonnull NSArray *)readPayloadsDataFromFile:(nonnull NSString *)filePath; + +/// Clears all the payloads queued up in the persistent store +///@note THIS METHOD IS TO BE USED FOR TESTING PURPOSES ONLY. ++ (void)clearLogItemsStore; + +/// Clears all the SDK persisted data +///@note THIS METHOD IS TO BE USED FOR TESTING PURPOSES ONLY. ++ (void)clearSdkDataStore; + +/// Clears data from the specified file within the SDK data folder +/// @param sdkFileName fileName within the SDK data folder +///@note THIS METHOD IS TO BE USED FOR TESTING PURPOSES ONLY. ++ (void)clearSdkFile:(nonnull NSString *)sdkFileName; + +@end + +NS_ASSUME_NONNULL_END diff --git a/RollbarNotifier/Tests/RollbarNotifierTests-ObjC/PayloadTruncationTests.m b/RollbarNotifier/Tests/RollbarNotifierTests-ObjC/PayloadTruncationTests.m index b518a05e..735c9abc 100644 --- a/RollbarNotifier/Tests/RollbarNotifierTests-ObjC/PayloadTruncationTests.m +++ b/RollbarNotifier/Tests/RollbarNotifierTests-ObjC/PayloadTruncationTests.m @@ -1,12 +1,8 @@ -// Copyright (c) 2018 Rollbar, Inc. All rights reserved. - @import Foundation; +@import UnitTesting; #if !TARGET_OS_WATCH #import -#import "../../../UnitTests/RollbarUnitTestSettings.h" -#import "RollbarTestUtil.h" -//#import "../Rollbar/Notifier/RollbarPayloadTruncator.h" @import RollbarNotifier; @@ -17,15 +13,19 @@ @interface PayloadTruncationTests : XCTestCase @implementation PayloadTruncationTests - (void)setUp { + [super setUp]; - RollbarClearLogFile(); + + [RollbarLogger clearSdkDataStore]; + if (!Rollbar.currentConfiguration) { - [Rollbar initWithAccessToken:ROLLBAR_UNIT_TEST_PAYLOADS_ACCESS_TOKEN]; - Rollbar.currentConfiguration.destination.environment = ROLLBAR_UNIT_TEST_ENVIRONMENT; + [Rollbar initWithAccessToken:[RollbarTestHelper getRollbarPayloadsAccessToken]]; + Rollbar.currentConfiguration.destination.environment = [RollbarTestHelper getRollbarEnvironment]; } } - (void)tearDown { + [Rollbar updateConfiguration:[RollbarConfig new]]; [super tearDown]; } @@ -193,8 +193,9 @@ - (void)testPayloadTruncation { [Rollbar errorException:exception]; } - RollbarFlushFileThread(Rollbar.currentLogger); - NSArray *items = RollbarReadLogItemFromFile(); + [RollbarLogger flushRollbarThread]; + + NSArray *items = [RollbarLogger readLogItemsFromStore]; for (id payload in items) { NSMutableArray *frames = [payload mutableArrayValueForKeyPath:@"body.trace.frames"]; diff --git a/RollbarNotifier/Tests/RollbarNotifierTests-ObjC/RollbarConfigurationTests.m b/RollbarNotifier/Tests/RollbarNotifierTests-ObjC/RollbarConfigurationTests.m index 1a9d3923..31de609a 100644 --- a/RollbarNotifier/Tests/RollbarNotifierTests-ObjC/RollbarConfigurationTests.m +++ b/RollbarNotifier/Tests/RollbarNotifierTests-ObjC/RollbarConfigurationTests.m @@ -1,11 +1,8 @@ -// Copyright (c) 2018 Rollbar, Inc. All rights reserved. - @import Foundation; +@import UnitTesting; #if !TARGET_OS_WATCH #import -#import "../../../UnitTests/RollbarUnitTestSettings.h" -#import "RollbarTestUtil.h" @import RollbarNotifier; @@ -16,24 +13,30 @@ @interface RollbarConfigurationTests : XCTestCase @implementation RollbarConfigurationTests - (void)setUp { + [super setUp]; - RollbarClearLogFile(); + + [RollbarLogger clearSdkDataStore]; + if (!Rollbar.currentConfiguration) { [Rollbar initWithAccessToken:@""]; } } - (void)tearDown { + [Rollbar updateConfiguration:[RollbarConfig new]]; [super tearDown]; } - (void)testDefaultRollbarConfiguration { + RollbarConfig *rc = [RollbarConfig new]; NSLog(@"%@", rc); } - (void)testScrubSafeListFields { + NSString *scrubedContent = @"*****"; NSArray *keys = @[@"client.ios.app_name", @"client.ios.os_version", @"body.message.body"]; @@ -42,10 +45,11 @@ - (void)testScrubSafeListFields { [Rollbar.currentConfiguration.dataScrubber addScrubField:key]; } [Rollbar debugMessage:@"test"]; - RollbarFlushFileThread(Rollbar.currentLogger); + + [RollbarLogger flushRollbarThread]; // verify the fields were scrubbed: - NSArray *logItems = RollbarReadLogItemFromFile(); + NSArray *logItems = [RollbarLogger readLogItemsFromStore]; for (NSString *key in keys) { NSString *content = [logItems[0] valueForKeyPath:key]; XCTAssertTrue([content isEqualToString:scrubedContent], @@ -56,17 +60,18 @@ - (void)testScrubSafeListFields { ); } - RollbarClearLogFile(); + [RollbarLogger clearSdkDataStore]; // define scrub whitelist fields (the same as the scrub fields - to counterbalance them): for (NSString *key in keys) { [Rollbar.currentConfiguration.dataScrubber addScrubSafeListField:key]; } [Rollbar debugMessage:@"test"]; - RollbarFlushFileThread(Rollbar.currentLogger); + + [RollbarLogger flushRollbarThread]; // verify the fields were not scrubbed: - logItems = RollbarReadLogItemFromFile(); + logItems = [RollbarLogger readLogItemsFromStore]; for (NSString *key in keys) { NSString *content = [logItems[0] valueForKeyPath:key]; XCTAssertTrue(![content isEqualToString:scrubedContent], @@ -79,7 +84,8 @@ - (void)testScrubSafeListFields { } - (void)testTelemetryEnabled { - RollbarClearLogFile(); + + [RollbarLogger clearSdkDataStore]; BOOL expectedFlag = NO; Rollbar.currentConfiguration.telemetry.enabled = expectedFlag; @@ -178,8 +184,9 @@ - (void)testViewInputTelemetrScrubFieldsConfig { - (void)testEnabled { - RollbarClearLogFile(); - NSArray *logItems = RollbarReadLogItemFromFile(); + [RollbarLogger clearSdkDataStore]; + + NSArray *logItems = [RollbarLogger readLogItemsFromStore]; XCTAssertTrue(logItems.count == 0, @"logItems count is expected to be 0. Actual value is %lu", (unsigned long) logItems.count @@ -189,8 +196,9 @@ - (void)testEnabled { Rollbar.currentConfiguration.developerOptions.enabled = NO; Rollbar.currentLogger.configuration.developerOptions.enabled = NO; [Rollbar debugMessage:@"Test1"]; - RollbarFlushFileThread(Rollbar.currentLogger); - logItems = RollbarReadLogItemFromFile(); + [RollbarLogger flushRollbarThread]; + + logItems = [RollbarLogger readLogItemsFromStore]; XCTAssertTrue(logItems.count == 0, @"logItems count is expected to be 0. Actual value is %lu", (unsigned long) logItems.count @@ -198,8 +206,9 @@ - (void)testEnabled { Rollbar.currentConfiguration.developerOptions.enabled = YES; [Rollbar debugMessage:@"Test2"]; - RollbarFlushFileThread(Rollbar.currentLogger); - logItems = RollbarReadLogItemFromFile(); + [RollbarLogger flushRollbarThread]; + + logItems = [RollbarLogger readLogItemsFromStore]; XCTAssertTrue(logItems.count == 1, @"logItems count is expected to be 1. Actual value is %lu", (unsigned long) logItems.count @@ -207,14 +216,15 @@ - (void)testEnabled { Rollbar.currentConfiguration.developerOptions.enabled = NO; [Rollbar debugMessage:@"Test3"]; - RollbarFlushFileThread(Rollbar.currentLogger); - logItems = RollbarReadLogItemFromFile(); + [RollbarLogger flushRollbarThread]; + + logItems = [RollbarLogger readLogItemsFromStore]; XCTAssertTrue(logItems.count == 1, @"logItems count is expected to be 1. Actual value is %lu", (unsigned long) logItems.count ); - RollbarClearLogFile(); + [RollbarLogger clearSdkDataStore]; } - (void)testMaximumTelemetryEvents { @@ -232,8 +242,9 @@ - (void)testMaximumTelemetryEvents { [Rollbar reapplyConfiguration]; [Rollbar debugMessage:@"Test"]; - RollbarFlushFileThread(Rollbar.currentLogger); - NSArray *logItems = RollbarReadLogItemFromFile(); + [RollbarLogger flushRollbarThread]; + + NSArray *logItems = [RollbarLogger readLogItemsFromStore]; NSDictionary *item = logItems[0]; NSArray *telemetryData = [item valueForKeyPath:@"body.telemetry"]; XCTAssertTrue(telemetryData.count == max, @@ -244,20 +255,23 @@ - (void)testMaximumTelemetryEvents { } - (void)testCheckIgnore { + [Rollbar debugMessage:@"Don't ignore this"]; - RollbarFlushFileThread(Rollbar.currentLogger); - NSArray *logItems = RollbarReadLogItemFromFile(); + [RollbarLogger flushRollbarThread]; + + NSArray *logItems = [RollbarLogger readLogItemsFromStore]; XCTAssertTrue(logItems.count == 1, @"Log item count should be 1"); Rollbar.currentConfiguration.checkIgnoreRollbarData = ^BOOL(RollbarData *payloadData) { return true; }; [Rollbar debugMessage:@"Ignore this"]; - logItems = RollbarReadLogItemFromFile(); + logItems = [RollbarLogger readLogItemsFromStore]; XCTAssertTrue(logItems.count == 1, @"Log item count should be 1"); } - (void)testServerData { + NSString *host = @"testHost"; NSString *root = @"testRoot"; NSString *branch = @"testBranch"; @@ -269,9 +283,9 @@ - (void)testServerData { ]; [Rollbar debugMessage:@"test"]; - RollbarFlushFileThread(Rollbar.currentLogger); + [RollbarLogger flushRollbarThread]; - NSArray *logItems = RollbarReadLogItemFromFile(); + NSArray *logItems = [RollbarLogger readLogItemsFromStore]; NSDictionary *item = logItems[0]; NSDictionary *server = item[@"server"]; @@ -298,6 +312,7 @@ - (void)testServerData { } - (void)testPayloadModification { + NSString *newMsg = @"Modified message"; Rollbar.currentConfiguration.modifyRollbarData = ^RollbarData *(RollbarData *payloadData) { // [payloadData setValue:newMsg forKeyPath:@"body.message.body"]; @@ -308,9 +323,9 @@ - (void)testPayloadModification { }; [Rollbar debugMessage:@"test"]; - RollbarFlushFileThread(Rollbar.currentLogger); + [RollbarLogger flushRollbarThread]; - NSArray *logItems = RollbarReadLogItemFromFile(); + NSArray *logItems = [RollbarLogger readLogItemsFromStore]; NSString *msg1 = [logItems[0] valueForKeyPath:@"body.message.body"]; NSString *msg2 = [logItems[0] valueForKeyPath:@"body.message.body2"]; @@ -327,6 +342,7 @@ - (void)testPayloadModification { } - (void)testScrubField { + NSString *scrubedContent = @"*****"; NSArray *keys = @[@"client.ios.app_name", @"client.ios.os_version", @"body.message.body"]; @@ -335,9 +351,9 @@ - (void)testScrubField { } [Rollbar debugMessage:@"test"]; - RollbarFlushFileThread(Rollbar.currentLogger); + [RollbarLogger flushRollbarThread]; - NSArray *logItems = RollbarReadLogItemFromFile(); + NSArray *logItems = [RollbarLogger readLogItemsFromStore]; for (NSString *key in keys) { NSString *content = [logItems[0] valueForKeyPath:key]; XCTAssertTrue([content isEqualToString:scrubedContent], @@ -350,9 +366,10 @@ - (void)testScrubField { } - (void)testLogTelemetryAutoCapture { + NSString *logMsg = @"log-message-testing"; [[RollbarTelemetry sharedInstance] clearAllData]; - //Rollbar.currentConfiguration.accessToken = ROLLBAR_UNIT_TEST_DEPLOYS_WRITE_ACCESS_TOKEN; + Rollbar.currentConfiguration.telemetry.enabled = YES; Rollbar.currentConfiguration.telemetry.captureLog = YES; [Rollbar reapplyConfiguration]; @@ -361,9 +378,9 @@ - (void)testLogTelemetryAutoCapture { NSLog(logMsg); [Rollbar debugMessage:@"test"]; - RollbarFlushFileThread(Rollbar.currentLogger); + [RollbarLogger flushRollbarThread]; - NSArray *logItems = RollbarReadLogItemFromFile(); + NSArray *logItems = [RollbarLogger readLogItemsFromStore]; NSArray *telemetryData = [logItems[0] valueForKeyPath:@"body.telemetry"]; NSString *telemetryMsg = [telemetryData[0] valueForKeyPath:@"body.message"]; XCTAssertTrue([logMsg isEqualToString:telemetryMsg], diff --git a/RollbarNotifier/Tests/RollbarNotifierTests-ObjC/RollbarTelemetryTests.m b/RollbarNotifier/Tests/RollbarNotifierTests-ObjC/RollbarTelemetryTests.m index 546a71bf..f9ca5a9d 100644 --- a/RollbarNotifier/Tests/RollbarNotifierTests-ObjC/RollbarTelemetryTests.m +++ b/RollbarNotifier/Tests/RollbarNotifierTests-ObjC/RollbarTelemetryTests.m @@ -1,11 +1,8 @@ -// Copyright (c) 2018 Rollbar, Inc. All rights reserved. - @import Foundation; +@import UnitTesting; #if !TARGET_OS_WATCH #import -#import "../../../UnitTests/RollbarUnitTestSettings.h" -#import "RollbarTestUtil.h" @import RollbarNotifier; @@ -16,11 +13,14 @@ @interface RollbarTelemetryTests : XCTestCase @implementation RollbarTelemetryTests - (void)setUp { + [super setUp]; - RollbarClearLogFile(); + + [RollbarLogger clearSdkDataStore]; + if (!Rollbar.currentConfiguration) { - [Rollbar initWithAccessToken:ROLLBAR_UNIT_TEST_PAYLOADS_ACCESS_TOKEN]; - Rollbar.currentConfiguration.destination.environment = ROLLBAR_UNIT_TEST_ENVIRONMENT; + [Rollbar initWithAccessToken: [RollbarTestHelper getRollbarPayloadsAccessToken]]; + Rollbar.currentConfiguration.destination.environment = [RollbarTestHelper getRollbarEnvironment]; } } @@ -30,9 +30,8 @@ - (void)tearDown { [super tearDown]; } -- (void)doNothing {} - - (void)testTelemetryCapture { + Rollbar.currentConfiguration.telemetry.enabled = YES; [Rollbar reapplyConfiguration]; @@ -44,9 +43,9 @@ - (void)testTelemetryCapture { [Rollbar recordManualEventForLevel:RollbarLevel_Debug withData:@{@"data": @"content"}]; [Rollbar debugMessage:@"Test"]; - RollbarFlushFileThread(Rollbar.currentLogger); + [RollbarLogger flushRollbarThread]; - NSArray *logItems = RollbarReadLogItemFromFile(); + NSArray *logItems = [RollbarLogger readLogItemsFromStore]; NSDictionary *item = logItems[0]; NSArray *telemetryData = [item valueForKeyPath:@"body.telemetry"]; XCTAssertTrue(telemetryData.count > 0); @@ -78,15 +77,17 @@ - (void)testTelemetryCapture { } - (void)testErrorReportingWithTelemetry { + Rollbar.currentConfiguration.telemetry.enabled = YES; [Rollbar recordNavigationEventForLevel:RollbarLevel_Info from:@"SomeNavigationSource" to:@"SomeNavigationDestination"]; [Rollbar recordConnectivityEventForLevel:RollbarLevel_Info status:@"SomeConnectivityStatus"]; [Rollbar recordNetworkEventForLevel:RollbarLevel_Info method:@"POST" url:@"www.myservice.com" statusCode:@"200" extraData:nil]; [Rollbar recordErrorEventForLevel:RollbarLevel_Debug message:@"Some telemetry message..."]; - [Rollbar recordErrorEventForLevel:RollbarLevel_Error exception:[NSException exceptionWithName:@"someExceptionName" - reason:@"someExceptionReason" - userInfo:nil]]; + [Rollbar recordErrorEventForLevel:RollbarLevel_Error exception: + [NSException exceptionWithName:@"someExceptionName" + reason:@"someExceptionReason" + userInfo:nil]]; [Rollbar recordManualEventForLevel:RollbarLevel_Debug withData:@{@"myTelemetryParameter": @"itsValue"}]; [Rollbar debugMessage:@"Demonstrate Telemetry capture"]; @@ -95,7 +96,7 @@ - (void)testErrorReportingWithTelemetry { //[NSThread sleepForTimeInterval:8.0f]; - NSArray *logItems = RollbarReadLogItemFromFile(); + NSArray *logItems = [RollbarLogger readLogItemsFromStore]; for (NSDictionary *item in logItems) { NSArray *telemetryData = [item valueForKeyPath:@"body.telemetry"]; @@ -128,6 +129,7 @@ - (void)testErrorReportingWithTelemetry { } - (void)testTelemetryViewEventScrubbing { + Rollbar.currentConfiguration.telemetry.enabled = YES; Rollbar.currentConfiguration.telemetry.viewInputsScrubber.enabled = YES; [Rollbar.currentConfiguration.telemetry.viewInputsScrubber addScrubField:@"password"]; @@ -151,6 +153,7 @@ - (void)testTelemetryViewEventScrubbing { } - (void)testRollbarLog { + Rollbar.currentConfiguration.telemetry.enabled = YES; Rollbar.currentConfiguration.telemetry.captureLog = YES; [Rollbar reapplyConfiguration]; diff --git a/RollbarNotifier/Tests/RollbarNotifierTests-ObjC/RollbarTestUtil.h b/RollbarNotifier/Tests/RollbarNotifierTests-ObjC/RollbarTestUtil.h deleted file mode 100644 index 161eb9ea..00000000 --- a/RollbarNotifier/Tests/RollbarNotifierTests-ObjC/RollbarTestUtil.h +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright (c) 2018 Rollbar, Inc. All rights reserved. - -#import - -@import RollbarNotifier; - -void RollbarClearLogFile(void); -NSArray* RollbarReadLogItemFromFile(void); -void RollbarFlushFileThread(RollbarLogger *logger); - -@interface RollbarLogger (Tests) - -- (NSThread *)_rollbarThread; -- (void)_test_doNothing; - -@end diff --git a/RollbarNotifier/Tests/RollbarNotifierTests-ObjC/RollbarTestUtil.m b/RollbarNotifier/Tests/RollbarNotifierTests-ObjC/RollbarTestUtil.m deleted file mode 100644 index 5109c3df..00000000 --- a/RollbarNotifier/Tests/RollbarNotifierTests-ObjC/RollbarTestUtil.m +++ /dev/null @@ -1,64 +0,0 @@ -// Copyright (c) 2018 Rollbar, Inc. All rights reserved. - -#import "RollbarTestUtil.h" -#import "RollbarFileReader.h" -#import "RollbarCachesDirectory.h" - -static NSString *QUEUED_ITEMS_FILE_NAME = @"rollbar.items"; - -NSString* _logFilePath() { - - NSString *cachesDirectory = [RollbarCachesDirectory directory]; - return [cachesDirectory stringByAppendingPathComponent:QUEUED_ITEMS_FILE_NAME]; -} - -void RollbarClearLogFile() { - - NSString *filePath = _logFilePath(); - NSFileManager *fileManager = [NSFileManager defaultManager]; - NSError *error; - BOOL fileExists = [fileManager fileExistsAtPath:filePath]; - - if (fileExists) { - BOOL success = [fileManager removeItemAtPath:filePath - error:&error]; - if (!success) { - NSLog(@"Error: %@", [error localizedDescription]); - } - [[NSFileManager defaultManager] createFileAtPath:filePath - contents:nil - attributes:nil]; - } -} - -NSArray* RollbarReadLogItemFromFile() { - - NSString *filePath = _logFilePath(); - RollbarFileReader *reader = [[RollbarFileReader alloc] initWithFilePath:filePath - andOffset:0]; - - NSMutableArray *items = [NSMutableArray array]; - [reader enumerateLinesUsingBlock:^(NSString *line, NSUInteger nextOffset, BOOL *stop) { - NSMutableDictionary *payload = - [NSJSONSerialization JSONObjectWithData:[line dataUsingEncoding:NSUTF8StringEncoding] - options:(NSJSONReadingMutableContainers | NSJSONReadingMutableLeaves) - error:nil - ]; - - - if (!payload) { - return; - } - - NSMutableDictionary *data = payload[@"data"]; - [items addObject:data]; - }]; - - return items; -} - -void RollbarFlushFileThread(RollbarLogger *logger) { - - [logger performSelector:@selector(_test_doNothing) - onThread:[logger _rollbarThread] withObject:nil waitUntilDone:YES]; -} diff --git a/RollbarNotifier/Tests/RollbarNotifierTests-ObjC/RollbarTests.m b/RollbarNotifier/Tests/RollbarNotifierTests-ObjC/RollbarTests.m index 2df0acf2..db7e8dba 100644 --- a/RollbarNotifier/Tests/RollbarNotifierTests-ObjC/RollbarTests.m +++ b/RollbarNotifier/Tests/RollbarNotifierTests-ObjC/RollbarTests.m @@ -1,11 +1,8 @@ -// Copyright (c) 2018 Rollbar, Inc. All rights reserved. - @import Foundation; +@import UnitTesting; #if !TARGET_OS_WATCH #import -#import "../../../UnitTests/RollbarUnitTestSettings.h" -#import "RollbarTestUtil.h" @import RollbarNotifier; @@ -19,13 +16,13 @@ - (void)setUp { [super setUp]; - RollbarClearLogFile(); + [RollbarLogger clearSdkDataStore]; if (!Rollbar.currentConfiguration) { RollbarConfig *config = [[RollbarConfig alloc] init]; - config.destination.accessToken = ROLLBAR_UNIT_TEST_PAYLOADS_ACCESS_TOKEN; - config.destination.environment = ROLLBAR_UNIT_TEST_ENVIRONMENT; + config.destination.accessToken = [RollbarTestHelper getRollbarPayloadsAccessToken]; + config.destination.environment = [RollbarTestHelper getRollbarEnvironment]; config.developerOptions.transmit = YES; config.developerOptions.logPayload = YES; config.loggingOptions.maximumReportsPerMinute = 5000; @@ -39,15 +36,17 @@ - (void)setUp { } - (void)tearDown { + [Rollbar updateConfiguration:[RollbarConfig new]]; [super tearDown]; } - (void)testMultithreadedStressCase { + for( int i = 0; i < 20; i++) { dispatch_async(dispatch_get_global_queue(QOS_CLASS_UTILITY,0), ^(){ RollbarLogger *logger = [[RollbarLogger alloc] initWithAccessToken:Rollbar.currentConfiguration.destination.accessToken]; - logger.configuration.destination.environment = ROLLBAR_UNIT_TEST_ENVIRONMENT; + logger.configuration.destination.environment = [RollbarTestHelper getRollbarEnvironment]; for (int j = 0; j < 20; j++) { [logger log:RollbarLevel_Error message:@"error" @@ -107,7 +106,7 @@ - (void)testRollbarNotifiersIndependentConfiguration { - (void)testRollbarTransmit { Rollbar.currentConfiguration.destination.accessToken = @"09da180aba21479e9ed3d91e0b8d58d6"; - Rollbar.currentConfiguration.destination.environment = ROLLBAR_UNIT_TEST_ENVIRONMENT; + Rollbar.currentConfiguration.destination.environment = [RollbarTestHelper getRollbarEnvironment]; Rollbar.currentConfiguration.developerOptions.transmit = YES; Rollbar.currentConfiguration.developerOptions.transmit = YES; @@ -134,6 +133,7 @@ - (void)testRollbarTransmit { } - (void)testNotification { + NSDictionary *notificationText = @{ @"error": @[@"testing-error-with-message"], @"debug": @[@"testing-debug"], @@ -156,7 +156,7 @@ - (void)testNotification { [NSThread sleepForTimeInterval:3.0f]; - NSArray *items = RollbarReadLogItemFromFile(); + NSArray *items = [RollbarLogger readLogItemsFromStore]; for (id item in items) { NSString *level = [item valueForKeyPath:@"level"]; NSString *message = [item valueForKeyPath:@"body.message.body"]; diff --git a/RollbarNotifier/Tests/RollbarNotifierTests/RollbarNotifierConfigUtilTests.swift b/RollbarNotifier/Tests/RollbarNotifierTests/RollbarNotifierConfigUtilTests.swift index 980365cd..5fde124e 100644 --- a/RollbarNotifier/Tests/RollbarNotifierTests/RollbarNotifierConfigUtilTests.swift +++ b/RollbarNotifier/Tests/RollbarNotifierTests/RollbarNotifierConfigUtilTests.swift @@ -27,7 +27,7 @@ final class RolllbarNotifierConfigUtilTests: XCTestCase { print("Error: \(error) \n Stack Symbols: \(stackSymbols)") } - override class func setUp() { + override func setUp() { do { _ = try RollbarConfigUtil.deleteDefaultRollbarConfigFile(); } diff --git a/RollbarNotifier/Tests/RollbarNotifierTests/RollbarNotifierConfigurationTests.swift b/RollbarNotifier/Tests/RollbarNotifierTests/RollbarNotifierConfigurationTests.swift index 23f2c9ce..2e207850 100644 --- a/RollbarNotifier/Tests/RollbarNotifierTests/RollbarNotifierConfigurationTests.swift +++ b/RollbarNotifier/Tests/RollbarNotifierTests/RollbarNotifierConfigurationTests.swift @@ -2,11 +2,12 @@ import XCTest import Foundation import os.log +import UnitTesting @testable import RollbarNotifier final class RollbarNotifierConfigurationTests: XCTestCase { - override class func setUp() { + override func setUp() { super.setUp(); diff --git a/RollbarNotifier/Tests/RollbarNotifierTests/RollbarNotifierDTOsTests.swift b/RollbarNotifier/Tests/RollbarNotifierTests/RollbarNotifierDTOsTests.swift index c145c6f5..565aaacc 100644 --- a/RollbarNotifier/Tests/RollbarNotifierTests/RollbarNotifierDTOsTests.swift +++ b/RollbarNotifier/Tests/RollbarNotifierTests/RollbarNotifierDTOsTests.swift @@ -5,7 +5,7 @@ import Foundation final class RollbarNotifierDTOsTests: XCTestCase { - override class func setUp() { + override func setUp() { } override func tearDown() { diff --git a/RollbarNotifier/Tests/RollbarNotifierTests/RollbarNotifierLoggerTests.swift b/RollbarNotifier/Tests/RollbarNotifierTests/RollbarNotifierLoggerTests.swift index 20beb747..0d81396a 100644 --- a/RollbarNotifier/Tests/RollbarNotifierTests/RollbarNotifierLoggerTests.swift +++ b/RollbarNotifier/Tests/RollbarNotifierTests/RollbarNotifierLoggerTests.swift @@ -7,7 +7,7 @@ import os.log final class RollbarNotifierLoggerTests: XCTestCase { - override class func setUp() { + override func setUp() { super.setUp(); @@ -17,9 +17,9 @@ final class RollbarNotifierLoggerTests: XCTestCase { //if Rollbar.currentConfiguration() != nil { - Rollbar.initWithAccessToken(RollbarUnitTestSettings.payloadsPostAccessToken); - Rollbar.currentConfiguration()?.destination.accessToken = RollbarUnitTestSettings.payloadsPostAccessToken; - Rollbar.currentConfiguration()?.destination.environment = RollbarUnitTestSettings.environment; + Rollbar.initWithAccessToken(RollbarTestHelper.getRollbarPayloadsAccessToken()); + Rollbar.currentConfiguration()?.destination.accessToken = RollbarTestHelper.getRollbarPayloadsAccessToken(); + Rollbar.currentConfiguration()?.destination.environment = RollbarTestHelper.getRollbarEnvironment(); Rollbar.currentConfiguration()?.developerOptions.transmit = true; Rollbar.currentConfiguration()?.developerOptions.logPayload = true; Rollbar.currentConfiguration()?.loggingOptions.maximumReportsPerMinute = 5000; @@ -87,8 +87,8 @@ final class RollbarNotifierLoggerTests: XCTestCase { //RollbarTestUtil.clearLogFile(); //RollbarTestUtil.clearTelemetryFile(); - Rollbar.currentConfiguration()?.destination.accessToken = RollbarUnitTestSettings.deploysWriteAccessToken; - Rollbar.currentConfiguration()?.destination.environment = RollbarUnitTestSettings.environment; + Rollbar.currentConfiguration()?.destination.accessToken = RollbarTestHelper.getRollbarPayloadsAccessToken(); + Rollbar.currentConfiguration()?.destination.environment = RollbarTestHelper.getRollbarEnvironment(); Rollbar.currentConfiguration()?.developerOptions.transmit = true; Rollbar.currentConfiguration()?.developerOptions.transmit = true; diff --git a/RollbarNotifier/Tests/RollbarNotifierTests/RollbarNotifierTelemetryTests.swift b/RollbarNotifier/Tests/RollbarNotifierTests/RollbarNotifierTelemetryTests.swift index 806a4b59..0d742d65 100644 --- a/RollbarNotifier/Tests/RollbarNotifierTests/RollbarNotifierTelemetryTests.swift +++ b/RollbarNotifier/Tests/RollbarNotifierTests/RollbarNotifierTelemetryTests.swift @@ -7,7 +7,7 @@ import UnitTesting final class RollbarNotifierTelemetryTests: XCTestCase { - override class func setUp() { + override func setUp() { super.setUp(); RollbarTestUtil.clearLogFile(); RollbarTestUtil.clearTelemetryFile(); @@ -15,8 +15,8 @@ final class RollbarNotifierTelemetryTests: XCTestCase { print("Info: Rollbar already pre-configured!"); } else { - Rollbar.initWithAccessToken(RollbarUnitTestSettings.payloadsPostAccessToken); - Rollbar.currentConfiguration()?.destination.environment = RollbarUnitTestSettings.environment; + Rollbar.initWithAccessToken(RollbarTestHelper.getRollbarPayloadsAccessToken()); + Rollbar.currentConfiguration()?.destination.environment = RollbarTestHelper.getRollbarEnvironment(); } } diff --git a/RollbarNotifier/Tests/RollbarNotifierTests/RollbarNotifierTruncationTests.swift b/RollbarNotifier/Tests/RollbarNotifierTests/RollbarNotifierTruncationTests.swift index ab409746..71016c7e 100644 --- a/RollbarNotifier/Tests/RollbarNotifierTests/RollbarNotifierTruncationTests.swift +++ b/RollbarNotifier/Tests/RollbarNotifierTests/RollbarNotifierTruncationTests.swift @@ -7,7 +7,7 @@ import os.log final class RollbarNotifierTruncationTests: XCTestCase { - override class func setUp() { + override func setUp() { super.setUp(); @@ -15,8 +15,8 @@ final class RollbarNotifierTruncationTests: XCTestCase { RollbarTestUtil.clearTelemetryFile(); //if Rollbar.currentConfiguration() != nil { - Rollbar.initWithAccessToken(RollbarUnitTestSettings.payloadsPostAccessToken); - Rollbar.currentConfiguration()?.destination.environment = RollbarUnitTestSettings.environment; + Rollbar.initWithAccessToken(RollbarTestHelper.getRollbarPayloadsAccessToken()); + Rollbar.currentConfiguration()?.destination.environment = RollbarTestHelper.getRollbarEnvironment(); //} } diff --git a/RollbarPLCrashReporter.podspec b/RollbarPLCrashReporter.podspec index 8861d503..2313f85d 100644 --- a/RollbarPLCrashReporter.podspec +++ b/RollbarPLCrashReporter.podspec @@ -7,7 +7,7 @@ Pod::Spec.new do |s| - s.version = "2.0.3" + s.version = "2.1.0" s.name = "RollbarPLCrashReporter" s.summary = "Application or client side SDK for interacting with the Rollbar API Server." s.description = <<-DESC @@ -50,7 +50,7 @@ Pod::Spec.new do |s| s.static_framework = true s.framework = "Foundation" s.dependency "RollbarCommon", "~> #{s.version}" - s.dependency "PLCrashReporter", "~> 1.10.0" + s.dependency "PLCrashReporter", "~> 1.10.1" # s.frameworks = "SomeFramework", "AnotherFramework" # s.library = "iconv" # s.libraries = "iconv", "xml2" diff --git a/RollbarPLCrashReporter/Package.swift b/RollbarPLCrashReporter/Package.swift index d5891ced..a12cb1aa 100644 --- a/RollbarPLCrashReporter/Package.swift +++ b/RollbarPLCrashReporter/Package.swift @@ -29,7 +29,7 @@ let package = Package( ), .package(name:"PLCrashReporter", url: "https://github.com/microsoft/plcrashreporter.git", - from: "1.10.0" //Package.Dependency.Requirement.branch("master") + from: "1.10.1" //Package.Dependency.Requirement.branch("master") ), ], targets: [ diff --git a/RollbarSDK.experimental_podspec b/RollbarSDK.experimental_podspec index d61a9a4b..8b8ef4a3 100644 --- a/RollbarSDK.experimental_podspec +++ b/RollbarSDK.experimental_podspec @@ -9,7 +9,7 @@ Pod::Spec.new do |sdk| # Rollbar SDK: # ============ - sdk.version = "2.0.3" + sdk.version = "2.1.0" sdk.name = "RollbarSDK" s.summary = "Application or client side SDK for interacting with the Rollbar API Server." sdk.description = <<-DESC diff --git a/RollbarSDK.xcworkspace/contents.xcworkspacedata b/RollbarSDK.xcworkspace/contents.xcworkspacedata index c834da3e..2ae6dedb 100644 --- a/RollbarSDK.xcworkspace/contents.xcworkspacedata +++ b/RollbarSDK.xcworkspace/contents.xcworkspacedata @@ -4,13 +4,9 @@ - - - - + + @@ -81,6 +77,9 @@ + + diff --git a/RollbarSDK.xcworkspace/xcshareddata/swiftpm/Package.resolved b/RollbarSDK.xcworkspace/xcshareddata/swiftpm/Package.resolved index 7b7b50ff..e862be07 100644 --- a/RollbarSDK.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/RollbarSDK.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -1,6 +1,15 @@ { "object": { "pins": [ + { + "package": "CocoaLumberjack", + "repositoryURL": "https://github.com/CocoaLumberjack/CocoaLumberjack.git", + "state": { + "branch": null, + "revision": "80ada1f753b0d53d9b57c465936a7c4169375002", + "version": "3.7.4" + } + }, { "package": "KSCrash", "repositoryURL": "https://github.com/kstenerud/KSCrash.git", @@ -15,8 +24,17 @@ "repositoryURL": "https://github.com/microsoft/plcrashreporter.git", "state": { "branch": null, - "revision": "59513acde6194d93617afcf7b2c81c88638a6af2", - "version": "1.10.0" + "revision": "6b27393cad517c067dceea85fadf050e70c4ceaa", + "version": "1.10.1" + } + }, + { + "package": "swift-log", + "repositoryURL": "https://github.com/apple/swift-log.git", + "state": { + "branch": null, + "revision": "5d66f7ba25daf4f94100e7022febf3c75e37a6c7", + "version": "1.4.2" } } ] diff --git a/RollbarSwift.podspec b/RollbarSwift.podspec index 786dac9c..90a0f688 100644 --- a/RollbarSwift.podspec +++ b/RollbarSwift.podspec @@ -7,7 +7,7 @@ Pod::Spec.new do |s| - s.version = "2.0.3" + s.version = "2.1.0" s.name = "RollbarSwift" s.summary = "Application or client side SDK for interacting with the Rollbar API Server." s.description = <<-DESC diff --git a/RollbarSwift/Tests/RollbarSwiftTests/RollbarSwiftTests.swift b/RollbarSwift/Tests/RollbarSwiftTests/RollbarSwiftTests.swift index cbbc54c2..13467c60 100644 --- a/RollbarSwift/Tests/RollbarSwiftTests/RollbarSwiftTests.swift +++ b/RollbarSwift/Tests/RollbarSwiftTests/RollbarSwiftTests.swift @@ -18,8 +18,8 @@ final class RollbarSwiftTests: XCTestCase { func createGuard() -> RollbarExceptionGuard { let config = RollbarConfig(); - config.destination.accessToken = RollbarUnitTestSettings.payloadsPostAccessToken; - config.destination.environment = RollbarUnitTestSettings.environment; + config.destination.accessToken = RollbarTestHelper.getRollbarPayloadsAccessToken(); + config.destination.environment = RollbarTestHelper.getRollbarEnvironment(); config.developerOptions.transmit = true; let logger = RollbarLogger(configuration: config); diff --git a/UnitTesting/Package.swift b/UnitTesting/Package.swift index e0f59532..69ef04a3 100644 --- a/UnitTesting/Package.swift +++ b/UnitTesting/Package.swift @@ -5,6 +5,13 @@ import PackageDescription let package = Package( name: "UnitTesting", + platforms: [ + // Oldest targeted platform versions that are supported by this product. + .macOS(.v10_10), + .iOS(.v9), + .tvOS(.v11), + .watchOS(.v4), + ], products: [ // Products define the executables and libraries a package produces, and make them visible to other packages. .library( @@ -14,15 +21,33 @@ let package = Package( dependencies: [ // Dependencies declare other packages that this package depends on. // .package(url: /* package url */, from: "1.0.0"), + .package(path: "../RollbarCommon"), ], targets: [ // Targets are the basic building blocks of a package. A target can define a module or a test suite. // Targets can depend on other targets in this package, and on products in packages this package depends on. .target( name: "UnitTesting", - dependencies: []), + dependencies: [ + "RollbarCommon", + ], + publicHeadersPath: "include", + cSettings: [ + .headerSearchPath("Sources/UnitTesting/**"), + // .headerSearchPath("Sources/RollbarNotifier"), + // .headerSearchPath("Sources/RollbarNotifier/include"), + // .headerSearchPath("Sources/RollbarNotifier/DTOs"), + + // .define("DEFINES_MODULE"), + ] + ), .testTarget( name: "UnitTestingTests", dependencies: ["UnitTesting"]), + ], + swiftLanguageVersions: [ + SwiftVersion.v4, + SwiftVersion.v4_2, + SwiftVersion.v5, ] ) diff --git a/UnitTesting/Sources/UnitTesting/RollbarTestHelper.swift b/UnitTesting/Sources/UnitTesting/RollbarTestHelper.swift new file mode 100644 index 00000000..dee66c00 --- /dev/null +++ b/UnitTesting/Sources/UnitTesting/RollbarTestHelper.swift @@ -0,0 +1,29 @@ +import Foundation + +@objc public class RollbarTestHelper: NSObject { + + private static let rollbarUnitTestEnvironment = "Rollbar-Apple-UnitTests"; + private static let rollbarUnitTestPayloadsAccessToken = "09da180aba21479e9ed3d91e0b8d58d6"; + private static let rollbarUnitTestDeploysWriteAccessToken = "efdc4b85d66045f293a7f9e99c732f61"; + private static let rollbarUnitTestDeploysReadAccessToken = "595cbf76b05b45f2b3ef661a2e0078d4"; + + + @objc public static func getRollbarEnvironment() -> String { + return RollbarTestHelper.rollbarUnitTestEnvironment; + } + + @objc public static func getRollbarPayloadsAccessToken() -> String { + return RollbarTestHelper.rollbarUnitTestPayloadsAccessToken; + } + + @objc public static func getRollbarDeploysWriteAccessToken() -> String { + return RollbarTestHelper.rollbarUnitTestDeploysWriteAccessToken; + } + + @objc public static func getRollbarDeploysReadAccessToken() -> String { + return RollbarTestHelper.rollbarUnitTestDeploysReadAccessToken; + } + + private override init() { + } +} diff --git a/RollbarNotifier/Tests/RollbarNotifierTests/RollbarTestUtil.swift b/UnitTesting/Sources/UnitTesting/RollbarTestUtil.swift similarity index 91% rename from RollbarNotifier/Tests/RollbarNotifierTests/RollbarTestUtil.swift rename to UnitTesting/Sources/UnitTesting/RollbarTestUtil.swift index a7eeff5a..e6a22b6e 100644 --- a/RollbarNotifier/Tests/RollbarNotifierTests/RollbarTestUtil.swift +++ b/UnitTesting/Sources/UnitTesting/RollbarTestUtil.swift @@ -7,9 +7,8 @@ import Foundation import RollbarCommon -import RollbarNotifier -class RollbarTestUtil { +@objc public class RollbarTestUtil: NSObject { private static let queuedItemsFileName = "rollbar.items"; private static let queuedItemsStateFileName = "rollbar.state"; @@ -32,7 +31,7 @@ class RollbarTestUtil { return filePath.path; } - public static func clearTelemetryFile() { + @objc public static func clearTelemetryFile() { let filePath = RollbarTestUtil.getTelemetryFilePath(); let fileManager = FileManager.default; let fileExists = fileManager.fileExists(atPath: filePath); @@ -46,7 +45,7 @@ class RollbarTestUtil { } } - public static func clearLogFile() { + @objc public static func clearLogFile() { let itemsStateFilePath = RollbarTestUtil.getQueuedItemsStateFilePath(); let itemsFilePath = RollbarTestUtil.getQueuedItemsFilePath(); let fileManager = FileManager.default; @@ -67,7 +66,7 @@ class RollbarTestUtil { } } - public static func readFirstItemStringsFromLogFile() -> String? { + @objc public static func readFirstItemStringsFromLogFile() -> String? { let filePath = RollbarTestUtil.getQueuedItemsFilePath(); let fileReader = RollbarFileReader(filePath: filePath, andOffset: 0); @@ -75,7 +74,7 @@ class RollbarTestUtil { return item; } - public static func readItemStringsFromLogFile() -> [String] { + @objc public static func readItemStringsFromLogFile() -> [String] { let filePath = RollbarTestUtil.getQueuedItemsFilePath(); let fileReader = RollbarFileReader(filePath: filePath, andOffset: 0); @@ -89,7 +88,7 @@ class RollbarTestUtil { return items; } - public static func readItemsFromLogFile() -> [NSMutableDictionary] { + @objc public static func readItemsFromLogFile() -> [NSMutableDictionary] { let filePath = RollbarTestUtil.getQueuedItemsFilePath(); let fileReader = RollbarFileReader(filePath: filePath, andOffset: 0); var items = [NSMutableDictionary] (); @@ -115,7 +114,7 @@ class RollbarTestUtil { return items; } - public static func waitForPesistenceToComplete(waitTimeInSeconds: TimeInterval = 0.5) { + @objc public static func waitForPesistenceToComplete(waitTimeInSeconds: TimeInterval = 0.5) { Thread.sleep(forTimeInterval: waitTimeInSeconds); } @@ -129,7 +128,7 @@ class RollbarTestUtil { } } - public static func makeTroubledCall() throws { + @objc public static func makeTroubledCall() throws { try makeInnerTroubledCall(); } @@ -159,7 +158,7 @@ class RollbarTestUtil { } -enum RollbarTestUtilError: Error { +public enum RollbarTestUtilError: Error { case basicError case simulatedError(errorDescription: String) case simulatedException(errorDescription: String, errorCallStack: [String] = Thread.callStackSymbols) @@ -167,7 +166,7 @@ enum RollbarTestUtilError: Error { } -protocol BackTracedErrorProtocol : Error /*OR LocalizedError OR CustomNSError*/ { +public protocol BackTracedErrorProtocol : Error /*OR LocalizedError OR CustomNSError*/ { var errorDescription: String { get } var errorCallStack: [String] { get } } diff --git a/UnitTesting/Sources/UnitTesting/RollbarUnitTestSettings.swift b/UnitTesting/Sources/UnitTesting/RollbarUnitTestSettings.swift deleted file mode 100644 index d89c71f1..00000000 --- a/UnitTesting/Sources/UnitTesting/RollbarUnitTestSettings.swift +++ /dev/null @@ -1,8 +0,0 @@ -import Foundation - -public struct RollbarUnitTestSettings { - public static let environment = "Rollbar-Apple-UnitTests"; - public static let payloadsPostAccessToken = "09da180aba21479e9ed3d91e0b8d58d6"; - public static let deploysWriteAccessToken = "efdc4b85d66045f293a7f9e99c732f61"; - public static let deploysReadAccessToken = "595cbf76b05b45f2b3ef661a2e0078d4"; -} diff --git a/UnitTests/RollbarUnitTestSettings.h b/UnitTests/RollbarUnitTestSettings.h deleted file mode 100644 index 69213114..00000000 --- a/UnitTests/RollbarUnitTestSettings.h +++ /dev/null @@ -1,16 +0,0 @@ -#ifndef RollbarUnitTestSettings_h -#define RollbarUnitTestSettings_h - -static NSString * const ROLLBAR_UNIT_TEST_ENVIRONMENT = -@"Rollbar-Apple-UnitTests"; - -static NSString * const ROLLBAR_UNIT_TEST_PAYLOADS_ACCESS_TOKEN = -@"09da180aba21479e9ed3d91e0b8d58d6"; - -static NSString * const ROLLBAR_UNIT_TEST_DEPLOYS_WRITE_ACCESS_TOKEN = -@"efdc4b85d66045f293a7f9e99c732f61"; - -static NSString * const ROLLBAR_UNIT_TEST_DEPLOYS_READ_ACCESS_TOKEN = -@"595cbf76b05b45f2b3ef661a2e0078d4"; - -#endif /* RollbarUnitTestSettings_h */ diff --git a/docs/README.md b/docs/README.md new file mode 100644 index 00000000..0c765f97 --- /dev/null +++ b/docs/README.md @@ -0,0 +1,6 @@ +# Rollbar-Apple SDK Documentation Folder + + +# Help / Support + +If you run into any problems, please email us at `support@rollbar.com` or [file a bug report](https://github.com/rollbar/rollbar-apple/issues/new). diff --git a/docs/SDK Intro.md b/docs/SDK Intro.md new file mode 100644 index 00000000..1f877691 --- /dev/null +++ b/docs/SDK Intro.md @@ -0,0 +1,202 @@ +# Rollbar-Apple SDK + +**Rollbar SDK for any Apple \*OS (macOS, ipadOS, iOS, tvOS, watchOS, ...)** + +**Written in Objective-C. Works with Swift** + +--- + +[TOC] + +## What is Rollbar-Apple SDK? + +Objective-C & Swift SDK for remote crash, exception, error reporting, and logging with Rollbar. + +It works on all Apple *OS platforms (macOS, ipadOS, iOS, tvOS, watchOS, etc). + +It is the preferred SDK for sending log payloads to [Rollbar](http://rollbar.com). + +## How is Rollbar-Apple SDK different from Rollbar-iOS SDK? + +Look at Rollbar-Apple SDK as the next major reincarnation of Rollbar-iOS SDK. +It is v2 of Rollbar-iOS SDK under a new name that better describes its purpose. + +Rollbar-iOS will be available for a while to allow our customers to make a move to Rollbar-Apple SDK when it most convenient to them. + +All the new feature development will be happening here within Rollbar-Apple SDK. + +## Where can I get the SDK from? + +Rollbar-Apple SDK is an open-source project available on GitHub. +Its releases are published on GitHub as well. +The SDK can also be integrated into your codebase from the following package distribution systems: + +- Swift Package Manager (also known as SwiftPM or SPM) +- Cocoapods +- Carthage + +## Pay Attention + +Depending on the specific package management system, the SDK is available either as the whole (under `Rollbar-Apple` name) or on a per-module basis (for example, `RollbarCommon`, `RollbarNotifier`, `RollbarDeploys`, etc). + +Some package distribution systems also host packages associated with the older incarnation of this SDK, called Rollbar-iOS, that used to be published under Rollbar package name and versioned at either `v0.n.n` or `v1.n.n`. + +All the Rollbar-Apple SDK releases (and packages) versioned starting from v2 (since, as we already explained above, Rollbar-Apple is the `v2` of Rollbar-iOS SDK renamed into Rollbar-Apple). + + +## Getting Help and Support + +- [Gitter Community](https://gitter.im/rollbar/SDK-Apple) +- [Stack Overflow](https://stackoverflow.com/questions/tagged/rollbar) +- [GitHub Issues](https://github.com/rollbar/rollbar-apple/issues) +- [GitHub Discussions](https://github.com/rollbar/rollbar-apple/discussions) +- [File a bug report](https://github.com/rollbar/rollbar-apple/issues/new) +- Rollbar Support: `support@rollbar.com` + +## SDK Modules/Packages + +*RollbarNotifier* is the package that implements the `RollbarLogger` (i.e. Notifier) - that is the thing that supports a lot of configurational options and allows to capture, package, and forward (to the preconfigured Rollbar Project on rollbar.com) exceptions, errors, log messages, telemetry, and custom data. + +We offer a couple of optional crash reporting alternatives - one based on *KSCrash* and another one based on *PLCrashReporter*. Each package (*RollbarKSCrash*` or `*RollbarPLCrashReporter*) implements its own crash report collector adapter to a corresponding third-party crash reporter. +A collector is optional and can be supplied into a notifier (`RollbarLogger`) initializer along with the required `RollbarConfig` instance. + +*RollbarAUL* module implements *RollbarNotifier* integration with Apple Unified Logging (AUL) and allows capture of the AUL entries as corresponding Rollbar Telemetry log events. + +*RollbarSwift* implements components useful in cases when the SDK is used by a client code written in Swift. For example, any call chain made from Swift that eventually resolves into an Objective-C code being invoked can potentially produce an NSException that Swift cannot handle natively. So, the module provides utility classes and components that are helping to either handle or process such scenarios. + +*RollbarDeploys* is the package that should be used, for example by your CI Release pipeline, to track/manage your application releases/deployments so they are reported to the Rollbar Project and Rollbar would correlate the incoming payloads with specific deployment instance. + +*RollbarCommon* is just a shared package with types used by any of the other packages as well as some potentially useful public utility classes that you may find useful. + +## Installation + +Here are a few alternatives for installing the SDK into your software projects: + +### Via [GitHub](https://github.com/rollbar/rollbar-apple) + +Here are a few options: + +- you can download or clone the SDK source code directly from the GitHub repo; +- you can download a source code snapshot of a specific release from the repo Release page; +- you can integrate the the GitHub repo as a git submodule of your project git repository. + +### Via [Swift Package Manager](https://github.com/apple/swift-package-manager) + +For example, in Xcode, by pointing your project's build target SPM settings to https://github.com/rollbar/rollbar-apple.git repository and specifying the desired release version, or branch, or commit. + +### Via [Carthage](https://github.com/Carthage/Carthage) + +In your *Cartfile*, specify: + +```txt +github "rollbar/rollbar-apple" ~> n.n.n +``` + +where `n.n.n` is the desired pod version of the SDK to use. + +### Via [Cocoapods](https://cocoapods.org/) + +The SDK is configured for *Cocoapods* distribution on a pod-per-module basis, so you will have to separately specify each module pod dependency as needed. For example: + +```txt +pod "RollbarNotifier", "~> n.n.n" +pod "RollbarDeploys", "~> n.n.n" +``` + +where `n.n.n` is the desired pod version of the SDK to use. As the general rule, for multiple modules try using the same version. + +You do not have to worry about explicitly including other internal dependencies of the modules, like *RollbarCommon* module pod. The SDK modules' *podspec*s already specify these as needed. + +## Using SDK in Your Code + +### Import Necessary SDK Modules + +Before using any of the types provided by the SDK modules, you need to make sure you import the modules you need. For example: + +#### Objective-C + +```Obj-C +@import RollbarNotifier; +@import RollbarKSCrash; // optional +@import RollbarPLCrashReporter; // optional alternative to RollbarKSCrash +``` + +#### Swift + +```Swift +import RollbarNotifier +import RollbarKSCrash // optional +import RollbarPLCrashReporter // optional alternative to RollbarKSCrash +``` + +### Define the Shared Notifier's Configuration Instance + +When setting up a notifier configuration you must at least specify your Rollbar Project's access token: + +#### Objective-C + +```Obj-C +RollbarConfig *config = [RollbarConfig new]; +config.destination.accessToken = @"YOUR_PROJECT_ACCESS_TOKEN"; +config.destination.environment = @"YOUR_ENVIRONMENT"; +``` + +#### Swift + +```Swift +let config = RollbarConfig() +config.destination.accessToken = "YOUR_PROJECT_ACCESS_TOKEN" +config.destination.environment = "ENVIRONMENT" +``` + +### Optionally, Define A Crash Report Collector Instance + +#### Objective-C + +```Obj-C + +id crashCollector = + [[RollbarPLCrashCollector alloc] init]; + //OR [[RollbarKSCrashCollector alloc] init]; + //OR nil; +``` + +#### Swift + +```Swift + +let crashCollector = RollbarPLCrashCollector() +//OR let crashCollector = RollbarKSCrashCollector() +``` + +### Initialize the Shared Notifier + +#### Objective-C + +```Obj-C +[Rollbar initWithConfiguration:config]; +//OR [Rollbar initWithConfiguration:config crashCollector:crashCollector]; +``` + +#### Swift + +```Swift +Rollbar.initWithConfiguration(config) +//OR Rollbar.initWithConfiguration(config, crashCollector: crashCollector) +``` + +### Start Logging using the Shared Notifier + +#### Objective-C + +```Obj-C +[Rollbar infoMessage:@"See this message on your Rollbar Project Dashboard..."]; +``` + +#### Swift + +```Swift +Rollbar.infoMessage("See this message on your Rollbar Project Dashboard...") +``` + +There are other dedicated method overloads for logging `NSException`s, `NSError`s with different levels of log severity. \ No newline at end of file diff --git a/docs/SDK module - RollbarAUL.md b/docs/SDK module - RollbarAUL.md new file mode 100644 index 00000000..f1b97a9c --- /dev/null +++ b/docs/SDK module - RollbarAUL.md @@ -0,0 +1,99 @@ +# SDK Module: RollbarAUL + +This module implements `RollbarNotifier` integration with *Apple Unified Logging (AUL)* and allows capture of the AUL entries as corresponding Rollbar Telemetry log events. + +--- + +## Essential Components of the Module + +### `RollbarAulStoreMonitorOptions` DTO + +It implements configurational options for collecting relevant log entries from the Apple Unified Logging (AUL) store. +You can specify here lists of AUL subsystems and categories of interest. When these lists are empty, all the entries from the local AUL store related to the application process will be collected from the store. + +### `RollbarAulStoreMonitor` Service + +It implements a singleton-like component that monitors the AUL local store and retrieves relevant entries from it based on provided `RollbarAulStoreMonitorOptions` instance. These entries will be captured as Rollbar Telemetry log events. Hence, the Telemetry must be enabled as well as its capture of the log entries. +This component implements the following key protocols. + +### `RollbarAulStoreMonitoring` Protocol + +Allows to start and cancel the monitoring service as well as provides optional methods to configure the service with custom `RollbarAulStoreMonitorOptions` and/or a custom `RollbarLogger` instance. + +### `RollbarSingleInstancing` Protocol + +Defines access to the singleton of the type implementing this protocol. +Optionally, defines methods to test on the singleton instance existence and a method to define custom singleton deallocation logic. + + + +## Examples + +### Using the RollbarAulStoreMonitor to capture the application AUL entries + +1. Make sure you have properly configured `RollbarConfig` instance and the Telemetry and its log capture options are both enabled. +2. Setup a `RollbarLogger` instance with that `RolbarConfig` instance. +3. Configure the `RollbarAulStoreMonitor` service with that `RollbarLogger` instance. +4. Optionally, you can create a custom-configured `RollbarAulStoreMonitorOptions` instance and configure the `RollbarAulStoreMonitor` service with it. +5. Start the `RollbarAulStoreMonitor` service. +6. Any AUL entry made from your application process will be collected by the SDK as corresponding Telemetry log events according to the provided `RollbarAulStoreMonitorOptions`... + +#### Objective-C + +```Obj-C +// Create proper RollbarConfig instance making sure +// the Telemetry and its log capture are enabled: +RollbarConfig *rollbarConfig = [[RollbarConfig alloc] init]; +rollbarConfig.destination.accessToken = @""; +rollbarConfig.destination.environment = @""; +rollbarConfig.developerOptions.transmit = YES; +rollbarConfig.telemetry.enabled = YES; // required for AUL capture +rollbarConfig.telemetry.captureLog = YES; // required for AUL capture +rollbarConfig.telemetry.maximumTelemetryData = 100; + +// Setup shared RollbarLogger with the config: +[Rollbar initWithConfiguration:rollbarConfig]; + +// Configure the AUL monitor with the logger: +[RollbarAulStoreMonitor.sharedInstance configureRollbarLogger:Rollbar.currentLogger]; + +// Optionally, configure the AUL monitoring options: +RollbarAulStoreMonitorOptions *aulMonitorOptions = +[[RollbarAulStoreMonitorOptions alloc] init]; +[aulMonitorOptions addAulSubsystem:@"DataAccessLayer"]; +[aulMonitorOptions addAulSubsystem:@"Model"]; +[aulMonitorOptions addAulCategory:@"CompanyOrg"]; +[RollbarAulStoreMonitor.sharedInstance configureWithOptions:aulMonitorOptions]; + +// Start the AUL monitoring: +[RollbarAulStoreMonitor.sharedInstance start]; +``` + +#### Swift + +```Swift +// Create proper RollbarConfig instance making sure +// the Telemetry and its log capture are enabled: +let config = RollbarConfig(); +config.destination.accessToken = ""; +config.destination.environment = ""; +config.developerOptions.transmit = true; +config.telemetry.enabled = true; +config.telemetry.captureLog = true; + +// Setup shared RollbarLogger with the config: +Rollbar.initWithConfiguration(config); + +// Configure the AUL monitor with the logger: +RollbarAulStoreMonitor.sharedInstance().configureRollbarLogger(Rollbar.currentLogger()); + +// Optionally, configure the AUL monitoring options: +let aulOptions = RollbarAulStoreMonitorOptions(); +aulOptions.addAulSubsystem("DataAccessLayer"); +aulOptions.addAulSubsystem("Model"); +aulOptions.addAulCategory("CompanyOrg"); +RollbarAulStoreMonitor.sharedInstance().configure(with: aulOptions); + +// Start the AUL monitoring: +RollbarAulStoreMonitor.sharedInstance().start(); +``` diff --git a/docs/SDK module - RollbarCocoaLumberjack.md b/docs/SDK module - RollbarCocoaLumberjack.md new file mode 100644 index 00000000..bf2d27e6 --- /dev/null +++ b/docs/SDK module - RollbarCocoaLumberjack.md @@ -0,0 +1,81 @@ +# SDK Module: RollbarCocoaLumberjack + +This SDK module implements integration of Rollbar into the popular CocoaLumberjack logging framework. + +So if you either already use CocoaLumberjack or you are planning to use it for your software product logging needs, then you can easily integrate Rollbar into it via this module and have all or some of the logs performed via the *CocoaLumberjack* framework redirected into a dedicated Rollbar project at www.rollbar.com and monitor the health of your software product/service remotely. + +--- + +## Essential Components of the Module + +### `RollbarCocoaLumberjackLogger` + +Implements CocoaLumberjack compatible logger (`DDLogger`) capable of "intercepting" log events going through the CocoaLumberjack infrastructure, converting them to Rollbar compatible payloads, and sending the payloads to a Rollbar.com Project. + +## Examples + +### Integrating Rollbar-Apple into existing CocoaLumberjack use case + +1. Identify place(s) in the code where you already define currently used CocoaLumberjack loggers. That is where you would want to also add a `RollbarCocoaLumberjackLogger` instance. +2. Accordingly, import our *RollbarCocoaLumberjack* module. +3. Setup properly configured `RollbarConfig` object. +4. Create a `RollbarCocoaLumberjackLogger` instance using the preconfigured `RollbarConfig` instance and add it to the `DDLog` +5. From this point on, all relevant log entries made anywhere via the *CocoaLumberjack* logging methods will be "forked" to Rollbar based on filtering conditions specified on both levels: *CocoaLumberjackLogger* configuration and in `RollbarConfig` instances defined above. + +#### Objective-C + +```Obj-C +//... +#define LOG_LEVEL_DEF ddLogLevel +//... +@import CocoaLumberjack; +@import RollbarCocoaLumberjack; +//... + +//... + // setting up CocoaLumberjack usage: + [DDLog addLogger:[DDOSLogger sharedInstance]]; + + DDFileLogger *fileLogger = [[DDFileLogger alloc] init]; + fileLogger.rollingFrequency = 60 * 60 * 24; // 24 hour rolling + fileLogger.logFileManager.maximumNumberOfLogFiles = 1; + // the above code tells the application to keep a day worth of log files on the system. + [DDLog addLogger:fileLogger]; + + // create a valid RTollbar config: + RollbarConfig *config = [[RollbarConfig alloc] init]; + config.destination.accessToken = @"ROLLBAR_ACCESS_TOKEN"; + config.destination.environment = @"ROLLBAR_ENVIRONMENT"; + + // add Rollbar logger plug-in for CocoaLumberjack: + [DDLog addLogger:[RollbarCocoaLumberjackLogger createWithRollbarConfig:config]]; +//... +``` + +#### Swift + +```Swift +//... +import CocoaLumberjackSwift +import RollbarCocoaLumberjack +//... + +//... + // setting up CocoaLumberjack usage: + dynamicLogLevel = DDLogLevel.debug; + DDLog.add(DDOSLogger.sharedInstance); + + let ddFileLogger = DDFileLogger(); + ddFileLogger.rollingFrequency = 60 * 60 * 24; // 24-hours rolling + ddFileLogger.logFileManager.maximumNumberOfLogFiles = 1; + // the above code tells the application to keep a day worth of log files on the system. + DDLog.add(ddFileLogger); + + // create a valid RTollbar config: + let rollbarConfig = RollbarConfig(); + rollbarConfig.destination.accessToken = RollbarTestHelper.getRollbarPayloadsAccessToken(); + rollbarConfig.destination.environment = RollbarTestHelper.getRollbarEnvironment(); + + // add Rollbar logger plug-in for CocoaLumberjack: + DDLog.add(RollbarCocoaLumberjackLogger.create(with: rollbarConfig)); +``` diff --git a/docs/SDK module - RollbarSwift.md b/docs/SDK module - RollbarSwift.md new file mode 100644 index 00000000..e4706920 --- /dev/null +++ b/docs/SDK module - RollbarSwift.md @@ -0,0 +1,58 @@ +# SDK Module: RollbarSwift + +This module implements components useful in cases when the SDK is used by a client code written in Swift. For example, any call chain made from Swift that eventually resolves into an Objective-C code being invoked can potentially produce an NSException that Swift cannot handle natively. So, the RollbarSwift module provides utility classes and components that are helping to either handle or process such scenarios. + +--- + +## Essential Components of the Module + +### `RollbarTryCatch` + +This utility class provides an API to try Swift code blocks and to catch and to either handle or process any of `NSException` instances if thrown from the tried block. + +### `RollbarExceptionGuard` + +This component is meant to be initialized with a preconfigured instance of `RollbarLogger` so it can be used to try/guard a block of Swift code in cases when it might cause throwing of an `NSException` and to automatically report such `NSException` (if any) to a Rollbar.com Project. It also provides an alternative method that in addition converts the intercepted `NSException` into a matching `NSError` that could be natively tied and handled from within the Swift code. + +## Examples + +### Guarding Swift code that could potentially throw a NSException and reporting the exception (if any) to Rollbar + +#### Swift + +```Swift +func generateObjCException() { + + //simulating Obj-C NSException: + RollbarTryCatch.throw("NSException from Obj-C..."); +} + +func handleObjCExceptionWithRollbar() { + + let exceptionGuard = createGuard(); + var success = true; + //execute code block while guarding it with RollbarExceptionGuard: + success = exceptionGuard.tryExecute { + self.generateObjCException(); + } + //if there was an NSException thrown withing the guarded block of code, + //the guard instance would return NO and internally report the + //exception details to Rollbar. + + print("Guarded execution succeeded: \(success)."); +} + +func createGuard() -> RollbarExceptionGuard { + + let config = RollbarConfig(); + config.destination.accessToken = "2ff...0f3"; + config.destination.environment = "samples"; + config.developerOptions.transmit = true; + + let logger = RollbarLogger(configuration: config); + + let exceptionGuard = RollbarExceptionGuard(logger: logger); + + return exceptionGuard; +} +``` diff --git a/docs/SDK module - RollbarZZZ.md b/docs/SDK module - RollbarZZZ.md new file mode 100644 index 00000000..1f335c1b --- /dev/null +++ b/docs/SDK module - RollbarZZZ.md @@ -0,0 +1,31 @@ +# SDK Module: RollbarZZZ + +This module implements components useful in cases when the SDK is used ... + +--- + +## Essential Components of the Module + +### `RollbarComp1` + +This utility class provides ... + +### `RollbarComp2` + +This component is meant to be initialized with ... + +## Examples + +### Example title + +#### Objective-C + +```Obj-C + +``` + +#### Swift + +```Swift + +```