From 8f0aea8269bb14bfc8dccd2f535ccc0e983af8b0 Mon Sep 17 00:00:00 2001 From: Konrad Zdunczyk Date: Tue, 22 Dec 2015 13:55:12 +0100 Subject: [PATCH 1/3] Add Mac OS X support Remove '()' from QL1 online output --- QorumLogs.swift | 36 +++++++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/QorumLogs.swift b/QorumLogs.swift index 69350ec..05733cd 100755 --- a/QorumLogs.swift +++ b/QorumLogs.swift @@ -9,9 +9,13 @@ import Foundation #if os(OSX) - import Cocoa //TODO: Check if this works on OSX apps, maybe use NSColor? + import Cocoa + + public typealias QLColor = NSColor #elseif os(iOS) import UIKit + + public typealias QLColor = UIColor #endif public struct QorumLogs { @@ -20,13 +24,13 @@ public struct QorumLogs { /// 1 to 4 public static var minimumLogLevelShown = 1 /// Change the array element with another UIColor. 0 is info gray, 5 is purple, rest are log levels - public static var colorsForLogLevels: [UIColor] = [ - UIColor(redC: 120, greenC: 120, blueC: 120), //0 - UIColor(redC: 0, greenC: 180, blueC: 180), //1 - UIColor(redC: 0, greenC: 150, blueC: 0), //2 - UIColor(redC: 255, greenC: 190, blueC: 0), //3 - UIColor(redC: 255, greenC: 0, blueC: 0), //4 - UIColor(redC: 160, greenC: 32, blueC: 240)] //5 + public static var colorsForLogLevels: [QLColor] = [ + QLColor(redC: 120, greenC: 120, blueC: 120), //0 + QLColor(redC: 0, greenC: 180, blueC: 180), //1 + QLColor(redC: 0, greenC: 150, blueC: 0), //2 + QLColor(redC: 255, greenC: 190, blueC: 0), //3 + QLColor(redC: 255, greenC: 0, blueC: 0), //4 + QLColor(redC: 160, greenC: 32, blueC: 240)] //5 /// Enable console link with KZLinkedConsole plugin public static var KZLinkedConsoleSupportEnabled = false private static var showFile: String? @@ -149,7 +153,18 @@ public struct QorumOnlineLogs { request.HTTPMethod = "POST" request.setValue("application/x-www-form-urlencoded; charset=utf-8", forHTTPHeaderField: "Content-Type") request.HTTPBody = postData.dataUsingEncoding(NSUTF8StringEncoding) + +#if os(OSX) + if kCFCoreFoundationVersionNumber > kCFCoreFoundationVersionNumber10_10 { + let session = NSURLSession.sharedSession() + let task = session.dataTaskWithRequest(request) + task.resume() + } else { + NSURLConnection(request: request, delegate: nil)?.start() + } +#elseif os(iOS) NSURLConnection(request: request, delegate: nil)?.start() +#endif let printText = "OnlineLogs: \(extraInformation.description) - \(versionLevel) - \(classInformation) - \(text)" print(" \(ColorLog.colorizeString(printText, colorId: 5))\n", terminator: "") @@ -172,7 +187,6 @@ public struct QorumOnlineLogs { return false } } - } ///Detailed logs only used while debugging @@ -190,7 +204,7 @@ public func QL1(debug: T, _ file: String = __FILE__, _ function: String = __F } printLog(informationPart, text: debug, level: level) } else if QorumOnlineLogs.shouldSendLine(level: level, fileName: filename) { - let informationPart = "()\(filename).\(function)[\(line)]" + let informationPart = "\(filename).\(function)[\(line)]" QorumOnlineLogs.sendError(classInformation: informationPart, textObject: debug, level: levelText) } } @@ -316,7 +330,7 @@ private extension String { } } -private extension UIColor { +private extension QLColor { convenience init(redC: CGFloat, greenC: CGFloat, blueC: CGFloat) { self.init(red: redC / 255.0, green: greenC / 255.0, blue: blueC / 255.0, alpha: 1) } From 1f082f87d3945e99d5a148de3359d8365e5700f3 Mon Sep 17 00:00:00 2001 From: Konrad Zdunczyk Date: Tue, 22 Dec 2015 14:09:59 +0100 Subject: [PATCH 2/3] Fix bug which cause online log was possible only when QorumLogs.enabled = false --- QorumLogs.swift | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/QorumLogs.swift b/QorumLogs.swift index 05733cd..9717e0b 100755 --- a/QorumLogs.swift +++ b/QorumLogs.swift @@ -203,7 +203,9 @@ public func QL1(debug: T, _ file: String = __FILE__, _ function: String = __F informationPart = "\(filename).\(function)[\(line)]:" } printLog(informationPart, text: debug, level: level) - } else if QorumOnlineLogs.shouldSendLine(level: level, fileName: filename) { + } + + if QorumOnlineLogs.shouldSendLine(level: level, fileName: filename) { let informationPart = "\(filename).\(function)[\(line)]" QorumOnlineLogs.sendError(classInformation: informationPart, textObject: debug, level: levelText) } @@ -223,7 +225,9 @@ public func QL2(info: T, _ file: String = __FILE__, _ function: String = __FU informationPart = "\(filename).\(function)[\(line)]:" } printLog(informationPart, text: info, level: level) - } else if QorumOnlineLogs.shouldSendLine(level: level, fileName: filename) { + } + + if QorumOnlineLogs.shouldSendLine(level: level, fileName: filename) { let informationPart = "\(filename).\(function)[\(line)]" QorumOnlineLogs.sendError(classInformation: informationPart, textObject: info, level: levelText) } @@ -243,7 +247,9 @@ public func QL3(warning: T, _ file: String = __FILE__, _ function: String = _ informationPart = "\(filename).\(function)[\(line)]:" } printLog(informationPart, text: warning, level: level) - } else if QorumOnlineLogs.shouldSendLine(level: level, fileName: filename) { + } + + if QorumOnlineLogs.shouldSendLine(level: level, fileName: filename) { let informationPart = "\(filename).\(function)[\(line)]" QorumOnlineLogs.sendError(classInformation: informationPart, textObject: warning, level: levelText) } @@ -263,7 +269,9 @@ public func QL4(error: T, _ file: String = __FILE__, _ function: String = __F informationPart = "\(filename).\(function)[\(line)]:" } printLog(informationPart, text: error, level: level) - } else if QorumOnlineLogs.shouldSendLine(level: level, fileName: filename) { + } + + if QorumOnlineLogs.shouldSendLine(level: level, fileName: filename) { let informationPart = "\(filename).\(function)[\(line)]" QorumOnlineLogs.sendError(classInformation: informationPart, textObject: error, level: levelText) } From e5a389dc3adaefe4f0ca3aad98c899087c720264 Mon Sep 17 00:00:00 2001 From: Konrad Zdunczyk Date: Mon, 28 Dec 2015 20:41:32 +0100 Subject: [PATCH 3/3] Revert "Fix bug which cause online log was possible only when QorumLogs.enabled = false" This reverts commit 1f082f87d3945e99d5a148de3359d8365e5700f3. --- QorumLogs.swift | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/QorumLogs.swift b/QorumLogs.swift index 9717e0b..05733cd 100755 --- a/QorumLogs.swift +++ b/QorumLogs.swift @@ -203,9 +203,7 @@ public func QL1(debug: T, _ file: String = __FILE__, _ function: String = __F informationPart = "\(filename).\(function)[\(line)]:" } printLog(informationPart, text: debug, level: level) - } - - if QorumOnlineLogs.shouldSendLine(level: level, fileName: filename) { + } else if QorumOnlineLogs.shouldSendLine(level: level, fileName: filename) { let informationPart = "\(filename).\(function)[\(line)]" QorumOnlineLogs.sendError(classInformation: informationPart, textObject: debug, level: levelText) } @@ -225,9 +223,7 @@ public func QL2(info: T, _ file: String = __FILE__, _ function: String = __FU informationPart = "\(filename).\(function)[\(line)]:" } printLog(informationPart, text: info, level: level) - } - - if QorumOnlineLogs.shouldSendLine(level: level, fileName: filename) { + } else if QorumOnlineLogs.shouldSendLine(level: level, fileName: filename) { let informationPart = "\(filename).\(function)[\(line)]" QorumOnlineLogs.sendError(classInformation: informationPart, textObject: info, level: levelText) } @@ -247,9 +243,7 @@ public func QL3(warning: T, _ file: String = __FILE__, _ function: String = _ informationPart = "\(filename).\(function)[\(line)]:" } printLog(informationPart, text: warning, level: level) - } - - if QorumOnlineLogs.shouldSendLine(level: level, fileName: filename) { + } else if QorumOnlineLogs.shouldSendLine(level: level, fileName: filename) { let informationPart = "\(filename).\(function)[\(line)]" QorumOnlineLogs.sendError(classInformation: informationPart, textObject: warning, level: levelText) } @@ -269,9 +263,7 @@ public func QL4(error: T, _ file: String = __FILE__, _ function: String = __F informationPart = "\(filename).\(function)[\(line)]:" } printLog(informationPart, text: error, level: level) - } - - if QorumOnlineLogs.shouldSendLine(level: level, fileName: filename) { + } else if QorumOnlineLogs.shouldSendLine(level: level, fileName: filename) { let informationPart = "\(filename).\(function)[\(line)]" QorumOnlineLogs.sendError(classInformation: informationPart, textObject: error, level: levelText) }