Coder Social home page Coder Social logo

afnetworkinglogger's Introduction

AFNetworkingLogger

AFNetworkingLogger example

Overview

AFNetworkingLogger is a grateful child of AFHTTPRequestOperationLogger created by Mattt Thompson (@mattt) for AFNetworking library. It is not the one: there is also its closest brother and companion AFNetworkingMeter - they share similar design and are both built for the same purpose: to make a HTTP-logging routine for a daily basis of iOS/Mac development easy and informative.

Features list:

  • Logging of HTTP interactions performed by iOS / Mac OS X applications. AFNetworkingLogger logs the following HTTP data:

    • HTTP methods: GET, POST, ...
    • HTTP headers Keep-Alive, Last-Modified, ...
    • HTTP body: no comments. Large bodies are truncated
    • HTTP size: headers + body.
    • HTTP elapsed time: a time beetween AFNetworkingOperationDidStartNotification and AFNetworkingOperationDidFinishNotification.
  • Two levels of verbosity: normal (one string for one request like in AFHTTPRequestOperationLogger) and verbose (example above).

  • Logging HTTP errors and networking errors: both HTTP 400-600 errors and Cocoa NSURL-based errors (NSURLErrorNotConnectedToInternet and friends).

  • Error-only logging.

  • Remote logging: configure AFNetworkingLogger for logging inside your TestFlight builds by writing custom C function to stand proxy for TestFlight's TFLog/TFLogv functions.


Note. AFNetworkingLogger does not support logging of NSURLSession-based operations.


Installation

The recommended way is to install via Cocoapods:

Add into your Podfile:

pod 'AFNetworkingLogger', :git => 'https://github.com/stanislaw/AFNetworkingLogger'

And run pod update.

or you can just clone AFNetworkingLogger repository using git clone and copy the contents of its AFNetworkingLogger/ folder to your project.

Usage

You need to start AFNetworkingLogger somewhere. For example, your app's delegate is a good place to do this:

#import <AFNetworkingLogger.h>

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{
    [AFNetworkingLogger.sharedLogger startLogging];

    return YES;
}

Configuration

Logging levels

AFNetworkingLogger.sharedLogger.level = AFNetworkingLoggerLevelVerbose;

Output

[AFNetworkingLogger sharedLogger].output = &printf; // Any other printf-like function is fine.

Errors-only logging

The following will make AFNetworkingLogger to register only erroneuous HTTP responses: HTTP 400-600 errors and/or Cocoa NSURLError-based errors (including non-HTTP connection errors likeNSURLErrorNotConnectedToInternet).

[AFNetworkingLogger sharedLogger].errorsOnlyLogging = YES; 

Remote logging

The following is an example of how to configure an iOS application for remote logging while it performs its TestFlight:

#import <TestFlightSDK/TestFlight.h>

int AFNetworkingRemoteLoggingCFunction(const char * format, ... ) {
    va_list arguments;

    va_start(arguments, format);

    NSString *formatString = [NSString stringWithUTF8String:format];

    TFLogv(formatString, arguments);

    va_end(arguments);

    return 0;
}

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    
    // see https://github.com/stanislaw/iosenv
    if (isProduction()) { 
        [AFNetworkingLogger sharedLogger].output = &AFNetworkingRemoteLoggingCFunction;
        [AFNetworkingLogger sharedLogger].errorsOnlyLogging = YES;
        [AFNetworkingLogger startLogging];
    }
    
    // ...

    return YES;
}

Notes

  • Currently AFNetworkingLogger calculates HTTP headers size using -[NSPropertyListSerialization dataFromPropertyList:... (-[NSURLRequest allHTTPHeaderFields] => NSData). Let me know if there is a more precise way of doing this.
  • This line is designated for excuses about Russian/Ukrainian english that probably resulted in some misspelings exist somewhere in this README. The author will be thankful for any spelling corrections that might appear.

Credits

AFNetworkingLogger was created by Stanislaw Pankevich.

Thanks to Marina Balioura (@mettta) for her amazing contribution to the design of AFNetworkingLogger console-text output format: rigorous, clear and informative.

AFNetworkingLogger is a plugin for AFNetworking library created by Mattt Thompson.

AFNetworkingLogger is inspired by the design of the similar AFNetworking plugin AFHTTPRequestOperationLogger, that was as well created by Mattt Thompson.

Copyright

Copyright (c) 2013, 2014 Stanislaw Pankevich. See LICENSE for details.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.