Simple network activity logger for iOS

Overview

ackee|Reqres

Tests Version License Carthage Compatible Platform

Reqres is a simple library for logging all requests and responses in your app. It supports Alamofire and also requests made via native NSURLSession.

⬆️ POST 'https://ackee.cz/examples'
Headers: [
    Accept-Encoding : gzip;q=1.0, compress;q=0.5
    Accept-Language : en-US;q=1.0
    Content-Type : application/json
    User-Agent : Reqres_Example/org.cocoapods.demo.Reqres-Example (1; OS Version 9.3 (Build 13E230))
    Content-Length : 13
]
Body: {
    "foo" : "bar"
}

...

⬇️ POST https://ackee.cz/examples (✅ 201 Created) [time: 0.54741 s]
Headers: [
    Vary : Authorization,Accept-Encoding
    Content-Encoding : gzip
    Content-Length : 13
    Server : Apache
    Content-Type : application/json
    Date : Mon, 05 Sep 2016 07:33:51 GMT
    Cache-Control : no-cache
]
Body: {
    "foo" : "bar"
}

Installation

CocoaPods

Reqres is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod "Reqres"

Carthage

You can use Carthage. Specify in Cartfile:

github "AckeeCZ/Reqres"

Run carthage update to build the framework and drag the built Reqres.framework into your Xcode project. Follow build instructions. New Issue.

Usage

Initialization is different for usage with Alamofire and NSURLSession.

Alamofire

Create your SessionManager with proper configuration to make it work with Alamofire.

let configuration = Reqres.defaultSessionConfiguration()
configuration.httpAdditionalHeaders = SessionManager.defaultHTTPHeaders
let alamofireManager = SessionManager(configuration: configuration)
Reqres.sessionDelegate = alamofireManager.delegate

Then you must use this manager for all requests, so replace all Alamofire.request(...) to alamofireManager.request(...)

Usage without Alamofire

Register Reqres on application startup and it will monitor and log any requests you make via NSURLSession or NSURLConnection.

Reqres.register()

Customization

You can do some settings to make it fit your needs.

Custom logger

Reqres uses default print() for logging to avoid unnecessary dependencies but it's ready for any logging framework. Make your custom logger class which complies to ReqresLogging protocol and set it to Reqres, that's all.

class MyLogger: ReqresLogging {
    ...
}

Reqres.logger = MyLogger()

Log level

You can use 3 different log levels:

  • None - made for production use, it completely disables all Reqres functionality
  • Light - Logs only basic info (method, url, status code and time)
⬆️ POST 'https://ackee.cz/examples'
...
⬇️ POST https://ackee.cz/examples (✅ 201 Created) [time: 0.54741 s]
  • Verbose - Logs also headers and body (see example above)

Reqres uses Verbose log level by default. To change log level just set right value to Reqres.logger.logLevel

Emoji

Reqres uses emoji to make log better to read and to make it at least a little funny and nice. If you dont't like that, you can turn it off of course.

Reqres.allowUTF8Emoji = false

Forking this repository

If you use Reqres in your projects drop us as tweet at @ackeecz. We would love to hear about it!

Sharing is caring

This tool and repo has been opensourced within our #sharingiscaring action when we have decided to opensource our internal projects.

Author

Ackee team. We were inspired by andysmart's Timberjack

License

Reqres is available under the MIT license. See the LICENSE file for more info.

Comments
  • WIP: automatically use Reqres where code is using it's own NSURLSession

    WIP: automatically use Reqres where code is using it's own NSURLSession

    This isn't complete, it's missing the bridging header etc. I use this code in a project of my own, where Reqres wasn't able to log requests from a third-party binary-only library. With this change, all those requests are logged. If there's interest in merging this code I could finish / clean it up.

    Note that it uses ObjC to do the swizzling; it is possible to swizzle in Swift but it fails into the problems mentioned in this article:

    https://blog.newrelic.com/engineering/right-way-to-swizzle/

    whether in practice that would be a problem in this case or not I don't know, but when I'm doing slightly dodgy things I prefer to do it the safest way possible.

    stale 
    opened by jogu 4
  • Memory Leaks

    Memory Leaks

    There are a lot of memory leaks while using Reqres.defaultSessionConfiguration() instead of regular URLSessionConfiguration for Alamofire. The app increases its size several times.

    stale 
    opened by georgysolovei 3
  • duplicate http request

    duplicate http request

    using the example target, I noticed that when calling alamofileManager.request in ViewController.swift actually makes 2 requests for the same url, because Reqres.swift also makes a request inside the startLoading method, I caught up this issue using XCode 13's Network instrument.

    opened by murad1981 2
  • Mark cached responses

    Mark cached responses

    It could be very useful to see which requests are returned from cache and which are not. There seems to be no way to do it 100% reliable but I think this implementation is good enough for debug purposes.

    Checklist

    • [x] Added tests (if applicable)
    stale 
    opened by janmisar 2
  • Make extension friendly

    Make extension friendly

    I've been using Reqres in a custom framework. Enable this setting will make it extension Friendly. For example Alamofire is extension friendly https://github.com/Alamofire/Alamofire/pull/273

    opened by dimaosa 2
  • Custom URLSession

    Custom URLSession

    What about custom URLSession? If I use custom URLSession how can I log all requests and responses? As for now, no logging is occurring with custom URLSession.

    let urlSession = URLSession(configuration: URLSessionConfiguration.default)

    I'd like to have something like this:

    urlSession.logger = Reqres.logger

    opened by Yurssoft 2
  • Forgotten pod trunk push?

    Forgotten pod trunk push?

    Event though version 3.1.1 seems like ready-to-use I can't download it from cocoapods main repo, probably due to forgotten pod trunk push. From there I can download only 3.1.0 (https://cocoapods.org/pods/Reqres)

    opened by fvolchyok 1
  • Fix the example app

    Fix the example app

    Checklist

    • [x] Updated CHANGELOG.md.

    Changes:

    • https://requestb.in is no longer available, replaced by https://putsreq.com
    • alamofireManager didn't live long enough and thus requests were cancelled
    • newline before error message
    opened by michalsrutek 0
  • Communicate better the debug purpose of Reqres

    Communicate better the debug purpose of Reqres

    As we internally reconsidered Reqres to be debug tool that should not be used in production, we never made this reconsideration public (because of #33).

    To make this clear we should:

    enhancement 
    opened by olejnjak 0
  • Do not use new session for sending requests

    Do not use new session for sending requests

    When we catching sent requests we should not use new session. This would require proper implementation of URLProtocol and until this issue is resolved we should consider Reqres to be a debug tool that should not be used in production.

    https://github.com/AckeeCZ/Reqres/blob/6a88e6e1f52170e8cf89bf76c6e9549516a8309d/Reqres/Reqres.swift#L65

    bug 
    opened by olejnjak 0
  • Move string formatting out of ReqRes class

    Move string formatting out of ReqRes class

    Because of work on ios logging to ElasticSearch I would like to use ReqRes feature to "listen"on Requests and Responses.

    I would like to separate "output format" and "logger for output format" out of the ReqRes. I know it brings up some level of additional complexity. But if written correctly it wont affect the original simplicity and intentions of use.

    first idea out of the Box is to have Generic Formatter which conforms to logResponse, logRequest/ Error interface... and this formatter has output of T

    Formatters will have Logger which accepts T as input and do whatever it wants with it.

    if you agree i can start working on it and create pull request.

    enhancement stale 
    opened by Dominoo 1
Releases(3.1.1)
Owner
Ackee
Software development enthusiasts from the ❤️ of Europe.
Ackee
Logger - This package is a thin wrapper for `os.Logger`

Logger This package is a thin wrapper for os.Logger. Usage Define os.Logger as an extension of Logger with the property name of the string that the sy

treastrain / Tanaka Ryoga 5 Jul 1, 2022
A network logger for iOS and macOS projects.

OkLog for iOS and macOS OkLog-Swift is a network logger written in Swift highly inspired by simonpercic's original OkLog implementation to be used in

Diego Trevisan Lara 18 Dec 24, 2021
A simple logger for your swift applications.

AHQSLogger A simple logging system. Usage import AHQSLogger Use the following methods for loggging. Logging an information / debug You can log a simp

André Henrique da Silva 0 Dec 29, 2021
Tracker - A simple location logger app written in Swift and MVVM architecture

Tracker - A simple location logger app written in Swift and MVVM architecture

Loay Ashraf 1 Mar 12, 2022
Bugfender SDK for iOS, a remote logger tailor-made for mobile

Bugfender SDK for iOS Bugfender is a cloud service to collect mobile application logs. Developers can control log sending programmatically and manuall

Bugfender 69 Dec 4, 2022
Easy to use and lightweight logger for iOS, macOS, tvOS, watchOS and Linux in Swift.

Lighty Easy to use and lightweight logger for iOS, macOS, tvOS, watchOS and Linux in Swift. Screenshots Requirements Lighty Version Minimum iOS Target

Abdullah Selek 51 Dec 21, 2022
Stock tradings Logger app for iOS

Stock Logger Contributor: Name: Prof. Darren Takaki Author: Name: Ibrahim (Wusiman Yibulayin) Student ID: 0728356 Table of contents Description Gettin

null 2 Jul 28, 2022
A fancy logger yet lightweight, and configurable. 🖨

?? ?? Important: Printer can only print console logs if you're running an app in the Simulator. If you're running in a real device it will not print a

Hemang 66 Dec 7, 2022
LogDog is designed to work out of the box, you can use the pre-configured logger anytime, anywhere

LogDog user-friendly logging apple/swift-log api compatible Usage LogDog is designed to work out of the box, you can use the pre-configured logger any

Luo Xiu 21 Aug 14, 2022
Logger for Xcode

CSwiftLog Usage Log.log("Message text without category") Log.my.log("Message text with custom category") Log.network.log("Message text with network ca

Andrew Firsenko 2 Nov 29, 2021
A custom logger implementation and Task Local helper for swift-log

LGNLog A custom logger implementation and TaskLocal helper for Swift-Log. Why and how This package provides two and a half things (and a small bonus):

17:11 Games 0 Oct 26, 2021
A lightweight Swift logger, uses `print` in development and `NSLog` in production. Support colourful and formatted output.

Loggerithm A lightweight Swift logger, uses print in Debug and NSLog in Production with colourful output. Why In Swift, we usually use print to log in

HongHao Zhang 270 Oct 8, 2022
TraceLog is a highly configurable, flexible, portable, and simple to use debug logging system for Swift and Objective-C applications running on Linux, macOS, iOS, watchOS, and tvOS.

Please star this github repository to stay up to date. TraceLog Introduction TraceLog is a highly configurable, flexible, portable, and simple to use

Tony Stone 52 Oct 28, 2022
A fast & simple, yet powerful & flexible logging framework for Mac and iOS

CocoaLumberjack CocoaLumberjack is a fast & simple, yet powerful & flexible logging framework for macOS, iOS, tvOS and watchOS. How to get started Fir

null 12.9k Jan 9, 2023
A Simple iOS Testing Framework

LumberMill Stupidly Simple Logging for iOS. LumberMill is a simple logging library for iOS 10 and Swift 3.0. It allows users to Log files with 5 diffe

UBC Launch Pad 2 Nov 2, 2017
A simple iOS app to simulate a laser level using built-in camera and gyroscope.

Laser Level A simple iOS app to simulate a laser level using built-in camera and gyroscope. Demo https://youtu.be/aB03EtQ5zsU Usage Download Open .xco

Pavel Trusov 2 Oct 30, 2022
Simple logging for simples needs.

Simple logging for simples needs.

native.dev.br 0 May 30, 2022
CleanroomLogger provides an extensible Swift-based logging API that is simple, lightweight and performant

CleanroomLogger CleanroomLogger provides an extensible Swift-based logging API that is simple, lightweight and performant. The API provided by Cleanro

null 1.3k Dec 8, 2022
A simple Swift package for measuring and reporting the time taken for operations

Duration A simple Swift package for measuring and reporting the time taken for operations. It is derived from a version for Playgrounds that I blogged

Swift Studies 325 Nov 6, 2022