177b1fd22SAxel Dörfler /*
2*4bf862e3SAxel Dörfler * Copyright 2003-2015, Axel Dörfler, axeld@pinc-software.de.
3*4bf862e3SAxel Dörfler * Distributed under the terms of the MIT License.
477b1fd22SAxel Dörfler */
577b1fd22SAxel Dörfler
677b1fd22SAxel Dörfler
777b1fd22SAxel Dörfler #include <stdio.h>
877b1fd22SAxel Dörfler #include <string.h>
977b1fd22SAxel Dörfler #include <stdlib.h>
1077b1fd22SAxel Dörfler #include <syslog.h>
1177b1fd22SAxel Dörfler
1277b1fd22SAxel Dörfler
1377b1fd22SAxel Dörfler int
main(int argc,char ** argv)1477b1fd22SAxel Dörfler main(int argc, char **argv)
1577b1fd22SAxel Dörfler {
1677b1fd22SAxel Dörfler openlog_team("SyslogTest", LOG_PID, LOG_USER);
1777b1fd22SAxel Dörfler
1877b1fd22SAxel Dörfler log_team(LOG_ERR, "this is %.", "a test");
1977b1fd22SAxel Dörfler
2077b1fd22SAxel Dörfler int mask = setlogmask_team(LOG_MASK(LOG_CRIT));
2177b1fd22SAxel Dörfler printf("team mask == %d\n", mask);
2277b1fd22SAxel Dörfler
2377b1fd22SAxel Dörfler log_team(LOG_WARNING, "this is a warning (hidden)");
2477b1fd22SAxel Dörfler log_team(LOG_CRIT, "this is a critical condition (visible)");
2577b1fd22SAxel Dörfler
2677b1fd22SAxel Dörfler setlogmask_team(mask);
2777b1fd22SAxel Dörfler syslog(LOG_WARNING, "thread warning (visible)");
2877b1fd22SAxel Dörfler syslog(LOG_CRIT, "thread critical condition (visible)");
2977b1fd22SAxel Dörfler syslog(LOG_CRIT, "thread critical condition (visible)");
3077b1fd22SAxel Dörfler
3177b1fd22SAxel Dörfler setlogmask(LOG_MASK(LOG_WARNING));
3277b1fd22SAxel Dörfler log_team(LOG_WARNING | LOG_MAIL, "2. this is a warning from the MAIL facility (visible)");
3377b1fd22SAxel Dörfler log_team(LOG_CRIT, "2. this is a critical condition (visible)");
3477b1fd22SAxel Dörfler log_team(LOG_CRIT, "2. this is a critical condition (visible)");
3577b1fd22SAxel Dörfler log_team(LOG_CRIT, "2. this is a critical condition (visible)");
3677b1fd22SAxel Dörfler // test repeat message suppressing as well
3777b1fd22SAxel Dörfler
3877b1fd22SAxel Dörfler openlog(NULL, LOG_PERROR, LOG_USER);
3977b1fd22SAxel Dörfler syslog(LOG_WARNING, "thread/perror warning (visible in stderr as well)");
4077b1fd22SAxel Dörfler syslog(LOG_CRIT, "thread/perror critical condition (hidden)");
4177b1fd22SAxel Dörfler
4277b1fd22SAxel Dörfler openlog(NULL, LOG_CONS | LOG_PID, LOG_DAEMON);
4377b1fd22SAxel Dörfler syslog(LOG_WARNING, "thread/cons warning (visible in stderr only when there is no syslog_daemon)");
4477b1fd22SAxel Dörfler
4577b1fd22SAxel Dörfler openlog("", 0, LOG_DAEMON);
4677b1fd22SAxel Dörfler syslog(LOG_WARNING, "thread warning without ident (visible)");
4777b1fd22SAxel Dörfler
4877b1fd22SAxel Dörfler setlogmask(LOG_EMERG);
4977b1fd22SAxel Dörfler closelog();
5077b1fd22SAxel Dörfler // this should inherit the team log context on next logging entry
5177b1fd22SAxel Dörfler
5277b1fd22SAxel Dörfler syslog(LOG_ALERT, "now what are we doing here? (visible)");
5377b1fd22SAxel Dörfler return 0;
5477b1fd22SAxel Dörfler }
55