https://github.com/lujun9972/elog
a log library used in elisp
https://github.com/lujun9972/elog
Last synced: 6 months ago
JSON representation
a log library used in elisp
- Host: GitHub
- URL: https://github.com/lujun9972/elog
- Owner: lujun9972
- Created: 2015-11-05T13:25:45.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2022-12-07T06:43:31.000Z (over 3 years ago)
- Last Synced: 2025-02-09T15:12:21.897Z (over 1 year ago)
- Language: Emacs Lisp
- Size: 23.4 KB
- Stars: 6
- Watchers: 3
- Forks: 5
- Open Issues: 0
-
Metadata Files:
- Readme: README.org
Awesome Lists containing this project
README
#+TITLE: elog
#+AUTHOR: DarkSun
#+CATEGORY: elog
#+DATE: [2015-11-06 五 07:03]
#+OPTIONS: ^:{}
* What is elog
elog is a simple logging library for elisp. It is extended from [[https://github.com/sigma/logito][logito]]
* How to use elog
1. require the file
#+BEGIN_SRC emacs-lisp
(require 'elog)
#+END_SRC
2. use `elog-open-log' macro to generate your own logging function.
#+BEGIN_SRC emacs-lisp
(elog-open-log TYPE IDENT &rest init-args)
#+END_SRC
This macro generate two functions: the `elog-IDENT-log' for logging job and the `elog-IDENT-close-log' for cleanning job.
`TYPE' specify which kind of elog-object is used. Now, elog support four types of elog-object:
+ message :: use `message' function to do the logging job.
+ buffer :: log item will be recoreded in a specify buffer.
+ file :: log item will be recoreded in a specify file.
+ syslog :: log item will be send to a syslogd server.
`init-args' is used to initialize the elog-object.
+ the base elog-object
- :serverity :: specify the logging level. The default value is `elog-info'
- :fmt :: specify the logging format string. There are some %-sequences has a special meaning in it.
%I means the `IDENT' argument
%T means current time
%L means level
%M means message
+ the elog-buffer-object
- :buffer :: It specify which buffer is used to record the logging item.
+ the elog-file-object
- :file :: It specify which file is used to record the logging item.
+ the elog-syslog-object
- :host :: It specify the syslogd server host
- :port :: It specify the syslogd service port
- :facility :: It specify the facility
3. use `IDENT-log' function to do the logging job.
(IDENT-log LEVEL FORMAT-STRING &rest OBJECTS)
4. use `IDENT-close-log' function to do the cleanning job if you wish.
(IDENT-close-log)
5. use `IDENT-set-log-serverity' function to change the logging serverity
(IDENT-set-log-serverity NEW-SERVERITY)
6. use `IDENT-log-serverity' function to get the current logging serverity
(IDENT-log-serverity)
** Examples
*** use message function to display log
#+BEGIN_SRC emacs-lisp
(elog-open-log message "MSG" :prelog-functions (list (lambda (log)
(message "start to log at %s" (current-time-string))))
:postlog-functions (list (lambda (log)
(message "log done at %s" (current-time-string)))))
(MSG-log elog-error "%s-%d" "hello" 123)
#+END_SRC
*** record log to a buffer
#+BEGIN_SRC emacs-lisp
(elog-open-log buffer "BUF" :buffer "elog")
(BUF-log elog-error "%s-%d" "hello" 123)
(BUF-close-log)
#+END_SRC
*** record log to a file
#+BEGIN_SRC emacs-lisp
(defun elog-get-log-name ()
(format "/tmp/%s/elog.log" (format-time-string "%Y%m/%d")))
(elog-open-log file "FILE" :file 'elog-get-log-name
:modes 700
:max-size 10
:old-dir "/tmp/elog/"
:compress-command "gzip %L")
(FILE-log-serverity)
(FILE-set-log-serverity elog-emerg)
(FILE-log elog-error "%s-%d" "hello" 123)
#+END_SRC
*** record log to syslog
#+BEGIN_SRC emacs-lisp
(elog-open-log syslog "SYSLOG" :host "10.8.208.121" :port 514 :facility elog-local7)
(SYSLOG-log elog-error "%s-%d" "hello" 123)
(SYSLOG-close-log)
#+END_SRC
* How to extend elog
Elog is extensible. You just need to define a new subclass of elog-object three method:
+ elog-should-log-p :: this function is used to check if the log item should be recorded
+ elog-insert-log :: this function is used to do the actual logging job
+ elog-close-log :: this function is used to do the cleanning job.