Using the WeblogNG iOS client library follows an easy three-step process:
- add the WNGLogger library dependency to your project
- integrate the WNGLogger library into your application
- create dashboard and charts with your metrics
The WNGLogger library is available via CocoaPods and is the recommended installation path.
You can install it by adding a WNGLogger dependency to your Podfile:
pod 'WNGLogger', :git => 'https://github.com/weblogng/weblogng-client-iOS.git', :tag => '0.8.1'
Execute pod install. There should be some output like:
$ pod install
Analyzing dependencies
Pre-downloading: `WNGLogger` from `https://github.com/weblogng/weblogng-client-iOS.git`, tag `0.8.1`
Downloading dependencies
Using AFNetworking (2.4.1)
Using JRSwizzle (1.0)
Installing WNGLogger 0.8.1
Generating Pods project
Integrating client project
- sign-up for WeblogNG
- add the WNGLogger header file
- instantiate the Logger object using your api key and application name
- find or generate an api key on your WeblogNG account page
- recommendation: Store the sharedLogger in a convenient place to make it easy to use throughout the application
- send metrics with the values recorded by your application
Here is some example code taken from the (super-simple) WeblogNG iOS Sample App for iOS that demonstrates the basic usage:
#import <WNGLogger/logger.h>
#import <WNGLogger/NSURLConnection+WNGLogging.h>
@implementation WNGAppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
NSString *apiKey = @"specify your api key here";
NSString *application = @"specify your application name here";
[WNGLogger initSharedLogger:apiKey application:application];
//enable automatic measurement of http requests!
[NSURLConnection wng_enableLogging];
[self someIntensiveLogic];
//time execution of an arbitrary block
[[WNGLogger sharedLogger] executeWithTiming:@"sample-app-anExpensiveBlock" aBlock:^(void){
int millis_to_sleep = 250 + arc4random_uniform(250);
float seconds_to_sleep = ((float) millis_to_sleep) / 1000;
[NSThread sleepForTimeInterval:seconds_to_sleep];
}];
return YES;
}
- (void) someIntensiveLogic {
NSString *metricName = @"sample-app-someIntensiveLogic";
[[WNGLogger sharedLogger] recordStart:metricName];
int millis_to_sleep = 500 + arc4random_uniform(250);
float seconds_to_sleep = ((float) millis_to_sleep) / 1000;
[NSThread sleepForTimeInterval:seconds_to_sleep];
[[WNGLogger sharedLogger] recordFinishAndSendMetric:metricName];
}
@end- run your app, executing code timed with the library; this will report raw metric data to the WeblogNG api
- go to WeblogNG, create a dashboard, and add a chart with your data