1
/**********************************************************************
2
* vanessa_logger_sample.c September 2000
3
* Horms horms@vergenet.net
6
* Generic logging layer
7
* Copyright (C) 2000 Horms
9
* This library is free software; you can redistribute it and/or
10
* modify it under the terms of the GNU Lesser General Public License
11
* as published by the Free Software Foundation; either version 2 of
12
* the License, or (at your option) any later version.
14
* This library is distributed in the hope that it will be useful, but
15
* WITHOUT ANY WARRANTY; without even the implied warranty of
16
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17
* Lesser General Public License for more details.
19
* You should have received a copy of the GNU Lesser General Public
20
* License along with this library; if not, write to the Free Software
21
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
24
**********************************************************************/
26
#include <vanessa_logger.h>
28
#include <sys/types.h>
30
#include "vanessa_logger_sample_config.h"
34
/**********************************************************************
35
* Muriel the main function
36
**********************************************************************/
38
int main (int argc, char **argv){
39
vanessa_logger_t *log_fh=NULL;
40
vanessa_logger_t *log_fn=NULL;
41
vanessa_logger_t *log_sl=NULL;
42
vanessa_logger_t *log_sl_bn=NULL;
44
printf("vanessa_logger_sample version %s Copyright Horms\n", VERSION);
48
* Make sure this is _not_ being run by a privileged user
50
* This programme is not suitable to be run by privileged users
51
* as the filename logger that is opened opens a file
52
* in the PWD. If vanessa logger is used in a programme
53
* designed to be used by a privileged user then a full
54
* pathname should be given to vanessa_logger_openlog_filename()
56
if(getuid()<MIN_UID || geteuid()<MIN_UID){
60
"Error: Run by privileged user with UID<%d or EUID<%d. Exiting\n",
68
* Open logger to filehandle stderr
70
printf("\nOpening loggers\n");
72
log_fh=vanessa_logger_openlog_filehandle(
74
"vanessa_logger_sample",
79
fprintf(stderr, "Error: vanessa_logger_openlog_filehandle\n");
84
* Open logger to filename ./vanessa_logger_sample.log
86
log_fn=vanessa_logger_openlog_filename(
87
"./vanessa_logger_sample.log",
88
"vanessa_logger_sample",
93
fprintf(stderr, "Error: vanessa_logger_openlog_filename\n");
98
* Open logger to syslog facility LOG_USER
100
log_sl=vanessa_logger_openlog_syslog(
102
"vanessa_logger_sample",
107
fprintf(stderr, "Error: vanessa_logger_openlog_syslog\n");
112
* Open logger to syslog facility "mail" by name
114
log_sl_bn=vanessa_logger_openlog_syslog_byname(
116
"vanessa_logger_sample",
121
fprintf(stderr, "Error: vanessa_logger_openlog_syslog\n");
126
* Send a message to each logger
128
printf("Logging message to stderr\n");
130
vanessa_logger_log(log_fh, LOG_DEBUG, "This should log to stderr: %d\n", 7);
132
printf("Logging message to ./vanessa_logger_sample.log\n");
136
"This should log to ./vanessa_logger_sample.log: %d",
141
"Logging message to syslog facility LOG_USER, priority LOG_DEBUG\n"
142
"If the message is not logged to syslog then you may need to add\n"
143
"the following to /etc/syslog.conf and restart syslogd:\n"
144
"user.debug /var/log/messages\n"
149
"This should log to syslog facility LOG_USER, priority LOG_DEBUG: %d",
154
"Logging message to syslog facility LOG_MAIL (\"mail\"), priority\n"
155
"LOG_DEBUG, If the message is not logged to syslog then you may need\n"
156
"to add the following to /etc/syslog.conf and restart syslogd:\n"
157
"user.mail /var/log/mail\n"
162
"This should log to syslog facility LOG_MAIL, priority LOG_DEBUG: %d",
172
printf("\nReopening loggers\n");
173
vanessa_logger_reopen(log_fh);
174
vanessa_logger_reopen(log_fn);
175
vanessa_logger_reopen(log_sl);
178
* Send another message to each logger
180
printf("Logging another message to stderr\n");
182
vanessa_logger_log(log_fh, LOG_INFO, "This should also log to stderr\n");
184
printf("Logging another message to ./vanessa_logger_sample.log\n");
188
"This should also log to ./vanessa_logger_sample.log"
192
"Logging another message to syslog facility LOG_USER, priority LOG_INFO\n"
197
"This should also log to syslog facility LOG_USER, priority LOG_INFO"
201
"Logging another message to syslog facility LOG_MAIL, priority LOG_INFO\n"
206
"This should also log to syslog facility LOG_MAIL, priority LOG_INFO"
213
* Change the maximum priority for each logger to LOG_INFO.
214
* The maximum priority is counter-intuitive and sets the
215
* minimum priority that will be accepted for logging.
217
vanessa_logger_change_max_priority(log_fh, LOG_INFO);
218
vanessa_logger_change_max_priority(log_fn, LOG_INFO);
219
vanessa_logger_change_max_priority(log_sl, LOG_INFO);
220
vanessa_logger_change_max_priority(log_sl_bn, LOG_INFO);
223
* These messages should not get logged as their priority,
224
* LOG_DEBUG, is lower than the minimum priority LOG_INFO
225
* set when each logger was opened
227
printf("\nTesting that logs are filtered out by priority\n");
228
printf("No logs should appear after this line\n");
230
vanessa_logger_log(log_fh, LOG_DEBUG, "This should not log to stderr\n");
234
"This should not log to ./vanessa_logger_sample.log"
239
"This should not log to syslog facility LOG_USER, priority LOG_INFO"
244
"This should not log to syslog facility LOG_MAIL, priority LOG_INFO"
250
vanessa_logger_closelog(log_fh);
251
vanessa_logger_closelog(log_fn);
252
vanessa_logger_closelog(log_sl);
253
vanessa_logger_closelog(log_sl_bn);