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