Coder Social home page Coder Social logo

sunilsharma08 / xnlogger Goto Github PK

View Code? Open in Web Editor NEW
24.0 2.0 7.0 3.57 MB

Network Logger - Framework to log network traffics

License: MIT License

Ruby 0.71% Swift 98.25% Objective-C 0.30% C 0.04% Shell 0.70%
xnlogger networklogger logger network ios-logger swift-logger network-monitoring network-traffics

xnlogger's Introduction

Swift version Pod version Carthage compatible License Pod platforms

XNLogger is network logging framework, which can be easily extended and modified as per requirements. It can be formatted to log just url or complete network traffic details. It provides in-app logger UI for debugging and testing purpose. Logs can be written on files, print on Xcode console, send to network or use inbuild logger UI. Network logger UI appears in app with shake gesture on device and simulators.


Network loggers can generate huge data specially when binary data(like image, video, etc.) logging is enabled, this can increase memory usage and may result in app crash. To avoid such situation XNLogger is designed to use memory efficiently, it write logs on disk and only on requirement loads in memory.

Features

  • Logs all network traffics.
  • Network logs can be viewed In-App by pressing CTRL + X or via shake gesture.
  • Mini view mode, makes debugging easier. Mini view can be resized and moved on screen.
  • Share network logs via email, airdrop or copy to clipboard.
  • Save logs file to desktop or any other location when running app on Simulator.
  • Memory efficient, logs are written to disk to reduce memory pressure.
  • Filters for scheme(http, https), host(www.example.com), contains(any string in url).
  • Mutiple log writer/handlers support(e.g. console, file, etc.), more than one handlers can be used simultaneously.
  • Support for custom log handlers.
  • Separate filters can be added for each log handlers.
  • Skip completely XNLogger or skip some url for a specific log handelr.
  • Dynamically filters and log handlers can be added or removed.
  • Log formatter to log desired data only.
  • Swift & Objective-C compatibility.
  • Works with external libraries like Alamofire & AFNetworking.
  • Supports iPhone and iPad.

Screenshots

Network Log list Request details Response details
Log lists Request details Response details
Share Multimedia preview Mini view mode(PIP)
Share logs Multimedia preview Mini view mode

Requirements

iOS 12.0 or later

Installation

Cocoapods

pod 'XNLogger'

To integrate with project only for debug configuration

pod 'XNLogger', :configurations => ['Debug']

Carthage

github "https://github.com/sunilsharma08/XNLogger"

Manually

Drag the folder "XNLogger" with the source files into your project.

  • Remove file called "Info.plist" inside folder "XNLogger", you might get error due to this.
  • Go to file "XNLoader.m" and replace import statement from "XNLogger/XNLogger-Swift.h" to <Your-app-target-name>-Swift.h. For example your app target name is AwesomeApp, then import statement will be
#import "AwesomeApp-Swift.h"

For more details on how to bridge swift code in Objectiv-C file check this apple doc - Importing Swift into Objective-C

Usage

Logging starts automatically after integration in project. Press CTRL + X or shake device/simulator(Device -> Shake) to see logs in app.

Start Logging manually

XNLogger.shared.startLogging()

Stop Logging

XNLogger.shared.stopLogging()

To use logger only for debug configuration wrap logger code in preprocessor macros #if DEBUG as

#if DEBUG
    XNLogger.shared.startLogging()
#endif

Show XNLogger UI

XNUIManager.shared.presentUI()

Hide XNLogger UI

XNUIManager.shared.dismissUI()

Clear logs

XNUIManager.shared.clearLogs()

Add predefined log handlers

Console handler

let consoleLogHandler = XNConsoleLogHandler.create()
XNLogger.shared.addLogHandlers([consoleLogHandler])

File handler

let fileLogHandler = XNFileLogHandler.create() //Default file name 'XNNetworkLog'
// File log handler can be created with filename
let fileLogHandler = XNFileLogHandler.create(fileName: "AppNetworkLogs")

XNLogger.shared.addLogHandlers([fileLogHandler])

Remove log handlers

XNLogger.shared.removeHandlers([consoleLogHandler])

Filters

Filters can be applied to loggers and handlers. Filters added to loggers will be applicable to all handlers and also requests does not pass through XNLogger whereas filters added to handlers will be recorded but will be logged to only applicable handlers. Filters added to one handler are not applicable on other handlers. Addings filters to logger is useful when it is required to skip all handlers or wanted to record/skip some specific urls.

Add filters to logger(universal filter)

let httpScheme = XNSchemeFilter(scheme: "https")
XNLogger.shared.addFilters([httpScheme])

Remove filters from logger(universal filter)

XNLogger.shared.removeFilters([httpScheme])

Add filters to handler

let host = XNHostFilter(host: "www.example.com")
consoleHandler.addFilters([host])

Remove filters from handler

consoleHandler.removeFilters([host])

Any filters can be inverted, so lets suppose all http scheme url should not appear in log then just update filter property invert to true as:

let httpScheme = XNSchemeFilter(scheme: "https")
httpScheme.invert = true

Formatters

By default logger logs all informations except binary data. These setting can be adjusted as per requirement. Formatter allows to control what fields to log and what to skip. Formatter class XNLogFormatter has following properties:

public var showRequest: Bool = true // Hide or show requests log.
public var showResponse: Bool = true // Hide or show response log.
public var showReqstWithResp: Bool = false // Show request with response, useful when `showRequest` is disabled.
public var showCurlWithReqst: Bool = true // Show curl request with request log.
public var showCurlWithResp: Bool = true // Show curl request when url request is displayed with response.
public var prettyPrintJSON: Bool = true // Log pretty printed json data .
public var logUnreadableRespBody: Bool = false // Show binary data like image, video, etc in response.
public var logUnreadableReqstBody: Bool = false // Show binary data like image, video, etc in request body.
public var showReqstMetaInfo: [XNRequestMetaInfo] = XNRequestMetaInfo.allCases // Details to be displayed in request log portion.
public var showRespMetaInfo: [XNResponseMetaInfo] = XNResponseMetaInfo.allCases // Details to be displayed in response log portion.
public var showReqstMetaInfoWithResp: [XNRequestMetaInfo] = XNRequestMetaInfo.allCases // Details to display for request when display as response portion.

Limitations

  1. Does not log background url session tasks.
  2. WKWebView urls will be not logged.

Trying to log background tasks and WKWebView urls without using any private API. These limitation may be removed in next releases.

Contribution

Feel free to raise PR for any bug fixes, features or enchancements. When you are done with changes raise PR to develop branch.

Another way to contribute to the project is to send a detailed issue when you encounter a problem. In bug detail please provide steps to reproduce and some other details like Swift version, url(if possible), URLSession configuration, etc.

License

XNLogger is available under the MIT license.

xnlogger's People

Contributors

sunilsharma08 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

xnlogger's Issues

How to not use this library when in production mode?

Hi there,

First of all, great work. Really impressive.

The issue I am currently having is that I don't want to show the logging UI when in Production mode. How to achieve that?
I used stopLogging function but it only stop the library from logging purpose but it still appears the Logging UI.
I do not want to remove this library and install again and again when switching between production mode and development mode. Thank you.

Best Regards

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.