Unfortunately at this time, the Carthage module is only compatable with iOS. tvOS builds will have to use Cocoapods.
This is a forked version from AFNetworking/AFNetworkActivityLogger. The reason why this was forked is that the original repo DOES NOT have (as of 05/29/2017) a 3.0.0
version or above that will work with AFNetworking 3.0.0
or above. This repo contains a Carthage/Cocoapod versions that can be pulled in to other projects that will function correctly with AFNetworking version 3.0.0
or above.
- Update code that is required.
- Add any new public header files to AFNetworkActivityLogger.h.
- Bump version number (
CFBundleShortVersionString
) in Supporting Files/Info.plist. - Verify project builds.
- In the root directory run the following:
$ carthage build --no-skip-current
$ carthage archive
- Bump version number in AFNetworkActivityLogger.podspec (same number as step 3).
- Tag current
3_0_0
branch to the same number as the version number from steps 3 and 4, and push to Github. - Go to Github releases page for Reachability.
- Click on the release of the version you tagged and uploaded to Github.
- Add release notes, and attach Reachability.framework.zip that was created from step 5 to the release.
- Click "Update Release."
- In the root directory run the following:
$ pod repo push PrivateCocoapodSpecs AFNetworkActivityLogger.podspec
- Update this
README.md
pod version badge number.
AFNetworkActivityLogger
is an extension for AFNetworking 3.0 that logs network requests as they are sent and received.
AFNetworkActivityLogger
listensAFNetworkingTaskDidStartNotification
andAFNetworkingTaskDidFinishNotification
notifications, which are posted by AFNetworking as session tasks are started and finish. For further customization of logging output, users are encouraged to implement desired functionality by creating new objects that conform toAFNetworkActivityLoggerProtocol
.
3.0.0 featured the following breaking API changes:
- The log
level
property is now found on the individual unique loggers, rather than the shared logger. This allows for more advanced customization options for logging level. - The
filterPredicate
property is now found on the individual unique loggers, rather than the shared logger. This allows for more advanced customization options for logging specific requests.
Add the following code to AppDelegate.m -application:didFinishLaunchingWithOptions:
:
[[AFNetworkActivityLogger sharedLogger] startLogging];
Now all NSURLSessionTask
objects created by an AFURLSessionManager
will have their request and response logged to the console, a la:
GET http://example.com/foo/bar.json
200 http://example.com/foo/bar.json [0.1860 s]
If the default logging level is too verbose—say, if you only want to know when requests fail—then changing it is as simple as:
[[AFNetworkActivityLogger sharedLogger] setLevel:AFLoggerLevelError];
By default, the shared logger is configured with an AFNetworkActivityConsoleLogger
with a debug level set to AFLoggerLevelInfo
. To change the level, simply access the logger through the loggers
property, and adjust the level. The following levels are provided:
AFLoggerLevelOff
: Do not log requests or responses.AFLoggerLevelDebug
:Logs HTTP method, URL, header fields, & request body for requests, and status code, URL, header fields, response string, & elapsed time for responses.AFLoggerLevelInfo
: Logs HTTP method & URL for requests, and status code, URL, & elapsed time for responses.AFLoggerLevelError
: Logs HTTP method & URL for requests, and status code, URL, & elapsed time for responses, but only for failed requests.
To limit the requests that are logged by a unique logger, each object that conforms to AFNetworkActivityLoggerProtocol
has a filterPredicate
property. If the predicate returns true, the request will not be forwarded to the logger. For example, a custom file logger could be created that only logs requests for http://httpbin.org
, while a console logger could be used to log all errors in the application.
AFNetworkActivityConsoleLogger *testLogger = [AFNetworkActivityConsoleLogger new];
NSPredicate *predicate = [NSPredicate predicateWithBlock:^BOOL(NSURLRequest * _Nonnull request, NSDictionary<NSString *,id> * _Nullable bindings) {
return !([[request URL] baseURL] isEqualToString:@"httpbin.org"])
}];
[testLogger setFilterPredicate:predicate];
By default, the shared logger is configured with an AFNetworkActivityConsoleLogger
.
To create a custom logger, create a new object that conforms to AFNetworkActivityLoggerProtocol
, and add it to the shared logger. Be sure and configure the proper default logging level.
AFNetworkActivityLogger is available under the MIT license. See the LICENSE file for more info.