1 /***********************************************************
2 Copyright 1994 by Lance Ellinghouse,
3 Cathedral City, California Republic, United States of America.
7 Permission to use, copy, modify, and distribute this software and its
8 documentation for any purpose and without fee is hereby granted,
9 provided that the above copyright notice appear in all copies and that
10 both that copyright notice and this permission notice appear in
11 supporting documentation, and that the name of Lance Ellinghouse
12 not be used in advertising or publicity pertaining to distribution
13 of the software without specific, written prior permission.
15 LANCE ELLINGHOUSE DISCLAIMS ALL WARRANTIES WITH REGARD TO
16 THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
17 FITNESS, IN NO EVENT SHALL LANCE ELLINGHOUSE BE LIABLE FOR ANY SPECIAL,
18 INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
19 FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
20 NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
21 WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
23 ******************************************************************/
32 syslog_openlog(self
, args
)
38 long logopt
= LOG_PID
;
39 long facility
= LOG_USER
;
40 if (!PyArg_Parse(args
, "(Sll);ident string, logoption, facility", &ident_o
, &logopt
, &facility
))
41 if (!PyArg_Parse(args
, "(Sl);ident string, logoption", &ident_o
, &logopt
))
42 if (!PyArg_Parse(args
, "S;ident string", &ident_o
))
44 Py_INCREF(ident_o
); /* This is needed because openlog() does NOT make a copy
45 and syslog() later uses it.. cannot trash it. */
46 ident
= PyString_AsString(ident_o
);
47 openlog(ident
,logopt
,facility
);
53 syslog_syslog(self
, args
)
57 int priority
= LOG_INFO
;
60 if (!PyArg_Parse(args
,"(is);priority, message string",&priority
,&message
))
61 if (!PyArg_Parse(args
,"s;message string",&message
))
63 syslog(priority
, message
);
69 syslog_closelog(self
, args
)
73 if (!PyArg_NoArgs(args
))
81 syslog_setlogmask(self
, args
)
86 if (!PyArg_Parse(args
,"l;mask for priority",&maskpri
))
94 syslog_log_mask(self
, args
)
100 if (!PyArg_Parse(args
,"l",&pri
))
102 mask
= LOG_MASK(pri
);
103 return PyInt_FromLong(mask
);
107 syslog_log_upto(self
, args
)
113 if (!PyArg_Parse(args
,"l",&pri
))
115 mask
= LOG_UPTO(pri
);
116 return PyInt_FromLong(mask
);
119 /* List of functions defined in the module */
121 static PyMethodDef syslog_methods
[] = {
122 {"openlog", (PyCFunction
)syslog_openlog
},
123 {"closelog", (PyCFunction
)syslog_closelog
},
124 {"syslog", (PyCFunction
)syslog_syslog
},
125 {"setlogmask", (PyCFunction
)syslog_setlogmask
},
126 {"LOG_MASK", (PyCFunction
)syslog_log_mask
},
127 {"LOG_UPTO", (PyCFunction
)syslog_log_upto
},
128 {NULL
, NULL
} /* sentinel */
131 /* Initialization function for the module */
138 /* Create the module and add the functions */
139 m
= Py_InitModule("syslog", syslog_methods
);
141 /* Add some symbolic constants to the module */
142 d
= PyModule_GetDict(m
);
143 x
= PyInt_FromLong(LOG_EMERG
);
144 PyDict_SetItemString(d
, "LOG_EMERG", x
);
145 x
= PyInt_FromLong(LOG_ALERT
);
146 PyDict_SetItemString(d
, "LOG_ALERT", x
);
147 x
= PyInt_FromLong(LOG_CRIT
);
148 PyDict_SetItemString(d
, "LOG_CRIT", x
);
149 x
= PyInt_FromLong(LOG_ERR
);
150 PyDict_SetItemString(d
, "LOG_ERR", x
);
151 x
= PyInt_FromLong(LOG_WARNING
);
152 PyDict_SetItemString(d
, "LOG_WARNING", x
);
153 x
= PyInt_FromLong(LOG_NOTICE
);
154 PyDict_SetItemString(d
, "LOG_NOTICE", x
);
155 x
= PyInt_FromLong(LOG_INFO
);
156 PyDict_SetItemString(d
, "LOG_INFO", x
);
157 x
= PyInt_FromLong(LOG_DEBUG
);
158 PyDict_SetItemString(d
, "LOG_DEBUG", x
);
159 x
= PyInt_FromLong(LOG_PID
);
160 PyDict_SetItemString(d
, "LOG_PID", x
);
161 x
= PyInt_FromLong(LOG_CONS
);
162 PyDict_SetItemString(d
, "LOG_CONS", x
);
163 x
= PyInt_FromLong(LOG_NDELAY
);
164 PyDict_SetItemString(d
, "LOG_NDELAY", x
);
165 x
= PyInt_FromLong(LOG_NOWAIT
);
166 PyDict_SetItemString(d
, "LOG_NOWAIT", x
);
167 x
= PyInt_FromLong(LOG_KERN
);
168 PyDict_SetItemString(d
, "LOG_KERN", x
);
169 x
= PyInt_FromLong(LOG_USER
);
170 PyDict_SetItemString(d
, "LOG_USER", x
);
171 x
= PyInt_FromLong(LOG_MAIL
);
172 PyDict_SetItemString(d
, "LOG_MAIL", x
);
173 x
= PyInt_FromLong(LOG_DAEMON
);
174 PyDict_SetItemString(d
, "LOG_DAEMON", x
);
175 x
= PyInt_FromLong(LOG_LPR
);
176 PyDict_SetItemString(d
, "LOG_LPR", x
);
177 x
= PyInt_FromLong(LOG_LOCAL0
);
178 PyDict_SetItemString(d
, "LOG_LOCAL0", x
);
179 x
= PyInt_FromLong(LOG_LOCAL1
);
180 PyDict_SetItemString(d
, "LOG_LOCAL1", x
);
181 x
= PyInt_FromLong(LOG_LOCAL2
);
182 PyDict_SetItemString(d
, "LOG_LOCAL2", x
);
183 x
= PyInt_FromLong(LOG_LOCAL3
);
184 PyDict_SetItemString(d
, "LOG_LOCAL3", x
);
185 x
= PyInt_FromLong(LOG_LOCAL4
);
186 PyDict_SetItemString(d
, "LOG_LOCAL4", x
);
187 x
= PyInt_FromLong(LOG_LOCAL5
);
188 PyDict_SetItemString(d
, "LOG_LOCAL5", x
);
189 x
= PyInt_FromLong(LOG_LOCAL6
);
190 PyDict_SetItemString(d
, "LOG_LOCAL6", x
);
191 x
= PyInt_FromLong(LOG_LOCAL7
);
192 PyDict_SetItemString(d
, "LOG_LOCAL7", x
);
194 /* Check for errors */
195 if (PyErr_Occurred())
196 Py_FatalError("can't initialize module syslog");