     }
 
     init?(filename: String, flags: Int32, key: String? = nil, prevKey: String? = nil) {
+        log.debug("Opening connection to \(filename).")
         self.filename = filename
         self.queue = dispatch_queue_create("SQLite connection: \(filename)", DISPATCH_QUEUE_SERIAL)
-        if let _ = openWithFlags(flags) {
+        if let failure = openWithFlags(flags) {
+            log.warning("Opening connection to \(filename) failed: \(failure).")
             return nil
         }
 

     * Blindly attempts a WAL checkpoint on all attached databases.
     */
    func checkpoint(mode: Int32 = SQLITE_CHECKPOINT_PASSIVE) {
        sqlite3_wal_checkpoint_v2(sqliteDB, nil, mode, nil, nil)
    }

    func vacuum() -> NSError? {


    /// Closes a connection. This is called via deinit. Do not call this yourself.
    private func closeCustomConnection() -> NSError? {
        log.debug("Closing custom connection for \(self.filename) on \(NSThread.currentThread()).")
        // Make sure we don't try to call sqlite3_close multiple times.
        // TODO: add a lock here?
        guard self.sqliteDB != nil else {
            log.warning("Connection was nil.")
            return nil
        }

        let status = sqlite3_close(self.sqliteDB)
        log.debug("Closed \(self.filename).")
        self.sqliteDB = nil

        if status != SQLITE_OK {
            log.error("Got \(status) while closing.")
            return createErr("During: closing database with flags", status: Int(status))
        }

        return nil
