[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

updated log-message

From: Cecil Westerhof
Subject: updated log-message
Date: Tue, 04 May 2010 15:44:12 -0000
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux)

Some time ago I posted some code for logging to a buffer. Because
sometimes I want to save the logging also, I defined an extra parameter
dir-name. This is the directory where the log-message is appended.

For example when I call:
    (log-message "Starting gnus-idle-daemon"

Where gnus-message-log-idle-daemon contains:
    (:buffer-name " gnus-idle-daemon-log" :dir-name "~/.gnus.d/logging/" 
:max-number-of-lines 500 :number-to-decrease-extra 50)

Then in ~/.gnus.d/logging/2010-04-08 is appended:
    2010-04-08 08:45:19: Starting gnus-idle-daemon

An example of the output for the normal logging is:
    2010-04-08 07:50:45: Start with getting new news
               07:51:04: Done with getting new news (19 seconds)

The code itself is below. I hope it is useful to someone else. If the
code could be improved, or if there is an error: let me know. If someone
has a good idea, I also like to hear about it.

    (defun log-message (this-message log-message-list &optional log-format)
      "Put message prefixed with date/time in (created) buffer-name;
    When buffer-name starts with a space the buffer is hidden and undo is 
      (let ((beg)
            (buffer-name          (getf log-message-list :buffer-name))
            (decrease-extra       (getf log-message-list 
            (dir-name             (getf log-message-list :dir-name nil))
            (max-number-of-lines  (getf log-message-list :max-number-of-lines))
            (time-format-continue "           %T: ")
            (time-format-start      "%Y-%m-%d %T: "))
        (if buffer-name
              (setq time-format
                    (case log-format
                      ('continue time-format-continue)
                      (otherwise time-format-start)))
              (with-current-buffer (get-buffer-create buffer-name)
                (setq message
                      (format "%s%s\n"
                              (format-time-string time-format)
                (goto-char (point-max))
                (setq beg (point))
                (insert  message)
                (if (integerp max-number-of-lines)
                    (buffer-delete-lines-if-necessary max-number-of-lines
                (when dir-name
                  (setq file-name 
                        (format "%s%s" dir-name (format-time-string 
                  (write-region message nil file-name t))))
          (message "%slog-message called without a buffername (%s)\n"
                   (format-time-string time-format-start)

My only problem is with write-region. This gives a message to the
mini-buffer. If someone knows a way to circumvent this ...

Cecil Westerhof
Senior Software Engineer

reply via email to

[Prev in Thread] Current Thread [Next in Thread]