Add and report events
Add and report events
In addition to reporting the sequence of events leading up to an app crash, Splunk MINT can report events that are not associated with a crash. For example, if your application asks users to make a selection, you can report the user's selection.
To report an event:
- Use the logEventAsyncWithTag:completionBlock: method.
- Use the logEventAsyncWithName:completionBlock: method.
You can also include the log level with the event. Use one of the following enumeration values for the LogLevelStatus parameter:
- DebugLogLevel
- InfoLogLevel
- NoticeLogLevel
- WarningLogLevel
- ErrorLogLevel
- CriticalLogLevel
- AlertLogLevel
- EmergencyLogLevel
Add as many events as you like to track virtually any user activity on your app. To view the event data, see the Events dashboard in Splunk MINT Management Console.
Example code
[[Mint sharedInstance] logEventAsyncWithTag:@"Log Custom Event tag" completionBlock:^(MintLogResult *splunkLogResult) { NSString* logResultState = mintLogResult.resultState == OKResultState ? @"OK" : @"Error" NSLog(@"Log result: %@", logResultState) }]; [[Mint sharedInstance] logEventAsyncWithName:@"LoginButton" logLevel:InfoLogLevel andCompletionBlock:^(MintLogResult *result){}];
Add custom data to events
You can add extra custom data to specific events as a list or as a key-value pair. Custom data can only be viewed using the Splunk MINT App.
Example code
// Objective-C [[Mint sharedInstance] logEventAsyncWithName:@"Log Custom Event tag" logLevel:DebugLogLevel extraDataKey:@"test1" extraDataValue:@"testvalue1" andCompletionBlock:^(MintLogResult *result) { NSString *resultState = result.resultState? @"Success": @"Failed"; NSLog(@"Log Event Result:%@", resultState); } ]; LimitedExtraDataList* extraDataList = [LimitedExtraDataList new]; [extraDataList addWithKey:@"Extra Key1" andValue:@"Extra Value1"]; [extraDataList addWithKey:@"Extra Key2" andValue:@"Extra Value2"]; [[Mint sharedInstance] logEventAsyncWithName:@"Log Custom Event tag" logLevel:DebugLogLevel limitedExtraDataList:extraDataList andCompletionBlock:^(MintLogResult *result) { NSString *resultState = result.resultState? @"Success": @"Failed"; NSLog(@"Log Event Result:%@", resultState); } ]; [[Mint sharedInstance] logEventAsyncWithName:@"Log Custom Event" logLevel:DebugLogLevel extraDataKey:@"test" extraDataValue:@"testvalue" andCompletionBlock:^(MintLogResult *result) { NSString *resultState = result.resultState? @"Success": @"Failed"; NSLog(@"Log Event Result:%@", resultState); } ]; LimitedExtraDataList* extraDataList = [LimitedExtraDataList new]; [extraDataList addWithKey:@"Extra Key1" andValue:@"Extra Value1"]; [extraDataList addWithKey:@"Extra Key2" andValue:@"Extra Value2"]; [[Mint sharedInstance] logEventAsyncWithName:@"Log custom event tag" logLevel:DebugLogLevel limitedExtraDataList:extraDataList andCompletionBlock:^(MintLogResult *result) { NSString *resultState = result.resultState? @"Success": @"Failed"; NSLog(@"Log Event Result:%@", resultState); } ];
// Swift Mint.sharedInstance().logEventAsyncWithTag("Log Custom Event tag", extraDataKey: "test1", extraDataValue: "testvalue1") { (logResult) -> Void in let result = logResult.resultState.rawValue == OKResultState.rawValue ? "OK" : "Failed" print("Log Event Result: \(result)"); } var dataList:LimitedExtraDataList = LimitedExtraDataList() dataList.addWithKey("test1", andValue: "testvalue1") dataList.addWithKey("test2", andValue: "testvalue2") Mint.sharedInstance().logEventAsyncWithTag("Log Custom Event tag", limitedExtraDataList:dataList) { (logResult) -> Void in let result = logResult.resultState.rawValue == OKResultState.rawValue ? "OK":"Failed" print("Log Event Result:\(result)") } Mint.sharedInstance().logEventAsyncWithName("Log Custom Event tag", logLevel:DebugLogLevel , extraDataKey: "test", extraDataValue: "testvalue") { (logResult) -> Void in let result = logResult.resultState.rawValue == OKResultState.rawValue ? "OK" : "Failed" print("Log Event Result: \(result)"); } var dataList:LimitedExtraDataList = LimitedExtraDataList() dataList.addWithKey("test1", andValue: "testvalue1") dataList.addWithKey("test2", andValue: "testvalue2") Mint.sharedInstance().logEventAsyncWithName("Log custom event tag", logLevel: DebugLogLevel, limitedExtraDataList: dataList) { (logResult) -> Void in let result = logResult.resultState.rawValue == OKResultState.rawValue ? "OK":"Failed" print("Log Event Result:\(result)") }
View custom data
To view custom data for events, open the Splunk MINT App and run a search. For example, the following search shows the events that contain custom data for "hotel":
index=mint event_name=* extraData.hotel=* | table event_name, extraData.hotel
For more about running searches in MINT, see Searches in the Splunk MINT App User Guide.
Monitor transactions | Dispatch system log messages |
This documentation applies to the following versions of Splunk MINT™ SDK for iOS (EOL): 4.1.x, 4.2.x, 4.3.x, 4.4.x
Feedback submitted, thanks!