Skip to content

Instantly share code, notes, and snippets.

@jxq0
Created December 28, 2020 00:19
Show Gist options
  • Save jxq0/185112cb77781715968af4d0fe5bbe09 to your computer and use it in GitHub Desktop.
Save jxq0/185112cb77781715968af4d0fe5bbe09 to your computer and use it in GitHub Desktop.
class FMLog: NSObject {
let myOsLog = OSLog(subsystem: "com.jiaxq.fotomete", category: "")
func debug(
_ msg: String, _ args: CVarArg..., file: String = #file, line: Int = #line
) {
let logMsg = String(format: msg, arguments: args)
log(logMsg, type: .debug, file: file, line: line)
}
func info(
_ msg: String, _ args: CVarArg..., file: String = #file, line: Int = #line
) {
let logMsg = String(format: msg, arguments: args)
log(logMsg, type: .info, file: file, line: line)
}
func error(
_ msg: String, _ args: CVarArg..., file: String = #file, line: Int = #line
) {
let logMsg = String(format: msg, arguments: args)
log(logMsg, type: .error, file: file, line: line)
}
func fault(
_ msg: String, _ args: CVarArg..., file: String = #file, line: Int = #line
) {
let logMsg = String(format: msg, arguments: args)
log(logMsg, type: .fault, file: file, line: line)
}
func log(_ msg: String, type: OSLogType, file: String, line: Int) {
os_log(
"%s:%d %s", log: myOsLog, type: type,
(file as NSString).lastPathComponent, line, msg)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment