Skip to content

Commit

Permalink
Merge branch 'master' of github.com:sunilsharma08/NetworkLogger
Browse files Browse the repository at this point in the history
# Conflicts:
#	XNLogger/UI/Resources/Media.xcassets/maximise.imageset/Contents.json
#	XNLogger/UI/Resources/Media.xcassets/maximise.imageset/Maximise.pdf
  • Loading branch information
sunilsharma08 committed Sep 12, 2020
2 parents 5e4fba6 + 24434e0 commit 097d1d4
Show file tree
Hide file tree
Showing 15 changed files with 214 additions and 12 deletions.
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@
[![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-brightgreen.svg)](https://github.com/sunilsharma08/XNLogger)
[![License](https://img.shields.io/github/license/sunilsharma08/XNLogger?color=blue)](https://raw.githubusercontent.com/sunilsharma08/XNLogger/master/LICENSE)
[![Pod platforms](https://img.shields.io/cocoapods/p/XNLogger)](https://github.com/sunilsharma08/XNLogger)

</br>
<br/>
<br/>
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.
</br>

<br/>

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
Expand Down Expand Up @@ -88,7 +90,7 @@ For example your app target name is AwesomeApp, then import statement will be
For more details on how to bridge swift code in Objectiv-C file check this apple doc - [Importing Swift into Objective-C](https://developer.apple.com/documentation/swift/imported_c_and_objective-c_apis/importing_swift_into_objective-c)

# Usage
Logging starts automatically after integration in project. Shake device or simulator to see logs in app.
**Logging starts automatically after integration in project. Shake device or simulator to see logs in app.**

### Start Logging manually
```swift
Expand Down
2 changes: 1 addition & 1 deletion XNLogger.podspec
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Pod::Spec.new do |s|

s.name = "XNLogger"
s.version = "2.0.0"
s.version = "2.1.1"
s.summary = "Network Logger - Framework to log network traffics"
s.description = <<-DESC
XNLogger is simple and extensible network traffic logger. It makes easy to log network request and response on file, Xcode console or send log to servers. XNLogger provides user friendly UI for debugging and testing purpose.
Expand Down
16 changes: 14 additions & 2 deletions XNLogger.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
6547BEF42437CEF5001F7B4D /* XNUIResponseFullScreenVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6547BEF32437CEF5001F7B4D /* XNUIResponseFullScreenVC.swift */; };
6547BEF72437D023001F7B4D /* XNUIResponseFullScreenVC.xib in Resources */ = {isa = PBXBuildFile; fileRef = 6547BEF62437D023001F7B4D /* XNUIResponseFullScreenVC.xib */; };
6558E4C724CEFD590005E65B /* WebKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6558E4C624CEFD590005E65B /* WebKit.framework */; };
65639D71250478300006A858 /* XNUICustomPathUIActivity.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65639D70250478300006A858 /* XNUICustomPathUIActivity.swift */; };
65B90C3824A0F07E0007FAF0 /* XNUIWindow.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65B90C3724A0F07E0007FAF0 /* XNUIWindow.swift */; };
65C1D51524B7AC9B00F92862 /* XNUIOptionItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65C1D51424B7AC9B00F92862 /* XNUIOptionItem.swift */; };
65C1D51724B7AD1900F92862 /* XNUIPopOverViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65C1D51624B7AD1900F92862 /* XNUIPopOverViewController.swift */; };
Expand Down Expand Up @@ -141,6 +142,7 @@
6547BEF62437D023001F7B4D /* XNUIResponseFullScreenVC.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = XNUIResponseFullScreenVC.xib; sourceTree = "<group>"; };
6558E4C624CEFD590005E65B /* WebKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = WebKit.framework; path = Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk/System/Library/Frameworks/WebKit.framework; sourceTree = DEVELOPER_DIR; };
6558E4C824CF0A800005E65B /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = System/Library/Frameworks/UIKit.framework; sourceTree = SDKROOT; };
65639D70250478300006A858 /* XNUICustomPathUIActivity.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = XNUICustomPathUIActivity.swift; sourceTree = "<group>"; };
65B90C3724A0F07E0007FAF0 /* XNUIWindow.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = XNUIWindow.swift; sourceTree = "<group>"; };
65C1D51424B7AC9B00F92862 /* XNUIOptionItem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = XNUIOptionItem.swift; sourceTree = "<group>"; };
65C1D51624B7AD1900F92862 /* XNUIPopOverViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = XNUIPopOverViewController.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -232,6 +234,7 @@
106BB6922304A882007968A8 /* UI */ = {
isa = PBXGroup;
children = (
65639D6F250477490006A858 /* Utils */,
653A1B0324C85A5200FE7B04 /* SettingsScreen */,
6547BEF52437CF08001F7B4D /* ResponseFullScreen */,
101750F92337EA1000CDAFF3 /* Resources */,
Expand Down Expand Up @@ -374,6 +377,14 @@
path = ResponseFullScreen;
sourceTree = "<group>";
};
65639D6F250477490006A858 /* Utils */ = {
isa = PBXGroup;
children = (
65639D70250478300006A858 /* XNUICustomPathUIActivity.swift */,
);
path = Utils;
sourceTree = "<group>";
};
E6D89CC31E4425ADB5FF1363 /* Pods */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -584,6 +595,7 @@
108576A821FDD662008ABD2B /* XNInterceptor.swift in Sources */,
101CA0B3230F23300063B0CF /* XNUIBaseViewController.swift in Sources */,
10D094C422E4EE0A0020D9DB /* XNLoader.m in Sources */,
65639D71250478300006A858 /* XNUICustomPathUIActivity.swift in Sources */,
1047D7FA22CA7BAF000A7B6C /* XNAppUtils.swift in Sources */,
108576AF21FDD662008ABD2B /* XNLogComposer.swift in Sources */,
10FC10EB231501D900F347BF /* XNUILogDetailVC.swift in Sources */,
Expand Down Expand Up @@ -770,7 +782,7 @@
"@executable_path/Frameworks",
"@loader_path/Frameworks",
);
MARKETING_VERSION = 1.1.1;
MARKETING_VERSION = 2.1.1;
PRODUCT_BUNDLE_IDENTIFIER = com.sunilsharma.XNLogger;
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
SKIP_INSTALL = NO;
Expand Down Expand Up @@ -798,7 +810,7 @@
"@executable_path/Frameworks",
"@loader_path/Frameworks",
);
MARKETING_VERSION = 1.1.1;
MARKETING_VERSION = 2.1.1;
PRODUCT_BUNDLE_IDENTIFIER = com.sunilsharma.XNLogger;
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
SKIP_INSTALL = NO;
Expand Down
4 changes: 3 additions & 1 deletion XNLogger/UI/LogDetailScreen/XNUILogDetailVC.swift
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,9 @@ class XNUILogDetailVC: XNUIBaseViewController {
DispatchQueue.main.async {
self.helper.hideActivityIndicator(from: self.view)

let shareVC = UIActivityViewController(activityItems: [shareDetails], applicationActivities: nil)
let saveToDesktopActivities = [XNUISaveToDesktopActivity(), XNUISaveToPathActivity()]

let shareVC = UIActivityViewController(activityItems: [shareDetails], applicationActivities: saveToDesktopActivities)
if (UIDevice.current.userInterfaceIdiom == UIUserInterfaceIdiom.pad) {

guard let moreOptionButton = self.moreOptionBtn else { return }
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"images" : [
{
"filename" : "maximise.pdf",
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
},
"properties" : {
"preserves-vector-representation" : true,
"template-rendering-intent" : "template"
}
}
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"images" : [
{
"filename" : "saveToDesktop.pdf",
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
},
"properties" : {
"preserves-vector-representation" : true,
"template-rendering-intent" : "template"
}
}
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"images" : [
{
"filename" : "saveToLocation.pdf",
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
},
"properties" : {
"preserves-vector-representation" : true,
"template-rendering-intent" : "template"
}
}
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,9 @@ class XNUIResponseFullScreenVC: XNUIBaseViewController {
}
DispatchQueue.main.async {
self.helper.hideActivityIndicator(from: self.view)
let shareVC = UIActivityViewController(activityItems: [shareItem], applicationActivities: nil)
let saveToDesktopActivities = [XNUISaveToDesktopActivity(), XNUISaveToPathActivity()]

let shareVC = UIActivityViewController(activityItems: [shareItem], applicationActivities: saveToDesktopActivities)

if (UIDevice.current.userInterfaceIdiom == UIUserInterfaceIdiom.pad) {

Expand Down
2 changes: 1 addition & 1 deletion XNLogger/UI/UIModels/XNUILogDetail.swift
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ class XNUIShareData: NSObject, UIActivityItemSource {

var logDetails: [XNUILogDetail] = []
var tempFileURL: URL?
var tempFileName: String = "XNLogger-log-\(XNUIHelper().randomString(length: 5)).txt"
var tempFileName: String = String(format: XNUIConstants.txtLogFileName, XNUIHelper().randomString(length: 5))
var processedStr: String = ""

init(logDetails: [XNUILogDetail]) {
Expand Down
137 changes: 137 additions & 0 deletions XNLogger/UI/Utils/XNUICustomPathUIActivity.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
//
// XNUICustomPathUIActivity.swift
// XNLogger
//
// Created by Sunil Sharma on 06/09/20.
// Copyright © 2020 Sunil Sharma. All rights reserved.
//

import Foundation

extension UIActivity.ActivityType {
static let saveToPath = UIActivity.ActivityType("com.xnlogger.saveToPath")
static let saveToDeskTop = UIActivity.ActivityType(rawValue: "com.xnlogger.saveToDesktop")
}

class XNUISimulatorActivity: UIActivity {

var shareData: [Any] = []
var destinationPath: String = ""

override class var activityCategory: UIActivity.Category {
return .action
}

override func prepare(withActivityItems activityItems: [Any]) {
shareData = activityItems
}

override func canPerform(withActivityItems activityItems: [Any]) -> Bool {
#if targetEnvironment(simulator)
return true
#else
return false
#endif
}

override func perform() {

let toBasePathUrl = URL(fileURLWithPath: destinationPath)
var actionStatus: Bool = true
let utils = XNUIHelper()

for item in shareData {
do {
if let shareUrl = item as? URL {
var toPathUrl = toBasePathUrl
toPathUrl.appendPathComponent(shareUrl.lastPathComponent)
if FileManager.default.fileExists(atPath: toPathUrl.path) {
let fileName = "\(toPathUrl.deletingPathExtension().lastPathComponent)-\(utils.randomString(length: 5))"
let fileExtension = toPathUrl.pathExtension
toPathUrl.deleteLastPathComponent()
toPathUrl = toPathUrl.appendingPathComponent("\(fileName).\(fileExtension)")
}
try FileManager.default.copyItem(at: shareUrl, to: toPathUrl)

} else if let shareStr = item as? String {

var toPathUrl = toBasePathUrl
toPathUrl.appendPathComponent(String(format: XNUIConstants.txtLogFileName, utils.randomString(length: 5)))
try shareStr.write(to: toPathUrl, atomically: true, encoding: String.Encoding.utf8)
}
} catch {
actionStatus = false
}
}
self.activityDidFinish(actionStatus)
}
}

class XNUISaveToPathActivity: XNUISimulatorActivity {

override var activityType: UIActivity.ActivityType? {
return .saveToPath
}

override var activityTitle: String? {
return "Save to Location"
}

override var activityImage: UIImage? {
return UIImage(named: "saveToLocation", in: Bundle.current(), compatibleWith: nil)
}

override var activityViewController: UIViewController? {

let alertVC = UIAlertController(title: "Save to location", message: nil, preferredStyle: .alert)
alertVC.addTextField { (textField) in
textField.placeholder = "Enter complete location path"
}

let actionSave = UIAlertAction(title: "Save", style: .default) {[weak self] (action) in
guard let self = self else { return }

if let pathTextField = alertVC.textFields?.first,
let toPathStr = pathTextField.text, toPathStr.isEmpty == false {
self.destinationPath = toPathStr
self.perform()
}
}

let cancel = UIAlertAction(title: "Cancel", style: .cancel) { (action) in
self.activityDidFinish(false)
}

alertVC.addAction(cancel)
alertVC.addAction(actionSave)

return alertVC
}

}

class XNUISaveToDesktopActivity: XNUISimulatorActivity {

override init() {
super.init()
let envInfo = ProcessInfo.processInfo.environment
if var homePath = envInfo["SIMULATOR_HOST_HOME"] {
homePath += "/Desktop"
destinationPath = homePath
} else {
destinationPath = ""
}
}

override var activityType: UIActivity.ActivityType? {
return .saveToDeskTop
}

override var activityTitle: String? {
return "Save to Desktop"
}

override var activityImage: UIImage? {
return UIImage(named: "saveToDesktop", in: Bundle.current(), compatibleWith: nil)
}
}
2 changes: 0 additions & 2 deletions XNLogger/UI/XNUIExtensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,4 @@ extension CGRect: Comparable {
public static func < (lhs: CGRect, rhs: CGRect) -> Bool {
return lhs.width < rhs.width && lhs.width < rhs.width
}


}
1 change: 1 addition & 0 deletions XNLogger/UI/XNUIHelper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ final class XNUIConstants {
static let activityIndicatorTag: Int = 10263
static let logIdKey: String = "logIdentifier"
static let isResponseLogUpdate: String = "isResponseLogUpdate"
static let txtLogFileName: String = "XNLogger-log-%@.txt"
}

class XNUIHelper {
Expand Down

0 comments on commit 097d1d4

Please sign in to comment.