Skip to content

lujun9972/elog

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

38 Commits
 
 
 
 

Repository files navigation

elog

What is elog

elog is a simple logging library for elisp. It is extended from logito

How to use elog

  1. require the file
    (require 'elog)
        
  2. use `elog-open-log’ macro to generate your own logging function.
    (elog-open-log TYPE IDENT &rest init-args)
        

    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

(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)

record log to a buffer

(elog-open-log buffer "BUF" :buffer "elog")

(BUF-log elog-error "%s-%d" "hello" 123)

(BUF-close-log)

record log to a file

(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)

record log to syslog

(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)

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.

About

a log library used in elisp

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published