Created
September 11, 2015 01:32
-
-
Save SammyJames/b3bcf1a8223a68d7a3c9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// main.swift | |
// Logg | |
// | |
// Created by Sammy James on 9/10/15. | |
// Copyright © 2015 Girl After Midnight. All rights reserved. | |
// | |
import Foundation | |
#if os(iOS) || os(watchOS) | |
import UIKit | |
#else | |
import AppKit | |
#endif | |
public class Logg : CustomDebugStringConvertible { | |
public enum Level: Int, Comparable, CustomStringConvertible { | |
case Verbose, Debug, Info, Warning, Error | |
public var description: String { | |
switch self { | |
case .Verbose: return "VRB" | |
case .Debug: return "DBG" | |
case .Info: return "INF" | |
case .Warning: return "WRN" | |
case .Error: return "ERR" | |
} | |
} | |
} | |
public var debugDescription: String { | |
get { | |
return "Logg" | |
} | |
} | |
internal func LogInternal( Lvl: Level, Function: String, File: String, Line: Int, @noescape Closure: () -> String? ) { | |
if let Msg: String = Closure() { | |
Paths = File.componentsSeparatedByString("/") | |
print( "\(NSDate()) [\(Lvl)][\(Paths.last!):\(Line) \(Function)]: \(Msg)") | |
} | |
} | |
public func Verbose( @autoclosure Closure: () -> String?, Function: String = __FUNCTION__, File: String = __FILE__, Line: Int = __LINE__ ) { | |
self.LogInternal(.Verbose, Function: Function, File: File, Line: Line, Closure: Closure) | |
} | |
public func Verbose( Function: String = __FUNCTION__, File: String = __FILE__, Line: Int = __LINE__, @noescape Closure: () -> String? ) { | |
self.LogInternal(.Verbose, Function: Function, File: File, Line: Line, Closure: Closure) | |
} | |
public func Debug( @autoclosure Closure: () -> String?, Function: String = __FUNCTION__, File: String = __FILE__, Line: Int = __LINE__ ) { | |
self.LogInternal(.Debug, Function: Function, File: File, Line: Line, Closure: Closure) | |
} | |
public func Debug( Function: String = __FUNCTION__, File: String = __FILE__, Line: Int = __LINE__, @noescape Closure: () -> String? ) { | |
self.LogInternal(.Debug, Function: Function, File: File, Line: Line, Closure: Closure) | |
} | |
public func Info( @autoclosure Closure: () -> String?, Function: String = __FUNCTION__, File: String = __FILE__, Line: Int = __LINE__ ) { | |
self.LogInternal(.Info, Function: Function, File: File, Line: Line, Closure: Closure) | |
} | |
public func Info( Function: String = __FUNCTION__, File: String = __FILE__, Line: Int = __LINE__, @noescape Closure: () -> String? ) { | |
self.LogInternal(.Info, Function: Function, File: File, Line: Line, Closure: Closure) | |
} | |
public func Warning( @autoclosure Closure: () -> String?, Function: String = __FUNCTION__, File: String = __FILE__, Line: Int = __LINE__ ) { | |
self.LogInternal(.Warning, Function: Function, File: File, Line: Line, Closure: Closure) | |
} | |
public func Warning( Function: String = __FUNCTION__, File: String = __FILE__, Line: Int = __LINE__, @noescape Closure: () -> String? ) { | |
self.LogInternal(.Warning, Function: Function, File: File, Line: Line, Closure: Closure) | |
} | |
public func Error( @autoclosure Closure: () -> String?, Function: String = __FUNCTION__, File: String = __FILE__, Line: Int = __LINE__ ) { | |
self.LogInternal(.Error, Function: Function, File: File, Line: Line, Closure: Closure) | |
} | |
public func Error( Function: String = __FUNCTION__, File: String = __FILE__, Line: Int = __LINE__, @noescape Closure: () -> String? ) { | |
self.LogInternal(.Error, Function: Function, File: File, Line: Line, Closure: Closure) | |
} | |
private var Paths: [String] = [] | |
} | |
public func < ( Left: Logg.Level, Right: Logg.Level ) -> Bool { | |
return Left.rawValue < Right.rawValue | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment