Debian Codegraph @

ext/syslog/syslog.scm

raw
1 ;;;
2 ;;; syslog - syslog interface
3 ;;;
4 ;;; Copyright (c) 2000-2024 Shiro Kawai <[email protected]>
5 ;;;
6 ;;; Redistribution and use in source and binary forms, with or without
7 ;;; modification, are permitted provided that the following conditions
8 ;;; are met:
9 ;;;
10 ;;; 1. Redistributions of source code must retain the above copyright
11 ;;; notice, this list of conditions and the following disclaimer.
12 ;;;
13 ;;; 2. Redistributions in binary form must reproduce the above copyright
14 ;;; notice, this list of conditions and the following disclaimer in the
15 ;;; documentation and/or other materials provided with the distribution.
16 ;;;
17 ;;; 3. Neither the name of the authors nor the names of its contributors
18 ;;; may be used to endorse or promote products derived from this
19 ;;; software without specific prior written permission.
20 ;;;
21 ;;; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 ;;; "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 ;;; LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 ;;; A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 ;;; OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 ;;; SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
27 ;;; TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
28 ;;; PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
29 ;;; LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
30 ;;; NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
31 ;;; SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 ;;;
33
34 #!no-fold-case
35
36 (define-module gauche.syslog
37 (export sys-openlog sys-syslog sys-closelog sys-logmask sys-setlogmask)
38 )
39 (select-module gauche.syslog)
40
41 (inline-stub
42 (declcode
43 (.include <gauche/extend.h>)
44 (.if (defined HAVE_SYSLOG_H)
45 (.include <syslog.h>)))
46
47 ;; On the platforms which don't have syslog facility, should we raise
48 ;; a "not implemented" error, or simply discard the requests? I tend to
49 ;; think, for a logging feature, it is more useful to discard them.
50
51 (.if (defined HAVE_SYSLOG)
52 (begin
53 (define-cproc sys-openlog (ident::<const-cstring>
54 option::<fixnum>
55 facility::<fixnum>)
56 ::<void>
57 (openlog ident option facility))
58 (define-cproc sys-syslog (prio::<fixnum> message::<const-cstring>)
59 ::<void>
60 (syslog prio "%s" message))
61 (define-cproc sys-closelog () ::<void> (closelog)))
62 (begin
63 (define-cproc sys-openlog (_::<const-cstring> _::<fixnum> _::<fixnum>)
64 ::<void> ())
65 (define-cproc sys-syslog (_::<fixnum> _::<const-cstring>) ::<void> ())
66 (define-cproc sys-closelog () ::<void> ())))
67
68 (.if (defined HAVE_SETLOGMASK)
69 (begin
70 (define-cproc sys-logmask (prio::<fixnum>) ::<fixnum>
71 (return (LOG_MASK prio)))
72 (define-cproc sys-setlogmask (mask::<fixnum>) ::<fixnum>
73 (return (setlogmask mask))))
74 (begin
75 (define-cproc sys-logmask (_::<fixnum>) ::<fixnum> (return 0))
76 (define-cproc sys-setlogmask (_::<fixnum>) ::<fixnum> (return 0))))
77
78 ;; We need to define at least these three logging option constants,
79 ;; for they are referenced in gauche.logger. The actual value doesn't matter.
80 (declcode
81 (.unless (defined LOG_PID) (.define LOG_PID 0))
82 (.unless (defined LOG_INFO) (.define LOG_INFO 1))
83 (.unless (defined LOG_USER) (.define LOG_USER 2)))
84
85 ;; openlog options
86 (define-enum-conditionally LOG_CONS)
87 (define-enum-conditionally LOG_NDELAY)
88 (define-enum-conditionally LOG_NOWAIT)
89 (define-enum-conditionally LOG_ODELAY)
90 (define-enum-conditionally LOG_PERROR)
91 (define-enum-conditionally LOG_PID)
92
93 ;; facility
94 (define-enum-conditionally LOG_AUTH)
95 (define-enum-conditionally LOG_AUTHPRIV)
96 (define-enum-conditionally LOG_CRON)
97 (define-enum-conditionally LOG_DAEMON)
98 (define-enum-conditionally LOG_FTP)
99 (define-enum-conditionally LOG_KERN)
100 (define-enum-conditionally LOG_LOCAL0)
101 (define-enum-conditionally LOG_LOCAL1)
102 (define-enum-conditionally LOG_LOCAL2)
103 (define-enum-conditionally LOG_LOCAL3)
104 (define-enum-conditionally LOG_LOCAL4)
105 (define-enum-conditionally LOG_LOCAL5)
106 (define-enum-conditionally LOG_LOCAL6)
107 (define-enum-conditionally LOG_LOCAL7)
108 (define-enum-conditionally LOG_LPR)
109 (define-enum-conditionally LOG_MAIL)
110 (define-enum-conditionally LOG_NEWS)
111 (define-enum-conditionally LOG_SYSLOG)
112 (define-enum-conditionally LOG_USER)
113 (define-enum-conditionally LOG_UUCP)
114
115 ;; level
116 (define-enum-conditionally LOG_EMERG)
117 (define-enum-conditionally LOG_ALERT)
118 (define-enum-conditionally LOG_CRIT)
119 (define-enum-conditionally LOG_ERR)
120 (define-enum-conditionally LOG_WARNING)
121 (define-enum-conditionally LOG_NOTICE)
122 (define-enum-conditionally LOG_INFO)
123 (define-enum-conditionally LOG_DEBUG)
124 )
125
126 (export-if-defined LOG_CONS LOG_NDELAY LOG_NOWAIT LOG_ODELAY
127 LOG_PERROR LOG_PID LOG_AUTH LOG_AUTHPRIV
128 LOG_CRON LOG_DAEMON LOG_FTP LOG_KERN
129 LOG_LOCAL0 LOG_LOCAL1 LOG_LOCAL2 LOG_LOCAL3
130 LOG_LOCAL4 LOG_LOCAL5 LOG_LOCAL6 LOG_LOCAL7
131 LOG_LPR LOG_MAIL LOG_NEWS LOG_SYSLOG
132 LOG_USER LOG_UUCP LOG_EMERG LOG_ALERT
133 LOG_CRIT LOG_ERR LOG_WARNING LOG_NOTICE
134 LOG_INFO LOG_DEBUG)