X-Git-Url: http://git.kpe.io/?a=blobdiff_plain;f=logger.lisp;h=16a47aff2e5336703a96456c2aba9f48803629ce;hb=f4a678d829c00ccfe0703b18a150332a4520bd85;hp=7c341299b3d07f120ed3c9b436477dbbd18197f4;hpb=63356535fbaa1b651d525e81befd6efd4b49016e;p=irc-logger.git diff --git a/logger.lisp b/logger.lisp index 7c34129..16a47af 100644 --- a/logger.lisp +++ b/logger.lisp @@ -246,23 +246,33 @@ (format stream "~S~%" (string-right-trim '(#\return) (raw-message-string msg))))) +(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 ((null msg) nil) ((eq type :kick) (trailing-argument msg)) + ((eq type :rpl_topicwhotime) + (when (stringp (car (last (arguments msg)))) + (let ((secs (parse-integer (car (last (arguments msg))) :junk-allowed t))) + (when secs + (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) @@ -356,10 +366,14 @@ (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))) @@ -471,8 +485,8 @@ (defun rpl_topicwhotime-hook (msg) (output-event msg :rpl_topicwhotime - (format nil "~{~A~^ ~}" (arguments msg)) - (trailing-argument msg))) + (second (arguments msg)) + (third (arguments msg)))) (defun invite-hook (msg) @@ -542,7 +556,8 @@ irc::irc-rpl_killdone-message irc::irc-rpl_closing-message irc::irc-rpl_topic-message irc::irc-rpl_namreply-message irc::irc-rpl_endofnames-message irc::irc-rpl_topicwhotime-message - irc::irc-rpl_motd irc::irc-rpl_motdstart-message irc::irc-rpl_endofmotd-message) + irc::irc-rpl_motd-message irc::irc-rpl_motdstart-message + irc::irc-rpl_endofmotd-message) ;; nothing to do ) (t @@ -634,7 +649,7 @@ (defun add-logger (nick server &key channels output (password "") realname username private-log unknown-log (logging-stream t) (async t) - (formats '(:text))) + (formats '(:sexp))) (when (find-logger-with-nick nick) (format (get-private-log-stream (find-logger-with-nick nick))