Emacs의 * 메시지 * 버퍼의 각 항목에 타임 스탬프를 추가하는 방법은 무엇입니까?


11

*Messages*버퍼에 많이 의존 하지만 항목 시간이 표시되지 않습니다.

Emacs 메시지 버퍼의 각 항목에 타임 스탬프를 어떻게 추가 할 수 있습니까?

그래서 이런 식으로 :

Loading /Users/gsl/lisp.d/init.el (source)...
No outline structure detected
For information about GNU Emacs and the GNU system, type C-h C-a.
Loading /Users/gsl/lisp.d/var/recentf...done
Error running timer: (wrong-number-of-arguments (lambda nil (setq gc-cons-threshold (* 64 1024 1024)) (message "WARNING: gc-cons-threshold restored to %S")) 1)
[yas] Prepared just-in-time loading of snippets successfully.
M-] is undefined
CHILDREN [2 times]
‘show-all’ is an obsolete command (as of 25.1); use ‘outline-show-all’ instead.
Invalid face reference: nil [33 times]
Auto-saving...done
Saving file /Users/gsl/lisp.d/init.el...
Wrote /Users/gsl/lisp.d/init.el
mwheel-scroll: Beginning of buffer [5 times]
Mark set
previous-line: Beginning of buffer [10 times]
Quit [4 times]

다음과 같이 될 것입니다 :

2017-02-14-18:50:01 Loading /Users/gsl/lisp.d/init.el (source)...
2017-02-14-18:50:02 No outline structure detected
2017-02-14-18:50:03 For information about GNU Emacs and the GNU system, type C-h C-a.
2017-02-14-18:50:05 Loading /Users/gsl/lisp.d/var/recentf...done
2017-02-14-18:50:10 Error running timer: (wrong-number-of-arguments (lambda nil (setq gc-cons-threshold (* 64 1024 1024)) (message "WARNING: gc-cons-threshold restored     to %S")) 1)
2017-02-14-18:50:12 [yas] Prepared just-in-time loading of snippets successfully.
2017-02-14-18:50:40 M-] is undefined
2017-02-14-18:50:41 CHILDREN [2 times]
2017-02-14-18:50:00 ‘show-all’ is an obsolete command (as of 25.1); use ‘outline-show-all’ instead.
2017-02-14-18:50:01 Invalid face reference: nil [33 times]
2017-02-14-18:51:01 Auto-saving...done
2017-02-14-18:51:03 Saving file /Users/gsl/lisp.d/init.el...
2017-02-14-18:51:06 Wrote /Users/gsl/lisp.d/init.el
2017-02-14-18:51:09 mwheel-scroll: Beginning of buffer [5 times]
2017-02-14-18:51:11 Mark set
2017-02-14-18:51:21 previous-line: Beginning of buffer [10 times]

물론 EmacsWiki, Reddit 및 emacs.sx를 검색했지만 아무 소용이 없습니다.

나는 알고있다 command-log-mode타임 스탬프에 로그인 할 때 조정할 수있는,하지만 그것은 단지 이맥스 ' "시스템"포함한 대화 형 명령, 모든 메시지 유용합니다.

대신 메시지 버퍼에 기록 된 모든 메시지 는 타임 스탬프되어야합니다.

소스와 상관없이 Emacs 메시지 버퍼의 각 항목에 타임 스탬프를 어떻게 추가 할 수 있습니까?


2
이것은 Emacs의 기능 요청처럼 들립니다. 이 message명령은 C로 구현되며 직접 발신자가있을 수 있으므로 Emacs를 직접 구축하지 않고는 기록 된 모든 메시지가 타임 스탬프를받는 것을 보장 할 수 없습니다. 즉, messageElisp에서 호출 될 때 타임 스탬프를 도입하라는 명령을 명령 할 수 있습니다 . 몇 가지주의가 필요합니다. messageargs, 빈 형식 문자열 등을 사용하여 호출 할 수 있습니다. 또한 타임 스탬프 조언 자체 message가 일부 코드 경로를 호출하는 경우 재귀 루프를 피하려고 합니다.
— glucas


1
그것을 after-change-functions구현 하기 위해 (메시지 버퍼에서) 사용하는 경향이 있습니다 . 버퍼의 끝에 무언가가 삽입 될 때마다 타임 스탬프를 접두어로 붙입니다.
— phils

1
@phils은 참조 gnu.org/software/emacs/manual/html_node/elisp/Change-Hooks.html의 에 메시지를 출력 메시지 이러한 함수 호출과 중립 이러한 작성된 버퍼의 변경 등의 특정 내부 버퍼 변경을 수행하지 않는 버퍼 특정 작업에 대해 내부적으로 Emacs에 의해 Lisp 프로그램에 보이지 않아야합니다.
— xinfa tang

답변:


7

내 init.el에 다음 스 니펫이 있는데, 다음 Reddit 스레드에서 찾은 원본에서 수정되었습니다. http://www.reddit.com/r/emacs/comments/16tzu9/anyone_know_of_a_reasonable_way_to_timestamp/

(편집 : @blujay의 조언에 따라 조언 추가 및 서투른 읽기 전용 버퍼 처리로 현대화 됨)

(defun sh/current-time-microseconds ()
  "Return the current time formatted to include microseconds."
  (let* ((nowtime (current-time))
         (now-ms (nth 2 nowtime)))
    (concat (format-time-string "[%Y-%m-%dT%T" nowtime) (format ".%d]" now-ms))))

(defun sh/ad-timestamp-message (FORMAT-STRING &rest args)
  "Advice to run before `message' that prepends a timestamp to each message.

Activate this advice with:
(advice-add 'message :before 'sh/ad-timestamp-message)"
  (unless (string-equal FORMAT-STRING "%s%s")
    (let ((deactivate-mark nil)
          (inhibit-read-only t))
      (with-current-buffer "*Messages*"
        (goto-char (point-max))
        (if (not (bolp))
          (newline))
        (insert (sh/current-time-microseconds) " ")))))

(advice-add 'message :before 'sh/ad-timestamp-message)

결과적으로 다음과 같이 * 메시지 * 버퍼가 장식됩니다.

[2017-06-13T07:21:13.270070] Turning on magit-auto-revert-mode...
[2017-06-13T07:21:13.467317] Turning on magit-auto-revert-mode...done
[2017-06-13T07:21:13.557918] For information about GNU Emacs and the GNU system, type C-h C-a.

3
이것이 기본적으로 옵션으로 제공되지 않는 이유가 궁금합니다.
— bertfred

1
훌륭합니다. 이것이 바로 제가 찾던 것입니다. 감사합니다.
— gsl

2
@bertfred 아무도 그렇게하지 않았기 때문입니다. 아마도 당신일까요?
— Phil Lord

2
advice-add?를 사용하여 조언을 다시 작성할 수 있습니까? 그것은 defadvice할 수없는 상황을 처리하는 방법을 알고 있기 때문에 현재 선호되는 방법 입니다. 또한 (read-only-mode 0)아마도 영구적 인 것이기 때문에 해서는 안됩니다 . 버퍼를 수정하는 코드 주위에 바인딩 inhibit-read-only할 수 있습니다 t.
— blujay

2
난 당신의 코드를 사용하지만, 많은 메시지를 단지 타임 스탬프 표시
— xinfa 탕

5

@xinfatang의 간단한 솔루션을 함수 advice-add주위의 래퍼로 새 구문으로 변환하면 message다음과 같습니다.

(defun my-message-with-timestamp (old-func fmt-string &rest args)
   "Prepend current timestamp (with microsecond precision) to a message"
   (apply old-func
          (concat (format-time-string "[%F %T.%3N %Z] ")
                   fmt-string)
          args))

다음 *Messages*과 같은 출력 :

[2018-02-25 10:13:45.442 PST] Mark set

추가하려면 다음을 수행하십시오.

 (advice-add 'message :around #'my-message-with-timestamp)

제거:

 (advice-remove 'message #'my-message-with-timestamp)

3
주변 조언을 사용하지 않고 인수를 필터링 할 수도 있습니다 (advice-add 'message :filter-args 'with-timestamp).(defun with-timestamp (args) (push (concat (format-time-string "[%F %T.%3N] ") (car args)) (cdr args)))
— glucas

1
트윗 담아 가기 미니 버퍼 위로 마우스를 가져 가면 메시지가없는 타임 스탬프가 표시됩니다. 이를 피할 수있는 방법이 있습니까?
— AstroFloyd 2014

3

https://www.emacswiki.org/emacs/DebugMessages 에서 참조하십시오 .

(defadvice message (before when-was-that activate)
  "Add timestamps to `message' output."
  (ad-set-arg 0 (concat (format-time-string "[%Y-%m-%d %T %Z] ") 
                        (ad-get-arg 0)) ))

마지막으로 난 여전히 같은 스튜어트 Hickinbottom 은 미니 버퍼에서 쇼 타임 스탬프를 피하기 때문에의 대답, 다음은 내가 사용하는,이 메시지는 (가 응답 영역에 표시 무시 수정 된 버전 let message-log-max에 대한 nil메시지 함수 호출하기 전에이) :

 (defun my/ad-timestamp-message (FORMAT-STRING &rest args)
   "Advice to run before `message' that prepends a timestamp to each message.
    Activate this advice with:
      (advice-add 'message :before 'my/ad-timestamp-message)
    Deactivate this advice with:
      (advice-remove 'message 'my/ad-timestamp-message)"
       (if message-log-max
           (let ((deactivate-mark nil)
                 (inhibit-read-only t))
             (with-current-buffer "*Messages*"
               (goto-char (point-max))
               (if (not (bolp))
                   (newline))
               (insert (format-time-string "[%F %T.%3N] "))))))
 (advice-add 'message :before 'my/ad-timestamp-message)

2
타임 스탬프 형식을 %F %T.%3N마이크로 초 표시로 변경
— xinfa tang
당사 사이트를 사용함과 동시에 당사의 쿠키 정책과 개인정보 보호정책을 읽고 이해하였음을 인정하는 것으로 간주합니다.
Licensed under cc by-sa 3.0 with attribution required.