[vhffs-dev] [2176] added tee option to syslogger, so that we can get the raw input

[ Thread Index | Date Index | More vhffs.org/vhffs-dev Archives ]


Revision: 2176
Author:   gradator
Date:     2012-05-06 00:59:54 +0200 (Sun, 06 May 2012)
Log Message:
-----------
added tee option to syslogger, so that we can get the raw input

Modified Paths:
--------------
    trunk/vhffs-syslogger/syslogger.c

Modified: trunk/vhffs-syslogger/syslogger.c
===================================================================
--- trunk/vhffs-syslogger/syslogger.c	2012-05-05 21:12:01 UTC (rev 2175)
+++ trunk/vhffs-syslogger/syslogger.c	2012-05-05 22:59:54 UTC (rev 2176)
@@ -46,6 +46,7 @@
 	char *buffer, *ident = "httpd";
 	int facility = DEFAULT_FACILITY, priority = DEFAULT_PRIORITY, option = DEFAULT_OPTION;
 	size_t bufsiz = 32768;
+	FILE *tee = NULL;
 
 	struct option long_options[] = {
 		{ "ident", required_argument, NULL, 'i' },
@@ -53,6 +54,7 @@
 		{ "facility", required_argument, NULL, 'f' },
 		{ "priority", required_argument, NULL, 'p' },
 		{ "option", required_argument, NULL, 'o' },
+		{ "tee", required_argument, NULL, 'r' },
 		{ "help", no_argument, NULL, 'h' },
 		{ "version", no_argument, NULL, 'v' },
 		{ 0, 0, 0, 0 }
@@ -60,7 +62,7 @@
 
 	while(1) {
 		int option_index = 0, c;
-		c = getopt_long(argc, argv, "i:s:f:p:o:hv", long_options, &option_index);
+		c = getopt_long(argc, argv, "i:s:f:p:o:t:hv", long_options, &option_index);
 		if(c == -1)
 			break;
 
@@ -107,6 +109,10 @@
 				}
 				break;
 
+			case 't':
+				tee = fopen(optarg, "a");
+				break;
+
 			case 'h':
 				usage_exit(0, argv[0]);
 
@@ -142,8 +148,13 @@
 	openlog(ident, option, facility);
 	while( fgets(buffer, bufsiz, stdin) ) {
 		syslog(priority, buffer);
+		if(tee) {
+			fwrite(buffer, strlen(buffer), 1, tee);
+			fflush(tee);
+		}
 	}
 	closelog();
+	if(tee) fclose(tee);
 
 	return 0;
 }
@@ -233,6 +244,7 @@
 		"\t\t\t\tPossible priority are: emerg, alert, crit, err, warning, notice, info, debug\n"
 		"  -o, --option=STRING\t\tA comma separated list of syslog options, defaults to none\n"
 		"\t\t\t\tPossible options are: cons, ndelay, nowait, odelay, perror, pid\n"
+		"  -t, --tee=PATH\t\tWrite the raw input to file, useful for debugging purposes\n"
 		"  -h, --help\t\t\tDisplay this help and exit\n"
 		"  -v, --version\t\t\tOutput version information and exit\n"
 		"\n"


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/