anchor.diff:    (:metaclass postmodern:dao-class))
   
   (defmethod connect-db ((chatlog chatlog-pg) &key (db (db chatlog)) (host (host chatlog)) (port (port chatlog)) (user (user chatlog)) (pass (pass chatlog)))
  +  (v:info :chatlog-pg "Connecting ~a@~a:~a/~a" user host port db)
     (setf (db chatlog) db)
     (setf (host chatlog) host)
     (setf (port chatlog) port)
     (setf (user chatlog) user)
     (setf (pass chatlog) pass)
  -  (postmodern:connect-toplevel db user pass host port)
  +  (postmodern:connect-toplevel (copy-seq db) (copy-seq user) (copy-seq pass) (copy-seq host) :port port)
     (unless (postmodern:table-exists-p 'chatlog)
       (postmodern:execute (postmodern:dao-table-definition 'chatlog))))
   
   (defmethod disconnect-db ((chatlog chatlog-pg))
  +  (v:info :chatlog-pg "Disconnecting.")
     (postmodern:disconnect-toplevel))
   
   (defconstant +UNIX-EPOCH-DIFFERENCE+ (encode-universal-time 0 0 0 1 1 1970 0))
   (defmethod insert-record ((chatlog chatlog-pg) server channel user type message)
     (when (find (format NIL "~a/~a" server channel) (active-in chatlog) :test #'string-equal)
  -    (postmodern:insert-dao (make-instance 'record :server (princ-to-string server) :channel channel :user user
  -                                                  :time (- (get-universal-time) +UNIX-EPOCH-DIFFERENCE+)
  -                                                  :type type :message message))))
  +    (v:trace :chatlog-pg "Logging event from ~a/~a <~a> (~a)" server channel user type)
  +    (bordeaux-threads:with-lock-held ((lock chatlog))
  +      (postmodern:insert-dao (make-instance 'chatlog :server (princ-to-string server) :channel channel :user user
  +                                                     :time (- (get-universal-time) +UNIX-EPOCH-DIFFERENCE+)
  +                                                     :type type :message message)))))
   
   (define-group chatlog-pg :documentation "Change chatlog-pg settings.")
   
  
positive.code: 
  (define-module chatlog-pg ()
    ((%active-in :initarg :active-in :initform () :accessor active-in)
     (%db :initarg :db :accessor db)
     (%host :initarg :host :accessor host)
     (%port :initarg :port :accessor port)
     (%user :initarg :user :accessor user)
     (%pass :initarg :pass :accessor pass))
    (:documentation "Logs messages in channels to a database."))
  
  (defmethod start ((chatlog chatlog-pg))
  
negative.code:   (setf (port chatlog) (config-tree :chatlog-pg :port))
    (setf (user chatlog) (config-tree :chatlog-pg :user))
    (setf (pass chatlog) (config-tree :chatlog-pg :pass))
    (connect-db chatlog))
  
  (defmethod stop ((chatlog chatlog-pg))
    (disconnect-db chatlog)
    (setf (config-tree :chatlog-pg :db) (db chatlog))
    (setf (config-tree :chatlog-pg :host) (host chatlog))
    (setf (config-tree :chatlog-pg :port) (port chatlog))
  