log4-hi-mode.el
author Oleksandr Gavenko <gavenkoa@gmail.com>
Wed, 25 Feb 2015 01:13:28 +0200
changeset 1227 e2355b44d39d
parent 1137 b260dc221119
child 1261 ebbd2c480f1d
permissions -rw-r--r--
Enable wesnoth-mode if possible.


(defface log4-hi-error-face
  '((t :inherit error))
  "Face for critical message.")

(defface log4-hi-warn-face
  '((t :inherit warning))
  "Face for urgent message.")

(defface log4-hi-info-face
  '((t :inherit success))
  "Face for informational message.")

(defface log4-hi-func-face
  '((t :inherit font-lock-function-name-face))
  "Face for functions in trace.")

(defface log4-hi-time-face
  '((t :inherit font-lock-builtin-face))
  "Face for time.")

(defvar log4-hi-keywords
  '(("FATAL\\|ERROR" . 'log4-hi-error-face)
    ("WARN\\|SEVERE" . 'log4-hi-warn-face)
    ("INFO\\|DEBUG\\|TRACE" . 'log4-hi-info-face) ))

(defvar log4-hi-func-keywords
  '(("at [[:alnum:].]+\\.\\([[:alnum:]$]+\\.[[:alnum:]$<>]+\\)([[:alnum:]]+\\.java:[0-9]+)" 1 'log4-hi-func-face) ))

(defvar log4-hi-time-keywords
  '(("\\<[0-9]?[0-9]:[0-9][0-9]:[0-9][0-9]\\>" . 'log4-hi-time-face)))

(defvar log4-hi-func t
  "Mark to use hilighting of function names in stacktraces. Currently only Java supported.")

;;;###autoload
(define-minor-mode log4-hi-mode
  "Highlight standard elements in log4* like log-files."
  nil " log4-hi" nil
  :global nil
  (catch 'exit
    (when log4-hi-mode
      (font-lock-mode 1)
      (font-lock-add-keywords nil log4-hi-keywords)
      (font-lock-add-keywords nil log4-hi-time-keywords)
      (when log4-hi-func (font-lock-add-keywords nil log4-hi-func-keywords))
      (throw 'exit nil))
    (font-lock-remove-keywords nil log4-hi-keywords)
    (font-lock-remove-keywords nil log4-hi-time-keywords)
    (font-lock-remove-keywords nil log4-hi-func-keywords))
  (font-lock-fontify-buffer))

(provide 'log4-hi-mode)