Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mac OS X support #10

Merged
merged 3 commits into from
Jan 4, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 25 additions & 11 deletions QorumLogs.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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?
Expand Down Expand Up @@ -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: "")
Expand All @@ -172,7 +187,6 @@ public struct QorumOnlineLogs {
return false
}
}

}

///Detailed logs only used while debugging
Expand All @@ -190,7 +204,7 @@ public func QL1<T>(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)
}
}
Expand Down Expand Up @@ -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)
}
Expand Down