Last active
August 29, 2015 14:26
-
-
Save harlanhaskins/2a1ada0fbf506cbe50b0 to your computer and use it in GitHub Desktop.
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
static func systemLogs(count: Int = 30) -> [LogEntry] { | |
let q = asl_new(UInt32(ASL_TYPE_QUERY)) | |
var logs = [LogEntry]() | |
let r = asl_search(nil, q) | |
var m = asl_next(r) | |
let keysNeeded = [ASL_KEY_MSG, ASL_KEY_TIME, ASL_KEY_LEVEL] | |
while logs.count < count && m != nil { | |
var logDict = [String: String]() | |
for key in keysNeeded { | |
if let val = String.fromCString(asl_get(m, key)) { | |
logDict[key] = val | |
} | |
} | |
if let entry = LogEntry(aslDict: logDict) { | |
logs.append(entry) | |
} | |
m = asl_next(r) | |
} | |
asl_release(r) | |
return logs.sorted { $0.timestamp < $1.timestamp } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment