Interface to syslog functions.
Showing
1 changed file
with
131 additions
and
0 deletions
libmu_scm/mu_logger.c
0 → 100644
1 | /* GNU mailutils - a suite of utilities for electronic mail | ||
2 | Copyright (C) 1999, 2000, 2001 Free Software Foundation, Inc. | ||
3 | |||
4 | This program is free software; you can redistribute it and/or modify | ||
5 | it under the terms of the GNU General Public License as published by | ||
6 | the Free Software Foundation; either version 2, or (at your option) | ||
7 | any later version. | ||
8 | |||
9 | This program is distributed in the hope that it will be useful, | ||
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
12 | GNU General Public License for more details. | ||
13 | |||
14 | You should have received a copy of the GNU General Public License | ||
15 | along with this program; if not, write to the Free Software | ||
16 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ | ||
17 | |||
18 | #include "mu_scm.h" | ||
19 | |||
20 | #include <syslog.h> | ||
21 | |||
22 | SCM_DEFINE(mu_openlog, "mu-openlog", 3, 0, 0, | ||
23 | (SCM IDENT, SCM OPTION, SCM FACILITY), | ||
24 | "Opens a connection to the system logger for Guile program.") | ||
25 | #define FUNC_NAME s_mu_openlog | ||
26 | { | ||
27 | char *ident; | ||
28 | int option, facility; | ||
29 | |||
30 | if (IDENT == SCM_BOOL_F) | ||
31 | ident = "libmu_scm"; | ||
32 | else | ||
33 | { | ||
34 | SCM_ASSERT (SCM_NIMP (IDENT) && SCM_STRINGP (IDENT), | ||
35 | IDENT, SCM_ARG1, FUNC_NAME); | ||
36 | ident = SCM_CHARS (IDENT); | ||
37 | } | ||
38 | |||
39 | if (SCM_IMP (OPTION) && SCM_INUMP (OPTION)) | ||
40 | option = SCM_INUM (OPTION); | ||
41 | else if (SCM_BIGP (OPTION)) | ||
42 | option = (int) scm_big2dbl (OPTION); | ||
43 | else | ||
44 | SCM_ASSERT (0, OPTION, SCM_ARG2, FUNC_NAME); | ||
45 | |||
46 | if (SCM_IMP (FACILITY) && SCM_INUMP (FACILITY)) | ||
47 | facility = SCM_INUM (FACILITY); | ||
48 | else if (SCM_BIGP (FACILITY)) | ||
49 | facility = (int) scm_big2dbl (FACILITY); | ||
50 | else | ||
51 | SCM_ASSERT (0, FACILITY, SCM_ARG3, FUNC_NAME); | ||
52 | |||
53 | openlog (ident, option, facility); | ||
54 | return SCM_UNSPECIFIED; | ||
55 | } | ||
56 | #undef FUNC_NAME | ||
57 | |||
58 | SCM_DEFINE (mu_logger, "mu-logger", 2, 0, 0, | ||
59 | (SCM PRIO, SCM TEXT), | ||
60 | "Generates a log message to be distributed via syslogd.") | ||
61 | #define FUNC_NAME s_mu_logger | ||
62 | { | ||
63 | int prio; | ||
64 | |||
65 | if (PRIO == SCM_BOOL_F) | ||
66 | prio = LOG_INFO; | ||
67 | else if (SCM_IMP (PRIO) && SCM_INUMP (PRIO)) | ||
68 | prio = SCM_INUM (PRIO); | ||
69 | else if (SCM_BIGP (PRIO)) | ||
70 | prio = (int) scm_big2dbl (PRIO); | ||
71 | else | ||
72 | SCM_ASSERT (0, PRIO, SCM_ARG1, FUNC_NAME); | ||
73 | |||
74 | SCM_ASSERT (SCM_NIMP (TEXT) && SCM_STRINGP (TEXT), | ||
75 | TEXT, SCM_ARG2, FUNC_NAME); | ||
76 | syslog (prio, "%s", SCM_CHARS (TEXT)); | ||
77 | return SCM_UNSPECIFIED; | ||
78 | } | ||
79 | #undef FUNC_NAME | ||
80 | |||
81 | SCM_DEFINE (mu_closelog, "mu-closelog", 0, 0, 0, | ||
82 | (), | ||
83 | "Closes the channel to the system logger open by mu-openlog.") | ||
84 | #define FUNC_NAME s_mu_closelog | ||
85 | { | ||
86 | closelog (); | ||
87 | return SCM_UNSPECIFIED; | ||
88 | } | ||
89 | #undef FUNC_NAME | ||
90 | |||
91 | |||
92 | static struct | ||
93 | { | ||
94 | char *name; | ||
95 | int facility; | ||
96 | } syslog_kw[] = { | ||
97 | { "LOG_USER", LOG_USER }, | ||
98 | { "LOG_DAEMON", LOG_DAEMON }, | ||
99 | { "LOG_AUTH", LOG_AUTH }, | ||
100 | { "LOG_LOCAL0", LOG_LOCAL0 }, | ||
101 | { "LOG_LOCAL1", LOG_LOCAL1 }, | ||
102 | { "LOG_LOCAL2", LOG_LOCAL2 }, | ||
103 | { "LOG_LOCAL3", LOG_LOCAL3 }, | ||
104 | { "LOG_LOCAL4", LOG_LOCAL4 }, | ||
105 | { "LOG_LOCAL5", LOG_LOCAL5 }, | ||
106 | { "LOG_LOCAL6", LOG_LOCAL6 }, | ||
107 | { "LOG_LOCAL7", LOG_LOCAL7 }, | ||
108 | /* severity */ | ||
109 | { "LOG_EMERG", LOG_EMERG }, | ||
110 | { "LOG_ALERT", LOG_ALERT }, | ||
111 | { "LOG_CRIT", LOG_CRIT }, | ||
112 | { "LOG_ERR", LOG_ERR }, | ||
113 | { "LOG_WARNING", LOG_WARNING }, | ||
114 | { "LOG_NOTICE", LOG_NOTICE }, | ||
115 | { "LOG_INFO", LOG_INFO }, | ||
116 | { "LOG_DEBUG", LOG_DEBUG }, | ||
117 | /* options */ | ||
118 | { "LOG_CONS", LOG_CONS }, | ||
119 | { "LOG_NDELAY", LOG_NDELAY }, | ||
120 | { "LOG_PID", LOG_PID } | ||
121 | }; | ||
122 | |||
123 | void | ||
124 | mu_scm_logger_init () | ||
125 | { | ||
126 | int i; | ||
127 | |||
128 | for (i = 0; i < sizeof (syslog_kw)/sizeof (syslog_kw[0]); i++) | ||
129 | scm_sysintern (syslog_kw[i].name, SCM_MAKINUM (syslog_kw[i].facility)); | ||
130 | #include <mu_logger.x> | ||
131 | } |
-
Please register or sign in to post a comment