Created
February 3, 2018 17:10
-
-
Save tanakeiQ/3ed765ebcfe0946fd330e54cc2479434 to your computer and use it in GitHub Desktop.
swift4-logger-service.swift
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
public class Logger { | |
fileprivate enum Prefix: String { | |
case Info = "🍀" | |
case Warn = "🍋" | |
case Error = "🍎" | |
case Happy = "🎀" | |
} | |
public static func info(_ items: String...) { | |
print(serialize(items, prefix: .Info)) | |
} | |
public static func warn(_ items: String...) { | |
print(serialize(items, prefix: .Warn)) | |
} | |
public static func error(_ items: String...) { | |
print(serialize(items, prefix: .Error)) | |
} | |
public static func happy(_ items: String...) { | |
print(serialize(items, prefix: .Happy)) | |
} | |
private static func serialize(_ items: [String], prefix: Prefix) -> String { | |
return items.map { $0 | |
.replacingOccurrences(of: "\n", with: "\n\(prefix.rawValue) ", options: .regularExpression, range: nil) | |
.replacingOccurrences(of: "^", with: "\(prefix.rawValue) ", options: .regularExpression, range: nil) | |
.replacingOccurrences(of: "$", with: "\n", options: .regularExpression, range: nil) | |
}.joined() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
example
output