log4-hi-mode.el
author Oleksandr Gavenko <gavenkoa@gmail.com>
Thu, 23 Feb 2017 09:59:25 +0200
changeset 1497 9a881de3da24
parent 1261 ebbd2c480f1d
child 1499 d64d7d3699b9
permissions -rw-r--r--
Define function to easy navigate to Java source file from Java exception.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
1078
bd0c280abe8a Define own faces to remove dependency on compile.el.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1077
diff changeset
     8
(defface log4-hi-error-face
bd0c280abe8a Define own faces to remove dependency on compile.el.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1077
diff changeset
     9
  '((t :inherit error))
bd0c280abe8a Define own faces to remove dependency on compile.el.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1077
diff changeset
    10
  "Face for critical message.")
bd0c280abe8a Define own faces to remove dependency on compile.el.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1077
diff changeset
    11
bd0c280abe8a Define own faces to remove dependency on compile.el.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1077
diff changeset
    12
(defface log4-hi-warn-face
bd0c280abe8a Define own faces to remove dependency on compile.el.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1077
diff changeset
    13
  '((t :inherit warning))
bd0c280abe8a Define own faces to remove dependency on compile.el.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1077
diff changeset
    14
  "Face for urgent message.")
bd0c280abe8a Define own faces to remove dependency on compile.el.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1077
diff changeset
    15
bd0c280abe8a Define own faces to remove dependency on compile.el.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1077
diff changeset
    16
(defface log4-hi-info-face
bd0c280abe8a Define own faces to remove dependency on compile.el.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1077
diff changeset
    17
  '((t :inherit success))
bd0c280abe8a Define own faces to remove dependency on compile.el.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1077
diff changeset
    18
  "Face for informational message.")
1076
eed45b8a9e3a Highlight standard elements in log4* like log-files.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    19
1083
d4b063fc0f5e Add highlighting for Java stack traces.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1078
diff changeset
    20
(defface log4-hi-func-face
d4b063fc0f5e Add highlighting for Java stack traces.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1078
diff changeset
    21
  '((t :inherit font-lock-function-name-face))
d4b063fc0f5e Add highlighting for Java stack traces.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1078
diff changeset
    22
  "Face for functions in trace.")
d4b063fc0f5e Add highlighting for Java stack traces.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1078
diff changeset
    23
1136
26996dddc80f Add highlighting for time.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1134
diff changeset
    24
(defface log4-hi-time-face
26996dddc80f Add highlighting for time.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1134
diff changeset
    25
  '((t :inherit font-lock-builtin-face))
26996dddc80f Add highlighting for time.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1134
diff changeset
    26
  "Face for time.")
26996dddc80f Add highlighting for time.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1134
diff changeset
    27
1076
eed45b8a9e3a Highlight standard elements in log4* like log-files.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    28
(defvar log4-hi-keywords
1078
bd0c280abe8a Define own faces to remove dependency on compile.el.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1077
diff changeset
    29
  '(("FATAL\\|ERROR" . 'log4-hi-error-face)
1134
d91fa7f7033a Add keyword for highlighting.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1083
diff changeset
    30
    ("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
    31
    ("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
    32
1137
b260dc221119 Refactoring: fix according to naming convention.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1136
diff changeset
    33
(defvar log4-hi-func-keywords
1083
d4b063fc0f5e Add highlighting for Java stack traces.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1078
diff changeset
    34
  '(("at [[:alnum:].]+\\.\\([[:alnum:]$]+\\.[[:alnum:]$<>]+\\)([[:alnum:]]+\\.java:[0-9]+)" 1 'log4-hi-func-face) ))
d4b063fc0f5e Add highlighting for Java stack traces.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1078
diff changeset
    35
1136
26996dddc80f Add highlighting for time.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1134
diff changeset
    36
(defvar log4-hi-time-keywords
26996dddc80f Add highlighting for time.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1134
diff changeset
    37
  '(("\\<[0-9]?[0-9]:[0-9][0-9]:[0-9][0-9]\\>" . 'log4-hi-time-face)))
26996dddc80f Add highlighting for time.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1134
diff changeset
    38
1137
b260dc221119 Refactoring: fix according to naming convention.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1136
diff changeset
    39
(defvar log4-hi-func t
1083
d4b063fc0f5e Add highlighting for Java stack traces.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1078
diff changeset
    40
  "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
    41
1497
9a881de3da24 Define function to easy navigate to Java source file from Java exception.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1261
diff changeset
    42
(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
    43
  "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
    44
1076
eed45b8a9e3a Highlight standard elements in log4* like log-files.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    45
;;;###autoload
eed45b8a9e3a Highlight standard elements in log4* like log-files.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    46
(define-minor-mode log4-hi-mode
eed45b8a9e3a Highlight standard elements in log4* like log-files.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    47
  "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
    48
  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
    49
  :global nil
eed45b8a9e3a Highlight standard elements in log4* like log-files.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    50
  (catch 'exit
eed45b8a9e3a Highlight standard elements in log4* like log-files.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    51
    (when log4-hi-mode
eed45b8a9e3a Highlight standard elements in log4* like log-files.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    52
      (font-lock-mode 1)
eed45b8a9e3a Highlight standard elements in log4* like log-files.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    53
      (font-lock-add-keywords nil log4-hi-keywords)
1136
26996dddc80f Add highlighting for time.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1134
diff changeset
    54
      (font-lock-add-keywords nil log4-hi-time-keywords)
1137
b260dc221119 Refactoring: fix according to naming convention.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1136
diff changeset
    55
      (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
    56
      (throw 'exit nil))
1083
d4b063fc0f5e Add highlighting for Java stack traces.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1078
diff changeset
    57
    (font-lock-remove-keywords nil log4-hi-keywords)
1136
26996dddc80f Add highlighting for time.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1134
diff changeset
    58
    (font-lock-remove-keywords nil log4-hi-time-keywords)
1137
b260dc221119 Refactoring: fix according to naming convention.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1136
diff changeset
    59
    (font-lock-remove-keywords nil log4-hi-func-keywords))
1076
eed45b8a9e3a Highlight standard elements in log4* like log-files.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    60
  (font-lock-fontify-buffer))
eed45b8a9e3a Highlight standard elements in log4* like log-files.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    61
eed45b8a9e3a Highlight standard elements in log4* like log-files.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    62
(provide 'log4-hi-mode)
1261
ebbd2c480f1d Fix checkdoc warnings.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1137
diff changeset
    63
ebbd2c480f1d Fix checkdoc warnings.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1137
diff changeset
    64
(provide 'log4-hi-mode)
ebbd2c480f1d Fix checkdoc warnings.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1137
diff changeset
    65
ebbd2c480f1d Fix checkdoc warnings.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1137
diff changeset
    66
;;; log4-hi-mode.el ends here