unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* updated log-message
@ 2010-04-08  7:23 Cecil Westerhof
  2010-04-08  8:01 ` José A. Romero L.
  0 siblings, 1 reply; 3+ messages in thread
From: Cecil Westerhof @ 2010-04-08  7:23 UTC (permalink / raw)
  To: help-gnu-emacs

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"
                 gnus-message-log-idle-daemon
                 'start)

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 disabled."
      (let ((beg)
            (buffer-name          (getf log-message-list :buffer-name))
            (decrease-extra       (getf log-message-list :number-to-decrease-extra))
            (dir-name             (getf log-message-list :dir-name nil))
            (file-name)
            (log-format-to-use)
            (max-number-of-lines  (getf log-message-list :max-number-of-lines))
            (message)
            (time-format)
            (time-format-continue "           %T: ")
            (time-format-start      "%Y-%m-%d %T: "))
        (if buffer-name
            (progn
              (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)
                              this-message))
                (goto-char (point-max))
                (setq beg (point))
                (insert  message)
                (if (integerp max-number-of-lines)
                    (buffer-delete-lines-if-necessary max-number-of-lines
                                                      decrease-extra))
                (when dir-name
                  (setq file-name 
                        (format "%s%s" dir-name (format-time-string "%Y-%m-%d")))
                  (write-region message nil file-name t))))
          (message "%slog-message called without a buffername (%s)\n"
                   (format-time-string time-format-start)
                   this-message))))

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
LinkedIn: http://www.linkedin.com/in/cecilwesterhof


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: updated log-message
  2010-04-08  7:23 updated log-message Cecil Westerhof
@ 2010-04-08  8:01 ` José A. Romero L.
  2010-04-08  9:22   ` Cecil Westerhof
  0 siblings, 1 reply; 3+ messages in thread
From: José A. Romero L. @ 2010-04-08  8:01 UTC (permalink / raw)
  To: help-gnu-emacs

On 8 Kwi, 09:23, Cecil Westerhof <Ce...@decebal.nl> wrote:
(...)
> My only problem is with write-region. This gives a message to the
> mini-buffer. If someone knows a way to circumvent this ...
(...)

Do you mean the "Wrote file" message?

According to the description of write-region:

    (write-region START END FILENAME &optional APPEND VISIT LOCKNAME
MUSTBENEW)
    (...)
    If VISIT is neither t nor nil nor a string,
      that means do not display the "Wrote file" message.
    (...)

Cheers,
--
José A. Romero L.
escherdragon at gmail
"We who cut mere stones must always be envisioning cathedrals."
(Quarry worker's creed)



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: updated log-message
  2010-04-08  8:01 ` José A. Romero L.
@ 2010-04-08  9:22   ` Cecil Westerhof
  0 siblings, 0 replies; 3+ messages in thread
From: Cecil Westerhof @ 2010-04-08  9:22 UTC (permalink / raw)
  To: help-gnu-emacs

José A. Romero L. <escherdragon@gmail.com> writes:

>> My only problem is with write-region. This gives a message to the
>> mini-buffer. If someone knows a way to circumvent this ...
> (...)
>
> Do you mean the "Wrote file" message?
>
> According to the description of write-region:
>
>     (write-region START END FILENAME &optional APPEND VISIT LOCKNAME
> MUSTBENEW)
>     (...)
>     If VISIT is neither t nor nil nor a string,
>       that means do not display the "Wrote file" message.
>     (...)

I overlooked that. I changed the write-region to:
    (write-region message nil file-name t 0)

Now it works like I want.

Thanks.

-- 
Cecil Westerhof
Senior Software Engineer
LinkedIn: http://www.linkedin.com/in/cecilwesterhof


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2010-04-08  9:22 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-04-08  7:23 updated log-message Cecil Westerhof
2010-04-08  8:01 ` José A. Romero L.
2010-04-08  9:22   ` Cecil Westerhof

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).