Skip to content

Instantly share code, notes, and snippets.

@semireg
Created April 28, 2016 14:24
Show Gist options
  • Save semireg/66a127b6ae940984738e84334af84357 to your computer and use it in GitHub Desktop.
Save semireg/66a127b6ae940984738e84334af84357 to your computer and use it in GitHub Desktop.
Wrapper for QorumLogs
import QorumLogs
class Log: NSObject {
enum Level:Int {
case None = 0
case Debug = 1
case Info = 2
case Warning = 3
case Error = 4
}
static func start() {
QorumLogs.enabled = true
}
static func setMinimumLevel(level:Level, _ file: String = #file, _ function: String = #function, _ line: Int = #line){
QorumLogs.minimumLogLevelShown = level.rawValue
self.log(level, t: "<-- SETTING MINIMUM LOG VALUE", file, function, line)
}
static func onlyShowThisFile(_file: String = #file, _ function: String = #function, _ line: Int = #line){
let pathString = _file as NSString
let lastComponent = pathString.lastPathComponent as NSString
let filename = lastComponent.stringByDeletingPathExtension
self.line(_file, function, line)
QorumLogs.onlyShowThisFile(filename)
self.line(_file, function, line)
}
static func line(_file: String = #file, _ function: String = #function, _ line: Int = #line){
QLShortLine(_file, function, line)
}
static func linePlus(_file: String = #file, _ function: String = #function, _ line: Int = #line){
QLPlusLine(_file, function, line)
}
// ------
static func debug(t: String?, _ file: String = #file, _ function: String = #function, _ line: Int = #line){
self.log(.Debug, t: t, file, function, line)
}
// ------
static func info(t: String?, _ file: String = #file, _ function: String = #function, _ line: Int = #line){
self.log(.Info, t: t, file, function, line)
}
// ------
static func warning(t: String?, _ file: String = #file, _ function: String = #function, _ line: Int = #line){
self.log(.Warning, t: t, file, function, line)
}
// ------
static func error(t: String?, _ file: String = #file, _ function: String = #function, _ line: Int = #line){
self.log(.Error, t: t, file, function, line)
}
// Master logger
static func log(level:Level, t: String?, _ file: String = #file, _ function: String = #function, _ line: Int = #line){
let unwrappedT = t == nil ? "" : " " + t! // Add whitespace before t
let output = self.stringForLevel(level) + unwrappedT
switch level {
case .Debug:
QL1(output, file, function, line)
case .Info:
QL2(output, file, function, line)
case .Warning:
QL3(output, file, function, line)
case .Error:
QL4(output, file, function, line)
case .None:
self.log(.Error, t: "Something went wrong.")
}
}
static func stringForLevel(level:Level) -> String {
switch level {
case .Debug:
return "DEBUG"
case .Info:
return "INFO"
case .Warning:
return "WARNING"
case .Error:
return "ERROR"
case .None:
return "NONE?"
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment