Log.swift 936 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. //
  2. // Log.swift
  3. // Haneke
  4. //
  5. // Created by Hermes Pique on 11/10/14.
  6. // Copyright (c) 2014 Haneke. All rights reserved.
  7. //
  8. import Foundation
  9. struct Log {
  10. fileprivate static let Tag = "[HANEKE]"
  11. fileprivate enum Level : String {
  12. case Debug = "[DEBUG]"
  13. case Error = "[ERROR]"
  14. }
  15. fileprivate static func log(_ level: Level, _ message: @autoclosure () -> String, _ error: Error? = nil) {
  16. if let error = error {
  17. print("\(Tag)\(level.rawValue) \(message()) with error \(error)")
  18. } else {
  19. print("\(Tag)\(level.rawValue) \(message())")
  20. }
  21. }
  22. static func debug(message: @autoclosure () -> String, error: Error? = nil) {
  23. #if DEBUG
  24. log(.Debug, message(), error)
  25. #endif
  26. }
  27. static func error(message: @autoclosure () -> String, error: Error? = nil) {
  28. log(.Error, message(), error)
  29. }
  30. }