13

Some of the log files I'm working with are fairly large (>200Mb) but it would be nice to browse them in Emacs. At the moment by default Emacs attempts to enable log4j mode which just slows everything down. What I really need is a lightweight viewer that:

  • disabled undo mode
  • can auto-revert when the log file is updated
  • can follow the tail of the log when it updates

Ideally it would be nice just to map in a small portion of the log file as you browse through. Do any such log modes exist?

6
  • 3
    Not an emacs answer, but I've found that using tmux with a simple tail -f has given me the best solution, using tmux will allow you to stop the log and search around it using emacs like bindings. My log files are usually upwards of 2gb and it runs well. Alternatively M-x shell + tail -f + no font lock is a nice solution. Jun 8, 2015 at 15:24
  • 1
    Not exactly what you're asking for, but perhaps M-x fundamental-mode would be an improvement over log4j-mode in terms of speed.
    – legoscia
    Jun 8, 2015 at 15:24
  • @legoscia: yeah I've already been manually switching to text-mode which helps.
    – stsquad
    Jun 8, 2015 at 15:44
  • What I usually do in this case: similar to what @JordonBiondo suggested, except I'm using a pager instead of tail, i.e. cat file.log | less. This has the benefit of being able to use all the pager commands, such as searching and displaying number of lines at a time.
    – wvxvw
    Jun 8, 2015 at 15:45
  • Also, this: github.com/mbriggs/emacs-pager I found I've bookmarked it, but didn't use...
    – wvxvw
    Jun 8, 2015 at 15:47

3 Answers 3

7

This is what I use. It disables everything that might slow emacs down, makes the buffer read only, and sets up auto-revert-tail-mode:

;; automagically tail log files
(add-to-list 'auto-mode-alist '("\\.log\\'" . auto-revert-tail-mode))

(defun etc-log-tail-handler ()
  (end-of-buffer)
  (make-variable-buffer-local 'auto-revert-interval)
  (setq auto-revert-interval 1)
  (auto-revert-set-timer)
  (make-variable-buffer-local 'auto-revert-verbose)
  (setq auto-revert-verbose nil)
  (read-only-mode t)
  (font-lock-mode 0)
  (when (fboundp 'show-smartparens-mode)
    (show-smartparens-mode 0)))

(add-hook 'auto-revert-tail-mode-hook 'etc-log-tail-handler)

If you don't want emacs to behave this way for all auto-revert-tail-mode buffers you could add a check to make sure the file actually ends in .log at the top of etc-log-tail-handler, or use whatever other criteria you like.

2

I have been using https://github.com/re5et/itail with success for a couple of years.

It is a tail mode that opens in it's own buffer.

5
  • Additionally I have adapted ESHELL enough to my needs to comfortably run Leiningen and other CLI build tools reasonably well so that I can view my development build output easily in a buffer.
    – huntar
    Jun 8, 2015 at 16:06
  • Instead of commenting, please edit your own post to include the additional information. (After you do so, you may delete your comment.) Jun 8, 2015 at 16:17
  • @ScottWeldon I thought the additional information was more appropriate as a comment
    – huntar
    Jun 8, 2015 at 16:19
  • Comments are for clarification, constructive criticism, and minor or transient information. While it could qualify as minor, I think it would work just as well, if not better, as an edit. Jun 8, 2015 at 16:26
  • I've played with this a bit and I quite like it although it does seem to suffer when the data rate is high.
    – stsquad
    Jun 10, 2015 at 9:17
0

I have read that if you set global font locking to nil you should also see speed improvements

(global-font-lock-mode -1)

and maybe

(setq jit-lock-defer-time 0.05)

will improve scrolling speeds

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.