r8548: fix bug with unknown/private stream of nil
[irc-logger.git] / logger.lisp
index 449f154a08e97c76b37f1e0c0e4c43b87347b252..16a47aff2e5336703a96456c2aba9f48803629ce 100644 (file)
     (format stream "~S~%" 
            (string-right-trim '(#\return) (raw-message-string msg)))))
 
-(uffi:def-foreign-type time-t :unsigned-long)
-(uffi:def-function ("ctime" c-ctime) 
-    ((time (* time-t)))
-  :returning :cstring)
+(defconstant +posix-epoch+
+  (encode-universal-time 0 0 0 1 1 1970 0))
+
+(defun posix-time-to-utime (time)
+  (+ time +posix-epoch+))
 
 (defun last-sexp-field (type msg)
   (cond
     (when (stringp (car (last (arguments msg))))
       (let ((secs (parse-integer (car (last (arguments msg))) :junk-allowed t)))
        (when secs
-         (string-right-trim '(#\newline #\return)
-                            (uffi:convert-from-cstring
-                             (uffi:with-foreign-object (time 'time-t)
-                               (setf (uffi:deref-pointer time :unsigned-long) secs)
-                               (c-ctime time))))))))
+         (posix-time-to-utime secs)))))
    ((need-user-address? type)
     (user-address msg))))
 
 (defmethod %output-event ((format (eql :sexp)) stream utime type channel source text
                          msg unichannel)
-  (let ((*print-circle* nil)
-       (*print-pretty* nil))
+  (with-standard-io-syntax
     (if unichannel
        (format stream "(~S ~S ~S ~S ~S)~%" utime type source text (last-sexp-field type msg))
-      (format stream "(~S ~S ~S ~S ~S ~S)~%" utime type source channel text
-             (last-sexp-field type msg)))))
+       (format stream "(~S ~S ~S ~S ~S ~S)~%" utime type source channel text
+               (last-sexp-field type msg)))))
 
 (defmethod %output-event ((format (eql :text)) stream utime type channel
                          source text msg unichannel)
             (output-event-for-a-stream msg type channel text logger i))))))))
 
 (defun get-private-log-stream (logger)
-  (or (private-log-stream logger) *standard-output*))
+  (if (and logger (private-log-stream logger))
+      (private-log-stream logger)
+    *standard-output*))
 
 (defun get-unknown-log-stream (logger)
-  (or (unknown-log-stream logger) *standard-output*))
+  (if (and logger (unknown-log-stream logger))
+      (unknown-log-stream logger)
+    *standard-output*))
 
 (defun privmsg-hook (msg)
   (let ((logger (find-logger-with-connection (connection msg)))