|
1 ;;; log4-hi-mode.el --- Syntax highlighting logs keywords. |
|
2 |
|
3 ;;; Commentary: |
|
4 ;; Used for highlighting ERROR/WARN/INFO like keywords and dates in logs. |
|
5 |
|
6 ;;; Code: |
|
7 |
|
8 (defgroup log4-hi nil |
|
9 "`log4-hi-mode' mode for highlighting logs." |
|
10 :prefix "log4-hi-" |
|
11 :group 'text) |
|
12 |
|
13 (defface log4-hi-error-face |
|
14 '((t :inherit error)) |
|
15 "Face for critical message." |
|
16 :group 'log4-hi) |
|
17 |
|
18 (defface log4-hi-warn-face |
|
19 '((t :inherit warning)) |
|
20 "Face for urgent message." |
|
21 :group 'log4-hi) |
|
22 |
|
23 (defface log4-hi-info-face |
|
24 '((t :inherit success)) |
|
25 "Face for informational message." |
|
26 :group 'log4-hi) |
|
27 |
|
28 (defface log4-hi-func-face |
|
29 '((t :inherit font-lock-function-name-face)) |
|
30 "Face for functions in trace." |
|
31 :group 'log4-hi) |
|
32 |
|
33 (defface log4-hi-time-face |
|
34 '((t :inherit font-lock-builtin-face :height 0.7)) |
|
35 "Face for time." |
|
36 :group 'log4-hi) |
|
37 |
|
38 (defface log4-hi-hide-face |
|
39 '((t :inherit shadow :height 0.7 :family "Arial")) |
|
40 "Face for extra text for hiding." |
|
41 :group 'log4-hi) |
|
42 |
|
43 (defvar log4-hi-keywords |
|
44 '(("FATAL\\|ERROR" . 'log4-hi-error-face) |
|
45 ("WARN\\|SEVERE" . 'log4-hi-warn-face) |
|
46 ("INFO\\|DEBUG\\|TRACE" . 'log4-hi-info-face) )) |
|
47 |
|
48 (defvar log4-hi-func-keywords |
|
49 '(("^.\\{0,5\\}at [[:alnum:]./]+\\.\\([[:alnum:]$]+\\.[[:alnum:]$<>]+\\)([[:alnum:]]+\\.java:[0-9]+)" 1 'log4-hi-func-face) ) |
|
50 "Highlight regex for line from Java stack trace.") |
|
51 |
|
52 (defvar log4-hi-time-keywords |
|
53 '(("\\(:?\\(:?[0-9]\\{2\\}?[0-9]\\{2\\}.\\)?[0-9]\\{2\\}.[0-9]\\{2\\}.\\|\\<\\)[0-9]?[0-9]:[0-9][0-9]:[0-9][0-9]\\>\\(:?[.,][0-9]\\{3,6\\}\\)?" . 'log4-hi-time-face)) |
|
54 "Highlight regex for ISO date.") |
|
55 |
|
56 (defvar log4-hi-hide-regex |
|
57 '(("\\[`.\\{3,100\\}`]" . 'log4-hi-hide-face)) |
|
58 "Highlight regex for extra text for hiding.") |
|
59 |
|
60 (defvar log4-hi-func t |
|
61 "Mark to use hilighting of function names in stacktraces. Currently only Java supported.") |
|
62 |
|
63 (defvar log4-hi-mode-map (make-sparse-keymap) |
|
64 "Keymap for `log4-hi-mode'.") |
|
65 |
|
66 ;;;###autoload |
|
67 (define-minor-mode log4-hi-mode |
|
68 "Highlight standard elements in log4* like log-files." |
|
69 nil " log4-hi" log4-hi-mode-map |
|
70 :global nil |
|
71 (catch 'exit |
|
72 (when log4-hi-mode |
|
73 (font-lock-mode 1) |
|
74 (font-lock-add-keywords nil log4-hi-keywords) |
|
75 (font-lock-add-keywords nil log4-hi-time-keywords) |
|
76 (font-lock-add-keywords nil log4-hi-hide-regex) |
|
77 (when log4-hi-func (font-lock-add-keywords nil log4-hi-func-keywords)) |
|
78 (setq prettify-symbols-alist (list (cons "[`" ?$,2'f(B) (cons "`]" ?$,2'g(B))) |
|
79 (prettify-symbols-mode 1) |
|
80 (throw 'exit nil)) |
|
81 (font-lock-remove-keywords nil log4-hi-keywords) |
|
82 (font-lock-remove-keywords nil log4-hi-time-keywords) |
|
83 (font-lock-remove-keywords nil log4-hi-func-keywords) |
|
84 (font-lock-remove-keywords nil log4-hi-hide-regex) |
|
85 (prettify-symbols-mode -1)) |
|
86 (font-lock-flush)) |
|
87 |
|
88 (provide 'log4-hi-mode) |
|
89 |
|
90 (provide 'log4-hi-mode) |
|
91 |
|
92 ;;; log4-hi-mode.el ends here |