1 /*
2 * Copyright 2003-2015, Axel Dörfler, axeld@pinc-software.de.
3 * Distributed under the terms of the MIT License.
4 */
5
6
7 #include <stdio.h>
8 #include <string.h>
9 #include <stdlib.h>
10 #include <syslog.h>
11
12
13 int
main(int argc,char ** argv)14 main(int argc, char **argv)
15 {
16 openlog_team("SyslogTest", LOG_PID, LOG_USER);
17
18 log_team(LOG_ERR, "this is %.", "a test");
19
20 int mask = setlogmask_team(LOG_MASK(LOG_CRIT));
21 printf("team mask == %d\n", mask);
22
23 log_team(LOG_WARNING, "this is a warning (hidden)");
24 log_team(LOG_CRIT, "this is a critical condition (visible)");
25
26 setlogmask_team(mask);
27 syslog(LOG_WARNING, "thread warning (visible)");
28 syslog(LOG_CRIT, "thread critical condition (visible)");
29 syslog(LOG_CRIT, "thread critical condition (visible)");
30
31 setlogmask(LOG_MASK(LOG_WARNING));
32 log_team(LOG_WARNING | LOG_MAIL, "2. this is a warning from the MAIL facility (visible)");
33 log_team(LOG_CRIT, "2. this is a critical condition (visible)");
34 log_team(LOG_CRIT, "2. this is a critical condition (visible)");
35 log_team(LOG_CRIT, "2. this is a critical condition (visible)");
36 // test repeat message suppressing as well
37
38 openlog(NULL, LOG_PERROR, LOG_USER);
39 syslog(LOG_WARNING, "thread/perror warning (visible in stderr as well)");
40 syslog(LOG_CRIT, "thread/perror critical condition (hidden)");
41
42 openlog(NULL, LOG_CONS | LOG_PID, LOG_DAEMON);
43 syslog(LOG_WARNING, "thread/cons warning (visible in stderr only when there is no syslog_daemon)");
44
45 openlog("", 0, LOG_DAEMON);
46 syslog(LOG_WARNING, "thread warning without ident (visible)");
47
48 setlogmask(LOG_EMERG);
49 closelog();
50 // this should inherit the team log context on next logging entry
51
52 syslog(LOG_ALERT, "now what are we doing here? (visible)");
53 return 0;
54 }
55