Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 70 lines (55 sloc) 1.79 kb
f62d524 Migrated from UFFI to CFFI for portable FFI-support.
lnostdal authored
1 ;;;; $Id: cl-syslog.lisp,v 1.3 2006/11/28 19:46:09 lnostdal Exp $
9a42838 Initial revision
eenge authored
2 ;;;; $Source: /project/cl-syslog/cvsroot/cl-syslog/cl-syslog.lisp,v $
3
4 ;;;; See the LICENSE file for licensing information.
5
6 (in-package :syslog)
7
8 ;;
9 ;; Condition
10 ;;
11
12 (define-condition invalid-facility (error)
13 ((facility
14 :reader facility
15 :initarg :facility))
16 (:report (lambda (condition stream)
17 (format stream "Invalid facility ~A." (facility condition)))))
18
19 (define-condition invalid-priority (error)
20 ((priority
21 :reader priority
22 :initarg :priority))
23 (:report (lambda (condition stream)
24 (format stream "Invalid priority ~A." (priority condition)))))
25
26 ;;
27 ;; Foreign function
28 ;;
29
f62d524 Migrated from UFFI to CFFI for portable FFI-support.
lnostdal authored
30 (cffi:defcfun "openlog" :void
31 (ident :string)
32 (option :int)
33 (facility :int))
9a42838 Initial revision
eenge authored
34
f62d524 Migrated from UFFI to CFFI for portable FFI-support.
lnostdal authored
35 (cffi:defcfun "closelog" :void)
9a42838 Initial revision
eenge authored
36
f62d524 Migrated from UFFI to CFFI for portable FFI-support.
lnostdal authored
37 (cffi:defcfun "syslog" :void
38 (priority :int)
39 (format :string))
9a42838 Initial revision
eenge authored
40
41 ;;
42 ;; Utility
43 ;;
44
45 (defun get-facility (facility-name)
22c7cf9 adding some better docstrings
eenge authored
46 "Return facility number given the facility's name. If there is no
47 such facility, signal `invalid-facility' error."
9a42838 Initial revision
eenge authored
48 (ash (or (cdr (assoc facility-name *facilities*))
49 (error (make-condition 'invalid-facility :facility facility-name)))
50 3))
51
52 (defun get-priority (priority-name)
22c7cf9 adding some better docstrings
eenge authored
53 "Return priority number given the priority's name. If there is no
54 such priority, signal `invalid-priority' error."
9a42838 Initial revision
eenge authored
55 (or (cdr (assoc priority-name *priorities*))
56 (error (make-condition 'invalid-priority :priority priority-name))))
57
58 ;;
59 ;; Log function
60 ;;
61
62 (defun log (name facility priority text &optional (option 0))
63 "Print message to syslog.
64 'option' can be any of the +log...+ constants"
f62d524 Migrated from UFFI to CFFI for portable FFI-support.
lnostdal authored
65 (cffi:with-foreign-string (cname name)
66 (openlog cname option (get-facility facility))
67 (syslog (get-priority priority) text)
68 (closelog))
9a42838 Initial revision
eenge authored
69 text)
Something went wrong with that request. Please try again.