mirror of
https://github.com/Ranchero-Software/NetNewsWire
synced 2026-12-05 03:37:41 +00:00
Move ErrorLog stuff to its own module. Extend it to report errors for components other than Accounts.
This commit is contained in:
1 parent
ef8c8af43d
commit
5c7b8cff07
7 files changed
+213
-79
No files matched your search
@@ -0,0 +1,61 @@
|
||||
//
|
||||
// ErrorLogTable.swift
|
||||
// ErrorLog
|
||||
//
|
||||
// Created by Brent Simmons on 3/11/26.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import RSDatabase
|
||||
import RSDatabaseObjC
|
||||
|
||||
struct ErrorLogTable {
|
||||
|
||||
static let name = "errors"
|
||||
|
||||
static func insertEntry(sourceName: String, sourceID: Int, errorMessage: String, database: FMDatabase) {
|
||||
let dictionary: DatabaseDictionary = [
|
||||
ErrorLogEntry.DatabaseKey.date: Date().timeIntervalSince1970,
|
||||
ErrorLogEntry.DatabaseKey.sourceName: sourceName,
|
||||
ErrorLogEntry.DatabaseKey.sourceID: sourceID,
|
||||
ErrorLogEntry.DatabaseKey.errorMessage: errorMessage
|
||||
]
|
||||
database.insertRow(dictionary, insertType: .normal, tableName: name)
|
||||
}
|
||||
|
||||
static func allEntries(database: FMDatabase) -> [ErrorLogEntry] {
|
||||
let sql = "select * from \(name) order by id asc"
|
||||
guard let resultSet = database.executeQuery(sql, withArgumentsIn: nil) else {
|
||||
return []
|
||||
}
|
||||
|
||||
var entries = [ErrorLogEntry]()
|
||||
while resultSet.next() {
|
||||
if let entry = entryWithRow(resultSet) {
|
||||
entries.append(entry)
|
||||
}
|
||||
}
|
||||
return entries
|
||||
}
|
||||
|
||||
static func pruneEntries(limit: Int, database: FMDatabase) {
|
||||
let sql = "delete from \(name) where id not in (select id from \(name) order by id desc limit \(limit))"
|
||||
database.executeUpdateInTransaction(sql)
|
||||
}
|
||||
}
|
||||
|
||||
private extension ErrorLogTable {
|
||||
|
||||
static func entryWithRow(_ row: FMResultSet) -> ErrorLogEntry? {
|
||||
guard let sourceName = row.string(forColumn: ErrorLogEntry.DatabaseKey.sourceName),
|
||||
let errorMessage = row.string(forColumn: ErrorLogEntry.DatabaseKey.errorMessage) else {
|
||||
return nil
|
||||
}
|
||||
|
||||
let id = Int(row.longLongInt(forColumn: ErrorLogEntry.DatabaseKey.id))
|
||||
let date = Date(timeIntervalSince1970: row.double(forColumn: ErrorLogEntry.DatabaseKey.date))
|
||||
let sourceID = Int(row.int(forColumn: ErrorLogEntry.DatabaseKey.sourceID))
|
||||
|
||||
return ErrorLogEntry(id: id, date: date, sourceName: sourceName, sourceID: sourceID, errorMessage: errorMessage)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user