GNU bug report logs - #79253
Add timestamps to *Messages*

Previous Next

Package: emacs;

Reported by: "R. Diez" <rdiez-2006 <at> rd10.de>

Date: Sat, 16 Aug 2025 07:38:04 UTC

Severity: wishlist

Full log


View this message in rfc822 format

From: Eli Zaretskii <eliz <at> gnu.org>
To: "R. Diez" <rdiez-2006 <at> rd10.de>
Cc: 79253 <at> debbugs.gnu.org
Subject: bug#79253: Add timestamps to *Messages*
Date: Sun, 17 Aug 2025 09:53:26 +0300
severity 79253 wishlist
thanks

> Date: Sat, 16 Aug 2025 23:01:50 +0200
> Cc: 79253 <at> debbugs.gnu.org
> From: "R. Diez" <rdiez-2006 <at> rd10.de>
> 
> 
> >> Could you implement an easy way to add timestamps to the *Messages* buffer?
> > 
> > Did you try using set-message-function to install your function as the
> > one that adds a time stamp to the text of the message to be shown?  If
> > you tried, and it didn't work, please tell what didn't work.  If you
> > didn't try, please do.
> 
> First of all, thanks for the hint. The 'message' function does not mention 'set-message-function' or the like, so I missed it.
> 
> I could find very little information about 'set-message-function', and no examples whatsoever, so I came up with this:
> 
> (defun my-message-function (msg)
>    "" ; No docstring yet.
>    (concat "Test: " msg))
> 
> (setq set-message-function #'my-message-function)
> 
> The effect is that messages in the minibuffer do get the "Test:" prefix, but messages in the *Messages* buffer do not.
> 
> But that is exactly the opposite of what I am trying to achieve!

OK, thanks for testing.

One problem with your request is that Emacs many times generates
messages by multiple calls to the 'message' function.  Prepending the
current time to each message passed to 'message' will thus produce
somewhat sub-optimal, maybe even ugly, results.  For example, if you
type C-p at the first line of a buffer, Emacs signals an error that
logs in the *Messages* buffer as

  previous-line: Beginning of buffer

But if we prepend each logged message with current time, it will
instead look like this:

  17/08/2025 00:09:44 previous-line
  17/08/2025 00:09:44 :
  17/08/2025 00:09:44 Beginning of buffer

This happens because in this case we call 'message' 3 times, with the
following 3 strings:

  "previous-line"
  ": "
  "Beginning of buffer"

If this is acceptable, we can implement the feature you are asking
for.  Otherwise, I don't see how this could be implemented, except by
having each Lisp program that calls 'message' inject the time string
where appropriate.

What do people think about the acceptability of the above?
Do people have other ideas for implementing this?




This bug report was last modified 25 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.