https://github.com/aki2o/log4e.git
git clone 'git://github.com/aki2o/log4e.git'
This is a extension of Emacs provides logging framework for Elisp.
Write the following sexp in your elisp file.
(log4e:deflogger "hoge" "%t [%l] %m" "%H:%M:%S")
Then, you can use the following function/command.
For detail, see Usage section.
Here is the image of logging buffer.
The following face is used for font-lock on logging buffer.
The mode of logging buffer is log4e-mode which is based view-mode.
The following binding is added.
- J
log4e:next-log … move to head of next log
- K
log4e:previous-log … move to head of previous log
2013/07/19 It's available by using melpa.
2013/07/26 It's available. But, master branch only.
(auto-install-from-url "https://raw.github.com/aki2o/log4e/master/log4e.el")
Download log4e.el and put it on your load-path.
For example, develop elisp with prefix “hoge”.
Write the following in the elisp.
(require 'log4e)
(log4e:deflogger "hoge" "%t [%l] %m" "%H:%M:%S" '((fatal . "fatal")
(error . "error")
(warn . "warn")
(info . "info")
(debug . "debug")
(trace . "trace")))
log4e:deflogger
receives the following arguments.
Develop the elisp with logging.
(defun hoge-do-hoge (hoge)
(if (not (stringp hoge))
(progn (hoge--fatal "failed do hoge : hoge is '%s'" hoge)
(hoge--log-open-log-if-debug))
(hoge--debug "start do hoge about '%s'" hoge)
(message "hoge!")
(hoge--info "done hoge about '%s'" hoge)))
The logging functions are named by the 4th argument of log4e:deflogger
.
The arguments of them are passed to format
and its returned is used for the message part of log.
The returned of them is always nil.
By default, logging is disabled.
For doing logging, use hoge--log-enable-logging
.
If you want to do logging anytime, write hoge--log-enable-logging
in the elisp.
For stopping logging, use hoge--log-disable-logging
.
By default, The logging range is from ‘info’ to ‘fatal’.
So, eval the following …
(hoge-do-hoge "HOGEGE")
(hoge--log-open-log)
Then, the buffer is displayed that named ' \*log4e-hoge\*'. And the string is like the following.
12:34:56 [INFO ] done hoge about 'HOGEGE'
If you change the logging range, eval the following sexp.
(hoge--log-set-level 'debug 'fatal)
Then, eval the following …
(hoge-do-hoge "FUGAGA")
(hoge--log-open-log)
Then, the buffer is displayed that named ' \*log4e-hoge\*'. And the string is like the following.
12:34:56 [INFO ] done hoge about 'HOGEGE'
12:35:43 [DEBUG] start do hoge about 'FUGAGA'
12:35:43 [INFO ] done hoge about 'FUGAGA'
If you change the logging range anytime, write hoge--log-set-level
in the elisp.
hoge--log-set-level
receive the following arguments.
When you debug the elisp, eval the following …
(hoge--log-enable-debugging)
(hoge-do-hoge 'hogege)
Then, the buffer is displayed that named ' \*log4e-hoge\*'. And the string is like the following.
12:34:56 [INFO ] done hoge about 'HOGEGE'
12:35:43 [DEBUG] start do hoge about 'FUGAGA'
12:35:43 [INFO ] done hoge about 'FUGAGA'
12:54:32 [FATAL] failed do hoge : hoge is 'hogege'
If you want to stop debugging, use hoge--log-disable-debugging
.
If you want to verify activity of debugging in the elisp, use hoge--log-debugging-p
.
By using hoge--log-enable-debugging
, logging is enabled too.
You are able to dump the same log into other area with logging to standard log buffer
by hoge--log-enable-messaging
.
The command receives an argument as a buffer. In default, it's echo area.
For stopping to dump, use hoge--log-disable-messaging
.
Arguments of logging function are evaluated even if the logging level is not a logging range or logging is disabled like the following code.
(hoge--log-set-level 'info 'fatal)
(hoge--log-disable-logging)
(hoge--debug "%s" (very-big-cost-function)) ; <= This is done in any situation
(some-action) ; <= This will be not started until very-big-cost-function is finished
In the case, you are able to inhibit the evaluation using a macro version of the logging function like the following code.
(hoge--log-set-level 'info 'fatal)
(hoge--log-disable-logging)
(hoge--debug* "%s" (very-big-cost-function)) ; <= This is done only if this should be logged
(some-action) ; <= This will be started soon
But, if the macro version is used frequently, the compiled file size might come big.
If you want to do logging with changing log level by some condition locally, use hoge--log
.
hoge--log
is base of the logging function. About them, see Coding section above.
It receive a log level as 1st argument.
You are able to insert logging statement quickly using log4e:insert-start-log-quickly
.
If you want to bind some key to the command, write like the following in your .emacs or site-start.el file.
(define-key emacs-lisp-mode-map (kbd "C-\\") 'log4e:insert-start-log-quickly)
If you want to clear the log buffer named ' \*log4e-hoge\*', use hoge--log-clear-log
.
Enjoy!!!