[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Log file helper



A few weeks ago we discussed the issue of efficiently
reading log files inside emacspeak, and I had pointed to
forms mode.

Here is a slightly cleaned up version of what I use to
quickly examine /var/adm/messages on linux and solaris 

Instructions on use:

Save the attached file 
as messages.el  and open it with
M-x forms-find-file

When prompted specify the log file you want to view
--/var/adm/messages is the default.

You will also be prompted for a filter pattern --if you
specify a string, lines matching that string will be nuked
before 
the log is displayed.

Finally, you can filter out other unwanted lines by invoking 
M-x forms-rerun-filter 
and specifying a pattern.

You should of course read the help on forms mode to learn
how to use all its facilities.

Note that the attached file splits records as they appear in
/var/adm/messages 
--you can modify it appropriately for other log formats.
;;;$Id: messages.el,v 1.2 1998/12/19 02:35:55 raman Exp $
;;; Display /var/adm/messages
(setq forms-read-only t)
(setq forms-file
      (read-file-name  "Messages file: "
                       "/var/adm/"
                       "/var/adm/messages"))
(defun flush-unwanted-messages ()
  "Prompt for pattern and flush matching lines"
  (interactive)
  (let ((pattern (read-from-minibuffer
                  "Specify filter pattern")))
    (when (> (length pattern) 0)
(flush-lines
 pattern))))

(setq forms-read-file-filter 'flush-unwanted-messages)
(setq forms-read-only nil)
(setq forms-field-sep
      (substring (system-name)
0
(string-match "\\." (system-name))))
(setq forms-number-of-fields 2)

(setq forms-format-list
      (list
       2
       "\n"
       1
       "\n"))

(defun forms-rerun-filter ()
  "Rerun  filter --allows us to nuke more matching records"
  (interactive)
  (declare (special forms--file-buffer))
  (save-excursion
    (set-buffer forms--file-buffer)
    (let ((inhibit-read-only t)
          (file-modified (buffer-modified-p)))
      (flush-unwanted-messages)
      (if (not file-modified) (set-buffer-modified-p
                               nil))))
  (let (ro)
    (setq forms--total-records
	  (save-excursion
	    (prog1
		(progn
		  ;;(message "forms: counting records...")
		  (set-buffer forms--file-buffer)
		  (bury-buffer (current-buffer))
		  (setq ro buffer-read-only)
		  (count-lines (point-min) (point-max)))
	      ;;(message "forms: counting records... done.")
	      )))
    (if ro
	(setq forms-read-only t)))
  (message "%s records after filtering"
           forms--total-records))



Emacspeak Files | Subscribe | Unsubscribe