Skip to content

Commit

Permalink
U 增加输出方式和说明
Browse files Browse the repository at this point in the history
U 增加输出方式和说明
  • Loading branch information
DamonHu committed Dec 9, 2019
1 parent aaf2fbc commit 3821279
Show file tree
Hide file tree
Showing 8 changed files with 164 additions and 159 deletions.
2 changes: 1 addition & 1 deletion HDWindowLoggerSwift.podspec
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Pod::Spec.new do |s|
s.name = 'HDWindowLoggerSwift'
s.swift_version = '5.0'
s.version = '1.1.1'
s.version = '1.2.0'
s.license= { :type => "MIT", :file => "LICENSE" }
s.summary = 'The iOS side displays the output log log on the screen, and can generate log file sharing, which is convenient for debugging information'
s.homepage = 'https://github.com/DamonHu/HDWindowLoggerSwift'
Expand Down
6 changes: 2 additions & 4 deletions HDWindowLoggerSwift.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
/* Begin PBXBuildFile section */
E4885A7122C60E5100B9BC8B /* LogContent.swift in Sources */ = {isa = PBXBuildFile; fileRef = E4885A7022C60E5100B9BC8B /* LogContent.swift */; };
E48AABF722C05EF600CC5F1C /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = E48AABF622C05EF600CC5F1C /* AppDelegate.swift */; };
E48AABF922C05EF600CC5F1C /* SceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = E48AABF822C05EF600CC5F1C /* SceneDelegate.swift */; };
E48AABFB22C05EF600CC5F1C /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = E48AABFA22C05EF600CC5F1C /* ViewController.swift */; };
E48AABFE22C05EF600CC5F1C /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = E48AABFC22C05EF600CC5F1C /* Main.storyboard */; };
E48AAC0022C05EF700CC5F1C /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = E48AABFF22C05EF700CC5F1C /* Assets.xcassets */; };
Expand Down Expand Up @@ -42,7 +41,6 @@
E4885A7022C60E5100B9BC8B /* LogContent.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LogContent.swift; sourceTree = "<group>"; };
E48AABF322C05EF600CC5F1C /* HDWindowLoggerSwift.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = HDWindowLoggerSwift.app; sourceTree = BUILT_PRODUCTS_DIR; };
E48AABF622C05EF600CC5F1C /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
E48AABF822C05EF600CC5F1C /* SceneDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SceneDelegate.swift; sourceTree = "<group>"; };
E48AABFA22C05EF600CC5F1C /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = "<group>"; };
E48AABFD22C05EF600CC5F1C /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = "<group>"; };
E48AABFF22C05EF700CC5F1C /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
Expand Down Expand Up @@ -112,7 +110,6 @@
children = (
E48AAC2622C05F0B00CC5F1C /* HDWindowLoggerSwift */,
E48AABF622C05EF600CC5F1C /* AppDelegate.swift */,
E48AABF822C05EF600CC5F1C /* SceneDelegate.swift */,
E48AABFA22C05EF600CC5F1C /* ViewController.swift */,
E48AABFC22C05EF600CC5F1C /* Main.storyboard */,
E48AABFF22C05EF700CC5F1C /* Assets.xcassets */,
Expand Down Expand Up @@ -289,7 +286,6 @@
E48AABFB22C05EF600CC5F1C /* ViewController.swift in Sources */,
E48AAC2822C05F5300CC5F1C /* HDWindowLoggerSwift.swift in Sources */,
E48AABF722C05EF600CC5F1C /* AppDelegate.swift in Sources */,
E48AABF922C05EF600CC5F1C /* SceneDelegate.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -477,6 +473,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_STYLE = Automatic;
INFOPLIST_FILE = HDWindowLoggerSwift/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 10.0;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
Expand All @@ -494,6 +491,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_STYLE = Automatic;
INFOPLIST_FILE = HDWindowLoggerSwift/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 10.0;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
Expand Down
23 changes: 5 additions & 18 deletions HDWindowLoggerSwift/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,31 +11,18 @@ import UIKit
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {


var window: UIWindow?

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.

let vc = ViewController()
self.window?.rootViewController = vc
self.window?.makeKeyAndVisible()
return true
}

func applicationWillTerminate(_ application: UIApplication) {
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

// MARK: UISceneSession Lifecycle

func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration {
// Called when a new scene session is being created.
// Use this method to select a configuration to create the new scene with.
return UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role)
}

func application(_ application: UIApplication, didDiscardSceneSessions sceneSessions: Set<UISceneSession>) {
// Called when the user discards a scene session.
// If any sessions were discarded while the application was not running, this will be called shortly after application:didFinishLaunchingWithOptions.
// Use this method to release any resources that were specific to the discarded scenes, as they will not return.
}


}

39 changes: 30 additions & 9 deletions HDWindowLoggerSwift/HDWindowLoggerSwift/HDWindowLoggerSwift.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@
import UIKit

///快速输出log
public func HDNormalLog(_ log:LogContent) -> Void {
HDWindowLoggerSwift.printLog(log: log.logStringValue, logType: HDLogType.kHDLogTypeNormal)
public func HDNormalLog(_ log:Any, file:String = #file, funcName:String = #function, lineNum:Int = #line) -> Void {
HDWindowLoggerSwift.printLog(log: log, logType: HDLogType.kHDLogTypeNormal, file:file, funcName:funcName, lineNum:lineNum)
}

public func HDWarnLog(_ log:LogContent) -> Void {
HDWindowLoggerSwift.printLog(log: log.logStringValue, logType: HDLogType.kHDLogTypeWarn)
public func HDWarnLog(_ log:Any, file:String = #file, funcName:String = #function, lineNum:Int = #line) -> Void {
HDWindowLoggerSwift.printLog(log: log, logType: HDLogType.kHDLogTypeWarn, file:file, funcName:funcName, lineNum:lineNum)
}

public func HDErrorLog(_ log:LogContent) -> Void {
HDWindowLoggerSwift.printLog(log: log.logStringValue, logType: HDLogType.kHDLogTypeError)
public func HDErrorLog(_ log:Any, file:String = #file, funcName:String = #function, lineNum:Int = #line) -> Void {
HDWindowLoggerSwift.printLog(log: log, logType: HDLogType.kHDLogTypeError, file:file, funcName:funcName, lineNum:lineNum)
}

///log的级别,对应不同的颜色
Expand Down Expand Up @@ -47,6 +47,9 @@ public class HDWindowLoggerItem {

///log的输出
public class HDWindowLoggerSwift: UIWindow, UITableViewDataSource, UITableViewDelegate, UISearchBarDelegate {
public static var mCompleteLogOut = false //是否完整输出日志文件名等调试内容
public static var mDebugAreaLogOut = true //是否在xcode底部的调试栏同步输出内容

public static let defaultWindowLogger = HDWindowLoggerSwift(frame: CGRect(x: 0, y: UIApplication.shared.statusBarFrame.size.height, width: UIScreen.main.bounds.size.width, height: 300))
public private(set) var mLogDataArray = [HDWindowLoggerItem]()
private var mFilterLogDataArray = [HDWindowLoggerItem]()
Expand Down Expand Up @@ -322,7 +325,7 @@ public class HDWindowLoggerSwift: UIWindow, UITableViewDataSource, UITableViewDe

private func p_getCurrentVC() -> UIViewController {
var window = UIApplication.shared.keyWindow
if window?.windowLevel != UIWindow.Level.normal {
if window == nil || window?.windowLevel != UIWindow.Level.normal {
let windowArray = UIApplication.shared.windows
for tmpWin in windowArray {
if tmpWin.windowLevel == UIWindow.Level.normal {
Expand Down Expand Up @@ -358,7 +361,7 @@ public class HDWindowLoggerSwift: UIWindow, UITableViewDataSource, UITableViewDe
/// 根据日志的输出类型去输出相应的日志,不同日志类型颜色不一样
/// - Parameter log: 日志内容
/// - Parameter logType: 日志类型
public class func printLog(log:LogContent, logType:HDLogType) -> Void {
public class func printLog(log:Any, logType:HDLogType, file:String = #file, funcName:String = #function, lineNum:Int = #line) -> Void {
if self.defaultWindowLogger.mLogDataArray.isEmpty {
let loggerItem = HDWindowLoggerItem()
loggerItem.mLogItemType = HDLogType.kHDLogTypeWarn
Expand All @@ -369,7 +372,25 @@ public class HDWindowLoggerSwift: UIWindow, UITableViewDataSource, UITableViewDe
let loggerItem = HDWindowLoggerItem()
loggerItem.mLogItemType = logType
loggerItem.mCreateDate = Date()
loggerItem.mLogContent = log.logStringValue
if self.mCompleteLogOut {
let fileName = (file as NSString).lastPathComponent;
if log is LogContent {
loggerItem.mLogContent = "[File:\(fileName)]:[Line:\(lineNum):[Function:\(funcName)]]-Log:\n" + (log as! LogContent).logStringValue
} else {
loggerItem.mLogContent = "[File:\(fileName)]:[Line:\(lineNum):[Function:\(funcName)]]-Log:\n\(log)"
}
} else {
if log is LogContent {
loggerItem.mLogContent = (log as! LogContent).logStringValue
} else {
loggerItem.mLogContent = "\(log)"
}
}
if self.mDebugAreaLogOut {
if let content = loggerItem.mLogContent {
print(content)
}
}
self.defaultWindowLogger.mLogDataArray.append(loggerItem)
if self.defaultWindowLogger.mMaxLogCount > 0 && self.defaultWindowLogger.mMaxLogCount > self.defaultWindowLogger.mMaxLogCount {
self.defaultWindowLogger.mLogDataArray.removeFirst()
Expand Down
21 changes: 0 additions & 21 deletions HDWindowLoggerSwift/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -20,27 +20,6 @@
<string>1</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>UIApplicationSceneManifest</key>
<dict>
<key>UIApplicationSupportsMultipleScenes</key>
<false/>
<key>UISceneConfigurations</key>
<dict>
<key>UIWindowSceneSessionRoleApplication</key>
<array>
<dict>
<key>UILaunchStoryboardName</key>
<string>LaunchScreen</string>
<key>UISceneConfigurationName</key>
<string>Default Configuration</string>
<key>UISceneDelegateClassName</key>
<string>$(PRODUCT_MODULE_NAME).SceneDelegate</string>
<key>UISceneStoryboardFile</key>
<string>Main</string>
</dict>
</array>
</dict>
</dict>
<key>UILaunchStoryboardName</key>
<string>LaunchScreen</string>
<key>UIMainStoryboardFile</key>
Expand Down
53 changes: 0 additions & 53 deletions HDWindowLoggerSwift/SceneDelegate.swift

This file was deleted.

2 changes: 2 additions & 0 deletions HDWindowLoggerSwift/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,15 @@ class ViewController: UIViewController {

override func viewDidLoad() {
super.viewDidLoad()
self.view.backgroundColor = UIColor.white
self.view.addSubview(self.clickButton)
self.clickButton.addTarget(self, action: #selector(onClickButton), for: UIControl.Event.touchUpInside)
}

override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
HDWindowLoggerSwift.show()
HDWindowLoggerSwift.mCompleteLogOut = true
HDNormalLog("收到就好丰盛的金凤凰就水电费交mmm换机时间开始的回复是砍价的回复四大皆空回复速度快解放后搜的飞机开会接口是点击开发还是手机打开混分巨兽地方收到就好丰盛的金凤凰就水电费交换机时间开始的回复是砍价的回复四大皆空回复速度快解放后搜的飞机开会接口是点击开发还是手机打开混分巨兽地方收到就好丰盛的金凤凰就水电费交换机时间开始的回复是砍价的回复四大皆空回复速度快解放后搜的飞机开会接口是点击开发还是手机打开混分巨兽地方")
}

Expand Down
Loading

0 comments on commit 3821279

Please sign in to comment.