     /// > advantage of the error logging facility of SQLite in their products,
     /// > as it is very low CPU and memory cost but can be a huge aid
     /// > for debugging.
-    public static var logError: LogErrorFunction? = nil
+    public static var logError: LogErrorFunction? = nil {
+        didSet {
+            if let logError = logError {
+                registerErrorLogCallback { (_, code, message) in
+                    guard let logError = Database.logError else { return }
+                    guard let message = message.map({ String(cString: $0) }) else { return }
+                    let resultCode = ResultCode(rawValue: code)
+                    logError(resultCode, message)
+                }
+            } else {
+                registerErrorLogCallback(nil)
+            }
+        }
+    }
     
     /// The database configuration
     public let configuration: Configuration

    // MARK: - Initializer

    init(path: String, configuration: Configuration, schemaCache: DatabaseSchemaCache) throws {
        // Setup the global SQLite error log before connecting to the database.
        Database.setupGlobalErrorLog()
        
        let sqliteConnection = try Database.openConnection(path: path, flags: configuration.SQLiteOpenFlags)
        do {
            try Database.activateExtendedCodes(sqliteConnection)

extension Database {

    // MARK: - Database Opening
    
    private static func openConnection(path: String, flags: Int32) throws -> SQLiteConnection {
        // See https://www.sqlite.org/c3ref/open.html
