[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"
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
- updated log-message,
Cecil Westerhof <=