forked from Haneke/HanekeSwift
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Log.swift
38 lines (30 loc) · 944 Bytes
/
Log.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
//
// Log.swift
// Haneke
//
// Created by Hermes Pique on 11/10/14.
// Copyright (c) 2014 Haneke. All rights reserved.
//
import Foundation
struct Log {
private static let Tag = "[HANEKE]"
private enum Level : String {
case Debug = "[DEBUG]"
case Error = "[ERROR]"
}
private static func log(level : Level, @autoclosure _ message: () -> String, _ error : NSError? = nil) {
if let error = error {
NSLog("%@%@ %@ with error %@", Tag, level.rawValue, message(), error);
} else {
NSLog("%@%@ %@", Tag, level.rawValue, message())
}
}
static func debug(@autoclosure message: () -> String, _ error : NSError? = nil) {
#if DEBUG
log(.Debug, message, error)
#endif
}
static func error(@autoclosure message: () -> String, _ error : NSError? = nil) {
log(.Error, message, error)
}
}