File: cl-syslog.lisp

package info (click to toggle)
cl-syslog 0.9.0-3
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 80 kB
  • ctags: 30
  • sloc: lisp: 135; makefile: 48
file content (73 lines) | stat: -rw-r--r-- 1,818 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
;;;; $Id: cl-syslog.lisp,v 1.2 2003/11/22 23:34:52 eenge Exp $
;;;; $Source: /project/cl-syslog/cvsroot/cl-syslog/cl-syslog.lisp,v $

;;;; See the LICENSE file for licensing information.

(in-package :syslog)

;;
;; Condition
;;

(define-condition invalid-facility (error)
  ((facility
    :reader facility
    :initarg :facility))
  (:report (lambda (condition stream)
             (format stream "Invalid facility ~A." (facility condition)))))

(define-condition invalid-priority (error)
  ((priority
    :reader priority
    :initarg :priority))
  (:report (lambda (condition stream)
             (format stream "Invalid priority ~A." (priority condition)))))

;;
;; Foreign function
;;

(uffi:def-function "openlog"
    ((ident :cstring)
     (option :int)
     (facility :int))
  :returning :void)

(uffi:def-function "closelog"
    ()
  :returning :void)

(uffi:def-function "syslog"
    ((priority :int)
     (format :cstring))
  :returning :void)

;;
;; Utility
;;

(defun get-facility (facility-name)
  "Return facility number given the facility's name.  If there is no
such facility, signal `invalid-facility' error."
  (ash (or (cdr (assoc facility-name *facilities*))
           (error (make-condition 'invalid-facility :facility facility-name)))
       3))

(defun get-priority (priority-name)
  "Return priority number given the priority's name.  If there is no
such priority, signal `invalid-priority' error."
  (or (cdr (assoc priority-name *priorities*))
      (error (make-condition 'invalid-priority :priority priority-name))))

;;
;; Log function
;;

(defun log (name facility priority text &optional (option 0))
  "Print message to syslog.

'option' can be any of the +log...+ constants"
  (openlog name option (get-facility facility))
  (syslog (get-priority priority) text)
  (closelog)
  text)