author | Oleksandr Gavenko <gavenkoa@gmail.com> |
Tue, 22 Sep 2020 12:55:29 +0300 | |
changeset 1622 | 954b7c665c1a |
parent 1610 | f88b5c82e16c |
child 1623 | 66e7dd2d4cf4 |
permissions | -rw-r--r-- |
1261
ebbd2c480f1d
Fix checkdoc warnings.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1137
diff
changeset
|
1 |
;;; log4-hi-mode.el --- Syntax highlighting logs keywords. |
ebbd2c480f1d
Fix checkdoc warnings.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1137
diff
changeset
|
2 |
|
ebbd2c480f1d
Fix checkdoc warnings.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1137
diff
changeset
|
3 |
;;; Commentary: |
ebbd2c480f1d
Fix checkdoc warnings.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1137
diff
changeset
|
4 |
;; Used for highlighting ERROR/WARN/INFO like keywords and dates in logs. |
ebbd2c480f1d
Fix checkdoc warnings.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1137
diff
changeset
|
5 |
|
ebbd2c480f1d
Fix checkdoc warnings.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1137
diff
changeset
|
6 |
;;; Code: |
1076
eed45b8a9e3a
Highlight standard elements in log4* like log-files.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
7 |
|
1520
049eff94d357
Fix: Warning: defface fails to specify containing group.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1518
diff
changeset
|
8 |
(defgroup log4-hi nil |
049eff94d357
Fix: Warning: defface fails to specify containing group.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1518
diff
changeset
|
9 |
"`log4-hi-mode' mode for highlighting logs." |
049eff94d357
Fix: Warning: defface fails to specify containing group.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1518
diff
changeset
|
10 |
:prefix "log4-hi-" |
049eff94d357
Fix: Warning: defface fails to specify containing group.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1518
diff
changeset
|
11 |
:group 'text) |
049eff94d357
Fix: Warning: defface fails to specify containing group.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1518
diff
changeset
|
12 |
|
1078
bd0c280abe8a
Define own faces to remove dependency on compile.el.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1077
diff
changeset
|
13 |
(defface log4-hi-error-face |
bd0c280abe8a
Define own faces to remove dependency on compile.el.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1077
diff
changeset
|
14 |
'((t :inherit error)) |
1520
049eff94d357
Fix: Warning: defface fails to specify containing group.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1518
diff
changeset
|
15 |
"Face for critical message." |
049eff94d357
Fix: Warning: defface fails to specify containing group.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1518
diff
changeset
|
16 |
:group 'log4-hi) |
1078
bd0c280abe8a
Define own faces to remove dependency on compile.el.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1077
diff
changeset
|
17 |
|
bd0c280abe8a
Define own faces to remove dependency on compile.el.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1077
diff
changeset
|
18 |
(defface log4-hi-warn-face |
bd0c280abe8a
Define own faces to remove dependency on compile.el.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1077
diff
changeset
|
19 |
'((t :inherit warning)) |
1520
049eff94d357
Fix: Warning: defface fails to specify containing group.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1518
diff
changeset
|
20 |
"Face for urgent message." |
049eff94d357
Fix: Warning: defface fails to specify containing group.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1518
diff
changeset
|
21 |
:group 'log4-hi) |
1078
bd0c280abe8a
Define own faces to remove dependency on compile.el.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1077
diff
changeset
|
22 |
|
bd0c280abe8a
Define own faces to remove dependency on compile.el.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1077
diff
changeset
|
23 |
(defface log4-hi-info-face |
bd0c280abe8a
Define own faces to remove dependency on compile.el.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1077
diff
changeset
|
24 |
'((t :inherit success)) |
1520
049eff94d357
Fix: Warning: defface fails to specify containing group.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1518
diff
changeset
|
25 |
"Face for informational message." |
049eff94d357
Fix: Warning: defface fails to specify containing group.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1518
diff
changeset
|
26 |
:group 'log4-hi) |
1076
eed45b8a9e3a
Highlight standard elements in log4* like log-files.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
27 |
|
1083
d4b063fc0f5e
Add highlighting for Java stack traces.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1078
diff
changeset
|
28 |
(defface log4-hi-func-face |
d4b063fc0f5e
Add highlighting for Java stack traces.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1078
diff
changeset
|
29 |
'((t :inherit font-lock-function-name-face)) |
1520
049eff94d357
Fix: Warning: defface fails to specify containing group.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1518
diff
changeset
|
30 |
"Face for functions in trace." |
049eff94d357
Fix: Warning: defface fails to specify containing group.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1518
diff
changeset
|
31 |
:group 'log4-hi) |
1083
d4b063fc0f5e
Add highlighting for Java stack traces.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1078
diff
changeset
|
32 |
|
1136
26996dddc80f
Add highlighting for time.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1134
diff
changeset
|
33 |
(defface log4-hi-time-face |
26996dddc80f
Add highlighting for time.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1134
diff
changeset
|
34 |
'((t :inherit font-lock-builtin-face)) |
1520
049eff94d357
Fix: Warning: defface fails to specify containing group.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1518
diff
changeset
|
35 |
"Face for time." |
049eff94d357
Fix: Warning: defface fails to specify containing group.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1518
diff
changeset
|
36 |
:group 'log4-hi) |
1136
26996dddc80f
Add highlighting for time.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1134
diff
changeset
|
37 |
|
1622
954b7c665c1a
Added highlighting for special pattern to be less distracting. Two symbols are used as markers from each side to avoid most false positive matches.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1610
diff
changeset
|
38 |
(defface log4-hi-hide-face |
954b7c665c1a
Added highlighting for special pattern to be less distracting. Two symbols are used as markers from each side to avoid most false positive matches.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1610
diff
changeset
|
39 |
'((t :inherit shadow)) |
954b7c665c1a
Added highlighting for special pattern to be less distracting. Two symbols are used as markers from each side to avoid most false positive matches.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1610
diff
changeset
|
40 |
"Face for extra text for hiding." |
954b7c665c1a
Added highlighting for special pattern to be less distracting. Two symbols are used as markers from each side to avoid most false positive matches.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1610
diff
changeset
|
41 |
:group 'log4-hi) |
954b7c665c1a
Added highlighting for special pattern to be less distracting. Two symbols are used as markers from each side to avoid most false positive matches.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1610
diff
changeset
|
42 |
|
1076
eed45b8a9e3a
Highlight standard elements in log4* like log-files.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
43 |
(defvar log4-hi-keywords |
1078
bd0c280abe8a
Define own faces to remove dependency on compile.el.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1077
diff
changeset
|
44 |
'(("FATAL\\|ERROR" . 'log4-hi-error-face) |
1134
d91fa7f7033a
Add keyword for highlighting.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1083
diff
changeset
|
45 |
("WARN\\|SEVERE" . 'log4-hi-warn-face) |
1078
bd0c280abe8a
Define own faces to remove dependency on compile.el.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1077
diff
changeset
|
46 |
("INFO\\|DEBUG\\|TRACE" . 'log4-hi-info-face) )) |
1076
eed45b8a9e3a
Highlight standard elements in log4* like log-files.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
47 |
|
1137
b260dc221119
Refactoring: fix according to naming convention.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1136
diff
changeset
|
48 |
(defvar log4-hi-func-keywords |
1610
f88b5c82e16c
Added docs, limited regex lookup for Java stack traces.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1609
diff
changeset
|
49 |
'(("^.\\{0,5\\}at [[:alnum:]./]+\\.\\([[:alnum:]$]+\\.[[:alnum:]$<>]+\\)([[:alnum:]]+\\.java:[0-9]+)" 1 'log4-hi-func-face) ) |
f88b5c82e16c
Added docs, limited regex lookup for Java stack traces.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1609
diff
changeset
|
50 |
"Highlight regex for line from Java stack trace.") |
1083
d4b063fc0f5e
Add highlighting for Java stack traces.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1078
diff
changeset
|
51 |
|
1136
26996dddc80f
Add highlighting for time.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1134
diff
changeset
|
52 |
(defvar log4-hi-time-keywords |
1610
f88b5c82e16c
Added docs, limited regex lookup for Java stack traces.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1609
diff
changeset
|
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\\}\\)?" . 'log4-hi-time-face)) |
f88b5c82e16c
Added docs, limited regex lookup for Java stack traces.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1609
diff
changeset
|
54 |
"Highlight regex for ISO date.") |
1136
26996dddc80f
Add highlighting for time.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1134
diff
changeset
|
55 |
|
1622
954b7c665c1a
Added highlighting for special pattern to be less distracting. Two symbols are used as markers from each side to avoid most false positive matches.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1610
diff
changeset
|
56 |
(defvar log4-hi-hide-regex |
954b7c665c1a
Added highlighting for special pattern to be less distracting. Two symbols are used as markers from each side to avoid most false positive matches.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1610
diff
changeset
|
57 |
'(("\\[`.\\{3,100\\}`]" . 'log4-hi-hide-face)) |
954b7c665c1a
Added highlighting for special pattern to be less distracting. Two symbols are used as markers from each side to avoid most false positive matches.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1610
diff
changeset
|
58 |
"Highlight regex for extra text for hiding.") |
954b7c665c1a
Added highlighting for special pattern to be less distracting. Two symbols are used as markers from each side to avoid most false positive matches.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1610
diff
changeset
|
59 |
|
1137
b260dc221119
Refactoring: fix according to naming convention.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1136
diff
changeset
|
60 |
(defvar log4-hi-func t |
1083
d4b063fc0f5e
Add highlighting for Java stack traces.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1078
diff
changeset
|
61 |
"Mark to use hilighting of function names in stacktraces. Currently only Java supported.") |
d4b063fc0f5e
Add highlighting for Java stack traces.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1078
diff
changeset
|
62 |
|
1497
9a881de3da24
Define function to easy navigate to Java source file from Java exception.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1261
diff
changeset
|
63 |
(defvar log4-hi-mode-map (make-sparse-keymap) |
9a881de3da24
Define function to easy navigate to Java source file from Java exception.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1261
diff
changeset
|
64 |
"Keymap for `log4-hi-mode'.") |
9a881de3da24
Define function to easy navigate to Java source file from Java exception.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1261
diff
changeset
|
65 |
|
1076
eed45b8a9e3a
Highlight standard elements in log4* like log-files.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
66 |
;;;###autoload |
eed45b8a9e3a
Highlight standard elements in log4* like log-files.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
67 |
(define-minor-mode log4-hi-mode |
eed45b8a9e3a
Highlight standard elements in log4* like log-files.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
68 |
"Highlight standard elements in log4* like log-files." |
1497
9a881de3da24
Define function to easy navigate to Java source file from Java exception.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1261
diff
changeset
|
69 |
nil " log4-hi" log4-hi-mode-map |
1076
eed45b8a9e3a
Highlight standard elements in log4* like log-files.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
70 |
:global nil |
eed45b8a9e3a
Highlight standard elements in log4* like log-files.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
71 |
(catch 'exit |
eed45b8a9e3a
Highlight standard elements in log4* like log-files.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
72 |
(when log4-hi-mode |
eed45b8a9e3a
Highlight standard elements in log4* like log-files.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
73 |
(font-lock-mode 1) |
eed45b8a9e3a
Highlight standard elements in log4* like log-files.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
74 |
(font-lock-add-keywords nil log4-hi-keywords) |
1136
26996dddc80f
Add highlighting for time.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1134
diff
changeset
|
75 |
(font-lock-add-keywords nil log4-hi-time-keywords) |
1622
954b7c665c1a
Added highlighting for special pattern to be less distracting. Two symbols are used as markers from each side to avoid most false positive matches.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1610
diff
changeset
|
76 |
(font-lock-add-keywords nil log4-hi-hide-regex) |
1137
b260dc221119
Refactoring: fix according to naming convention.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1136
diff
changeset
|
77 |
(when log4-hi-func (font-lock-add-keywords nil log4-hi-func-keywords)) |
1076
eed45b8a9e3a
Highlight standard elements in log4* like log-files.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
78 |
(throw 'exit nil)) |
1083
d4b063fc0f5e
Add highlighting for Java stack traces.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1078
diff
changeset
|
79 |
(font-lock-remove-keywords nil log4-hi-keywords) |
1136
26996dddc80f
Add highlighting for time.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1134
diff
changeset
|
80 |
(font-lock-remove-keywords nil log4-hi-time-keywords) |
1622
954b7c665c1a
Added highlighting for special pattern to be less distracting. Two symbols are used as markers from each side to avoid most false positive matches.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1610
diff
changeset
|
81 |
(font-lock-remove-keywords nil log4-hi-func-keywords) |
954b7c665c1a
Added highlighting for special pattern to be less distracting. Two symbols are used as markers from each side to avoid most false positive matches.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1610
diff
changeset
|
82 |
(font-lock-remove-keywords nil log4-hi-hide-regex)) |
1518
7965eec19342
Fix: Warning: "font-lock-fontify-buffer" is for interactive use only; use
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1499
diff
changeset
|
83 |
(font-lock-flush)) |
1076
eed45b8a9e3a
Highlight standard elements in log4* like log-files.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
84 |
|
eed45b8a9e3a
Highlight standard elements in log4* like log-files.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
85 |
(provide 'log4-hi-mode) |
1261
ebbd2c480f1d
Fix checkdoc warnings.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1137
diff
changeset
|
86 |
|
ebbd2c480f1d
Fix checkdoc warnings.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1137
diff
changeset
|
87 |
(provide 'log4-hi-mode) |
ebbd2c480f1d
Fix checkdoc warnings.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1137
diff
changeset
|
88 |
|
ebbd2c480f1d
Fix checkdoc warnings.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1137
diff
changeset
|
89 |
;;; log4-hi-mode.el ends here |