Procházet zdrojové kódy

Add a --verbose option

Add --verbose -v option to log on stderr
Yann Weber před 5 roky
rodič
revize
7b22e9278c
5 změnil soubory, kde provedl 36 přidání a 13 odebrání
  1. 6
    2
      include/conf.h
  2. 1
    1
      include/logger.h
  3. 7
    1
      src/conf.c
  4. 21
    8
      src/logger.c
  5. 1
    1
      src/python_pyfcgi.c

+ 6
- 2
include/conf.h Zobrazit soubor

@@ -56,7 +56,7 @@
56 56
 
57 57
 #define PYFCGI_NAME "spawn-fcgi [OPTIONS] -- pyfcgi"
58 58
 
59
-#define PYFCGI_SHORT_OPT "Ce:E:Aw:W:m:L:Svh"
59
+#define PYFCGI_SHORT_OPT "Ce:E:Aw:W:m:L:SvVh"
60 60
 
61 61
 #define PYFCGI_LONG_OPT { \
62 62
 	{"config", required_argument, 0, 'C'},\
@@ -69,7 +69,8 @@
69 69
 	{"log", required_argument, 0, 'L'},\
70 70
 	{"syslog", no_argument, 0, 'S'},\
71 71
 	{"pid-file", required_argument, 0, 'P'},\
72
-	{"version", no_argument, 0, 'v'},\
72
+	{"verbose", no_argument, 0, 'v'},\
73
+	{"version", no_argument, 0, 'V'},\
73 74
 	{"help", no_argument, 0, 'h' },\
74 75
 	{0, 0, 0, 0}\
75 76
 }
@@ -85,6 +86,7 @@
85 86
 	{"Add a logfile using syntax : 'LOGFILE[;FILT][;FMT]'", "LOGGER_SPEC"},\
86 87
 	{"Use syslog for logging", NULL},\
87 88
 	{"Create a PID file", "FILENAME"},\
89
+	{"Send all loglines on stderr", NULL},\
88 90
 	{"Print PyFCGI and Python version and exit", NULL},\
89 91
 	{"Display this help and exit", NULL},\
90 92
 }
@@ -163,6 +165,8 @@ struct pyfcgi_conf_s
163 165
 	 * @ingroup conf_glob */
164 166
 	int max_reqs;
165 167
 
168
+	/**@brief 0 is silent 1 means logs to stderr */
169
+	short verbosity;
166 170
 
167 171
 	/**@brief Logger configuration
168 172
 	 * @ingroupe conf_glob */

+ 1
- 1
include/logger.h Zobrazit soubor

@@ -334,7 +334,7 @@ void pyfcgi_logger_enable_syslog(const char*);
334 334
 void _pyfcgi_logger_free(pyfcgi_logger_t*);
335 335
 
336 336
 /**@brief Add a new logger
337
- * @param char* filename
337
+ * @param char* filename or NULL if stderr (fd 2 ) wanted
338 338
  * @param logmask_t loglvl a mask indicating wich loglevels should be logged
339 339
  * @param logmask_t typemask a mask indicating wich facility should be logged
340 340
  * @param char* log format (or NULL for default format)

+ 7
- 1
src/conf.c Zobrazit soubor

@@ -45,6 +45,7 @@ void default_conf()
45 45
 	PyFCGI_conf.max_wrk = 5;
46 46
 	PyFCGI_conf.max_reqs = 1000;
47 47
 	PyFCGI_conf.pep333 = 1;
48
+	PyFCGI_conf.verbosity = 0;
48 49
 }
49 50
 
50 51
 int parse_args(int argc, char *argv[])
@@ -60,7 +61,7 @@ int parse_args(int argc, char *argv[])
60 61
 		if(c == -1) { break; }
61 62
 		switch(c)
62 63
 		{
63
-			case 'v':
64
+			case 'V':
64 65
 				print_version(1);
65 66
 				exit(0);
66 67
 			case 'C':
@@ -81,6 +82,11 @@ int parse_args(int argc, char *argv[])
81 82
 			case 'W':
82 83
 				PyFCGI_conf.max_wrk = atoi(optarg);
83 84
 				break;
85
+			case 'v':
86
+				PyFCGI_conf.verbosity = 1;
87
+				pyfcgi_logger_add(NULL, 0xFF, 0xFF,
88
+					PYFCGI_LOGGER_FMT_DEFAULT);
89
+				break;
84 90
 			case 'm':
85 91
 				PyFCGI_conf.max_reqs = atoi(optarg);
86 92
 				if(PyFCGI_conf.max_reqs < 0)

+ 21
- 8
src/logger.c Zobrazit soubor

@@ -5,6 +5,7 @@ int pyfcgi_logger_init()
5 5
 	pyfcgi_conf_logger_t *conf;
6 6
 	conf = &PyFCGI_conf.logs;
7 7
 	memset(conf, 0, sizeof(pyfcgi_conf_logger_t));
8
+
8 9
 	return 0;
9 10
 }
10 11
 
@@ -96,16 +97,22 @@ int pyfcgi_logger_add(const char *filename, logmask_t loglvl, logmask_t logtyp,
96 97
 
97 98
 	logger.loglvl = loglvl;
98 99
 	logger.logtyp = logtyp;
99
-	logger.filename = strdup(filename);
100
-	if(!logger.filename)
100
+	if(!filename)
101 101
 	{
102
-		err = errno;
103
-		pyfcgi_log(LOG_ALERT,
104
-			"Unable to duplicate logger filename : %s",
105
-			strerror(err));
106
-		return PYFCGI_FATAL;	
102
+		logger.filename = NULL;
103
+	}
104
+	else
105
+	{
106
+		logger.filename = strdup(filename);
107
+		if(!logger.filename)
108
+		{
109
+			err = errno;
110
+			pyfcgi_log(LOG_ALERT,
111
+				"Unable to duplicate logger filename : %s",
112
+				strerror(err));
113
+			return PYFCGI_FATAL;	
114
+		}
107 115
 	}
108
-
109 116
 	new_idx = conf->logger_sz;
110 117
 	conf->logger_sz++;
111 118
 	conf->loggers[new_idx] = logger;
@@ -546,6 +553,12 @@ const char* pyfcgi_logger_value_facility(short typ)
546 553
 
547 554
 int pyfcgi_logger_open(pyfcgi_logger_t *logger)
548 555
 {
556
+	if(!logger->filename)
557
+	{
558
+		logger->fd = 2;
559
+		return 0;
560
+	}
561
+
549 562
 	if( ((logger->fd = open(logger->filename,
550 563
 		O_WRONLY | O_APPEND | O_CREAT, 00640)) < 0) )
551 564
 	{

+ 1
- 1
src/python_pyfcgi.c Zobrazit soubor

@@ -441,7 +441,7 @@ PyObject* _pyfcgi_write_body(PyObject *body_data)
441 441
 	// if headers not sent yet, send them....
442 442
 	if(!libpyfcgi.headers_sent)
443 443
 	{
444
-		pyfcgi_log(LOG_DEBUG, "Headers not sent... sending them...");
444
+		//pyfcgi_log(LOG_DEBUG, "Headers not sent... sending them...");
445 445
 		libpyfcgi_send_headers();
446 446
 	}
447 447
 

Loading…
Zrušit
Uložit