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