Created
December 2, 2017 15:09
-
-
Save roana0229/6a07357e1d90ea1eb7ec106f57670a58 to your computer and use it in GitHub Desktop.
アプリ開発時のスニペット的な何か
This file contains hidden or 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
import os | |
extension OSLogType: CustomStringConvertible { | |
public var description: String { | |
switch self { | |
case OSLogType.info: | |
return "INFO" | |
case OSLogType.debug: | |
return "DEBUG" | |
case OSLogType.error: | |
return "ERROR" | |
case OSLogType.fault: | |
return "FAULT" | |
default: | |
return "DEFAULT" | |
} | |
} | |
} | |
final class Logger { | |
private init() {} | |
static var osLog: OSLog = OSLog.default | |
public static func info(message: String, osLog: OSLog = osLog) { | |
doLog(message: message, osLog: osLog, logType: .info) | |
} | |
public static func debug(message: String, osLog: OSLog = osLog) { | |
doLog(message: message, osLog: osLog, logType: .debug) | |
} | |
public static func error(_ error: Error, osLog: OSLog = osLog) { | |
doLog(message: "error: \(error.localizedDescription)", osLog: osLog, logType: .error) | |
} | |
public static func error(message: String, osLog: OSLog = osLog) { | |
doLog(message: message, osLog: osLog, logType: .error) | |
} | |
public static func fault(message: String, osLog: OSLog = osLog) { | |
doLog(message: message, osLog: osLog, logType: .fault) | |
} | |
public static func `default`(message: String, osLog: OSLog = osLog) { | |
doLog(message: message, osLog: osLog) | |
} | |
private static func doLog(message: String, osLog: OSLog, logType: OSLogType = .default) { | |
os_log("[%@] %@", log: osLog, type: logType, String(describing: logType), message) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment