--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/mylisp/log4-hi-mode.el Sat Jan 02 00:33:04 2021 +0200
@@ -0,0 +1,92 @@
+;;; log4-hi-mode.el --- Syntax highlighting logs keywords.
+
+;;; Commentary:
+;; Used for highlighting ERROR/WARN/INFO like keywords and dates in logs.
+
+;;; Code:
+
+(defgroup log4-hi nil
+ "`log4-hi-mode' mode for highlighting logs."
+ :prefix "log4-hi-"
+ :group 'text)
+
+(defface log4-hi-error-face
+ '((t :inherit error))
+ "Face for critical message."
+ :group 'log4-hi)
+
+(defface log4-hi-warn-face
+ '((t :inherit warning))
+ "Face for urgent message."
+ :group 'log4-hi)
+
+(defface log4-hi-info-face
+ '((t :inherit success))
+ "Face for informational message."
+ :group 'log4-hi)
+
+(defface log4-hi-func-face
+ '((t :inherit font-lock-function-name-face))
+ "Face for functions in trace."
+ :group 'log4-hi)
+
+(defface log4-hi-time-face
+ '((t :inherit font-lock-builtin-face :height 0.7))
+ "Face for time."
+ :group 'log4-hi)
+
+(defface log4-hi-hide-face
+ '((t :inherit shadow :height 0.7 :family "Arial"))
+ "Face for extra text for hiding."
+ :group 'log4-hi)
+
+(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
+ '(("^.\\{0,5\\}at [[:alnum:]./]+\\.\\([[:alnum:]$]+\\.[[:alnum:]$<>]+\\)([[:alnum:]]+\\.java:[0-9]+)" 1 'log4-hi-func-face) )
+ "Highlight regex for line from Java stack trace.")
+
+(defvar log4-hi-time-keywords
+ '(("\\(:?\\(:?[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))
+ "Highlight regex for ISO date.")
+
+(defvar log4-hi-hide-regex
+ '(("\\[`.\\{3,100\\}`]" . 'log4-hi-hide-face))
+ "Highlight regex for extra text for hiding.")
+
+(defvar log4-hi-func t
+ "Mark to use hilighting of function names in stacktraces. Currently only Java supported.")
+
+(defvar log4-hi-mode-map (make-sparse-keymap)
+ "Keymap for `log4-hi-mode'.")
+
+;;;###autoload
+(define-minor-mode log4-hi-mode
+ "Highlight standard elements in log4* like log-files."
+ nil " log4-hi" log4-hi-mode-map
+ :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)
+ (font-lock-add-keywords nil log4-hi-hide-regex)
+ (when log4-hi-func (font-lock-add-keywords nil log4-hi-func-keywords))
+ (setq prettify-symbols-alist (list (cons "[`" ?$,2'f(B) (cons "`]" ?$,2'g(B)))
+ (prettify-symbols-mode 1)
+ (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-remove-keywords nil log4-hi-hide-regex)
+ (prettify-symbols-mode -1))
+ (font-lock-flush))
+
+(provide 'log4-hi-mode)
+
+(provide 'log4-hi-mode)
+
+;;; log4-hi-mode.el ends here