Skip to content

Commit

Permalink
Merge pull request #10 from konrado0905/master
Browse files Browse the repository at this point in the history
Mac OS X support
  • Loading branch information
Esqarrouth committed Jan 4, 2016
2 parents 8e9327d + e5a389d commit e4f1578
Showing 1 changed file with 25 additions and 11 deletions.
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 @@ -141,7 +145,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 @@ -156,7 +171,6 @@ public struct QorumOnlineLogs {
return false
}
}

}

///Detailed logs only used while debugging
Expand All @@ -174,7 +188,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 @@ -300,7 +314,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

0 comments on commit e4f1578

Please sign in to comment.